6.4. カスタムビルダーイメージの使用
カスタムビルダーイメージとカスタムストラテジーを併用する BuildConfig オブジェクトを定義し、カスタムビルドロジックを実行することができます。
前提条件
- 新規カスタムビルダーイメージに必要なすべての入力を定義します。
- カスタムビルダーイメージをビルドします。
手順
buildconfig.yamlという名前のファイルを作成します。このファイルは、プロジェクトに作成され、実行されるBuildConfigオブジェクトを定義します。kind: BuildConfig apiVersion: build.openshift.io/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
- プロジェクト名を指定します。
次のコマンドを入力して
BuildConfigオブジェクトを作成します。$ oc create -f buildconfig.yamlimagestream.yamlという名前のファイルを作成します。このファイルはビルドがイメージをプッシュするイメージストリームを定義します。kind: ImageStream apiVersion: image.openshift.io/v1 metadata: name: sample-custom spec: {}次のコマンドを入力してイメージストリームを作成します。
$ oc create -f imagestream.yaml次のコマンドを入力してカスタムビルドを実行します。
$ oc start-build sample-custom-build -Fビルドが実行されると、以前にビルドされたカスタムビルダーイメージを実行する Pod が起動します。Pod はカスタムビルダーイメージのエントリーポイントとして定義される
build.shロジックを実行します。build.shロジックは Buildah を起動し、カスタムビルダーイメージに埋め込まれたdockerfile.sampleをビルドしてから、Buildah を使用して新規イメージをsample-custom image streamにプッシュします。