6.4. Use custom builder image
You can define a BuildConfig object that uses the custom strategy in conjunction with your custom builder image to execute your custom build logic.
Prerequisites
- Define all the required inputs for new custom builder image.
- Build your custom builder image.
Procedure
Create a file named
buildconfig.yaml. This file defines theBuildConfigobject that is created in your project and executed:kind: BuildConfig apiVersion: v1 metadata: name: sample-custom-build labels: name: sample-custom-build annotations: template.alpha.openshift.io/wait-for-ready: 'true' spec: strategy: type: Custom customStrategy: forcePull: true from: kind: ImageStreamTag name: custom-builder-image:latest namespace: <yourproject>1 output: to: kind: ImageStreamTag name: sample-custom:latest- 1
- Specify your project name.
Create the
BuildConfig:$ oc create -f buildconfig.yamlCreate a file named
imagestream.yaml. This file defines the image stream to which the build will push the image:kind: ImageStream apiVersion: v1 metadata: name: sample-custom spec: {}Create the imagestream:
$ oc create -f imagestream.yamlRun your custom build:
$ oc start-build sample-custom-build -FWhen the build runs, it launches a pod running the custom builder image that was built earlier. The pod runs the
build.shlogic that is defined as the entrypoint for the custom builder image. Thebuild.shlogic invokes Buildah to build thedockerfile.samplethat was embedded in the custom builder image, and then uses Buildah to push the new image to thesample-custom image stream.