LoginSignup
0
0

More than 3 years have passed since last update.

CloudBuildでimageタグ名を$(cat FILE)してつける

Posted at

CloudBuildでは$TAG_NAMEなど予め用意された環境変数が使えるが,それでは足りないときがある.コマンドの実行結果を使いたいときはentrypointをshellにしてあげればよい.substitutionの仕組みもあるが,毎回コマンドでsubstitutionの値を指定して実行する必要があり,CloudBuild Trigger経由では静的な値しか使えず使い勝手が悪い.

Docker image builderとしてkaniko/executorの例を挙げる. VERSIONというファイルをプロジェクトルートディレクトリに用意して. $(cat /workspace/VERSION)にてタグ名を指定している.

VERSION
1.0.0
cloudbuild.yaml
steps:
  - name: gcr.io/kaniko-project/executor:debug
    entrypoint: sh
    args:
      - -c
      - |
        /kaniko/executor \
          --destination=gcr.io/$PROJECT_ID/example:$(cat /workspace/VERSION)

なお,kaniko/executorはscratchベースのためshが使えない.公式でshが使えるdebug版が用意されていたのでdebug版を使用した.

参考

Building images with kaniko and GitLab CI/CD

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0