Atlantis on Cloud Run の動作検証
![ucpr](https://res.cloudinary.com/zenn/image/fetch/s--AhjPuP9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/ddd3fee1e7.jpeg)
目標
Cloud Run 上で Atlantis を動かせるか検証したい
先行事例
適当に atlantis cloud run
で検索したところそれっぽいものは 2 件ヒット
![ucpr](https://res.cloudinary.com/zenn/image/fetch/s--AhjPuP9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/ddd3fee1e7.jpeg)
Atlantis のコンテナイメージを作る
をみると GitHub Packages でコンテナイメージを配布していそう.
CMD で server のバイナリが指定されているのでこれを今回はそのまま使う
![ucpr](https://res.cloudinary.com/zenn/image/fetch/s--AhjPuP9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/ddd3fee1e7.jpeg)
Cloud Run で ghcr のコンテナイメージをそのまま指定できなかったので自分の GCP Project の Artifact Registry に tag 変えて持っていった
![ucpr](https://res.cloudinary.com/zenn/image/fetch/s--AhjPuP9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/ddd3fee1e7.jpeg)
Atlantis のインストールはとりあえず公式ドキュメントに従う
今回は GitHub App での設定で進める。
検証なのでとりあえずコンソールでポチポチサービスを作る。
GH_USER と GH_TOKEN と PORT さえ指定していたら起動するのでサービスを作って、Cloud Run が吐く URL を取得する。
その後 ATLANTIS_ATLANTIS_URL
を指定しつつ、 GItHub App の設定をドキュメント通りに進める
![ucpr](https://res.cloudinary.com/zenn/image/fetch/s--AhjPuP9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/ddd3fee1e7.jpeg)
Deployment の設定は基本的に Kubernetes Manifest の設定を参考にやった
Credential 系は Secret Manager で管理しつつやって起動するところまで確認できた。
image: ***/atlantis
env:
- name: ATLANTIS_REPO_ALLOWLIST
value: ***
- name: ATLANTIS_GH_APP_ID
value: '***'
- name: ATLANTIS_PORT
value: '8080'
- name: ATLANTIS_ATLANTIS_URL
value: ***
- name: ATLANTIS_WRITE_GIT_CREDS
value: 'true'
- name: ATLANTIS_GH_APP_KEY
valueFrom:
secretKeyRef:
key: latest
name: ATLANTIS_GH_APP_KEY_FILE
- name: ATLANTIS_GH_WEBHOOK_SECRET
valueFrom:
secretKeyRef:
key: latest
name: ATLANTIS_GH_WEBHOOK_SECRET
![ucpr](https://res.cloudinary.com/zenn/image/fetch/s--AhjPuP9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/ddd3fee1e7.jpeg)
Cloud Run で払い出された URL に飛ぶと無事起動していそうだった。
起動していそうなので PR を作って動くか試してみる。
resource "google_storage_bucket" "example" {
name = "ucpr-example-gcs"
location = "asia-northeast1"
force_destroy = true
uniform_bucket_level_access = true
}
雑に GCS Bucket を作る tf を作成して PR を作ってみたらコメント帰ってきた。
なんかだめっぽい
![ucpr](https://res.cloudinary.com/zenn/image/fetch/s--AhjPuP9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/ddd3fee1e7.jpeg)
Cloud Run の設定をすべてデフォルトのまま作っていたので、CPU の設定を変えた。
動いた. Apply もできた
![ucpr](https://res.cloudinary.com/zenn/image/fetch/s--AhjPuP9G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/ddd3fee1e7.jpeg)
Atlantis has no external database. Atlantis stores Terraform plan files on disk. If Atlantis loses that data in between a plan and apply cycle, then users will have to re-run plan. Because of this, you may want to provision a persistent disk for Atlantis.
Persistent Disk 置いたりもしたほうがよいだろうけど今回は動かすまで終わり。
元気があったらこのあたりも続けてやってみる。
少し前に発表されてた Cloud Run から GCS Bucket をボリュームとしてマウントできるやつでも動いたりするかな?