6.4. カスタムビルダーイメージの使用

カスタムビルダーイメージとカスタムストラテジーを併用する BuildConfig オブジェクトを定義し、カスタムビルドロジックを実行することができます。

前提条件

  • 新規カスタムビルダーイメージに必要なすべての入力を定義します。
  • カスタムビルダーイメージをビルドします。

手順

  1. buildconfig.yaml という名前のファイルを作成します。このファイルは、プロジェクトに作成され、実行される BuildConfig オブジェクトを定義します。

    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
    プロジェクト名を指定します。
  2. BuildConfig を作成します。

    $ oc create -f buildconfig.yaml
  3. imagestream.yaml という名前のファイルを作成します。このファイルはビルドがイメージをプッシュするイメージストリームを定義します。

    kind: ImageStream
    apiVersion: v1
    metadata:
      name: sample-custom
    spec: {}
  4. imagestream を作成します。

    $ oc create -f imagestream.yaml
  5. カスタムビルドを実行します。

    $ oc start-build sample-custom-build -F

    ビルドが実行されると、以前にビルドされたカスタムビルダーイメージを実行する Pod が起動します。Pod はカスタムビルダーイメージのエントリーポイントとして定義される build.sh ロジックを実行します。build.sh ロジックは Buildah を起動し、カスタムビルダーイメージに埋め込まれた dockerfile.sample をビルドしてから、Buildah を使用して新規イメージを sample-custom image stream にプッシュします。