git push したらブログが更新されるようにした話の続き。

概要

詳細

元々 git push origin release するだけで Google Cloud Container Builder が docker image build してくれるようにはしていたのだけど、出来上がった docker image を撒く作業を手動でやってたのでそれを自動化した。

Container Builder の使い方などはググれば色んな記事がヒットするので適当に見れば良いのだが、やはり 公式ドキュメント を見るのが一番良いと思われる。便利な変数一覧もある。

開発中に毎回 git push しないと挙動を確認出来なくて不便…なんていうことはなくて、

gcloud container builds submit --config=cloudbuild.yaml .

と打つと build request が飛ぶので、実際に動かして確認することが出来る。

ただし手動で実行した場合は git push による hook で来るときだけ使えそうな変数には何も入っていない。注意が必要ですね。

Cloud Container Builder がビルドを初めたタイミングとかを知りたい。

cloud-builderscurl が追加されてたので、steps の中で curl を叩くことにした。

非同期でビルドしておいて waitFor で待つなど、通知のタイミングを完全にコントロール出来るという利点がある。

steps:
  - id: 'notification_start'
    name: 'gcr.io/cloud-builders/curl'
    args: ['-X', 'POST', 'https://example.com/hook', '-s', '--max-time', '2', '--retry', '0', '-d', '始まったよ〜。']

# [...] (中略)

  - id: 'notification_finish'
    name: 'gcr.io/cloud-builders/curl'
    args: ['-X', 'POST', 'https://example.com/hook', '-s', '--max-time', '2', '--retry', '0', '-d', '終わったよ〜。']
    waitFor: ['app1_push', 'app2_push']

しかし Cloud Functions とかをちゃんと調べて使えるようになるのが正しいという気はしている。後でちゃんとやります。

docker image push を終えたタイミングを知りたい。

以下の様に stepsimages を書くと取れなくなってしまう。

steps:
  - id: 'app1_build'
    name: 'gcr.io/cloud-builders/docker'
    args: ['image', 'build', '--no-cache=true', '--pull=true', '-t', 'gcr.io/dnpp-org/my_project/app1:latest', 'app1']
    waitFor: ['-']

  - id: 'app2_build'
    name: 'gcr.io/cloud-builders/docker'
    args: ['image', 'build', '--no-cache=true', '--pull=true', '-t', 'gcr.io/dnpp-org/my_project/app2:latest', 'app2']
    waitFor: ['-']

images:
  - 'gcr.io/dnpp-org/my_project/app1:latest'
  - 'gcr.io/dnpp-org/my_project/app2:latest'

こうすると steps で指定した手順が全て正常終了した後に gcr.io へ docker image push をしてくれて便利なのだが、今回は cloud-builders にある curlsteps 内で使って通知をしたいため、このままでは docker image push が終了したタイミングを取ることが出来ない。

しょうがないので steps 内で愚直に docker image push を行うように cloudbuild.yaml に記述することで解決した。

締め

Recents
2019/10/26 18:12
2018/6/1 5:13