Atlantis on Cloud Run の動作検証

目標
Cloud Run 上で Atlantis を動かせるか検証したい
先行事例
適当に atlantis cloud run
で検索したところそれっぽいものは 2 件ヒット

Atlantis のコンテナイメージを作る
をみると GitHub Packages でコンテナイメージを配布していそう.
CMD で server のバイナリが指定されているのでこれを今回はそのまま使う

Cloud Run で ghcr のコンテナイメージをそのまま指定できなかったので自分の GCP Project の Artifact Registry に tag 変えて持っていった

Atlantis のインストールはとりあえず公式ドキュメントに従う
今回は GitHub App での設定で進める。
検証なのでとりあえずコンソールでポチポチサービスを作る。
GH_USER と GH_TOKEN と PORT さえ指定していたら起動するのでサービスを作って、Cloud Run が吐く URL を取得する。
その後 ATLANTIS_ATLANTIS_URL
を指定しつつ、 GItHub App の設定をドキュメント通りに進める

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

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 を作ってみたらコメント帰ってきた。
なんかだめっぽい

Cloud Run の設定をすべてデフォルトのまま作っていたので、CPU の設定を変えた。
動いた. Apply もできた

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 をボリュームとしてマウントできるやつでも動いたりするかな?

📝 Cloud Run で GCS Fuse でマウントして試してみたけど厳しいかも
running git clone --depth=1 --branch update-version --single-branch https://github.com/ucpr/infra.git /atlantis/repos/ucpr/infra/9/default: Cloning into '/atlantis/repos/ucpr/infra/9/default'...
error: chmod on /atlantis/repos/ucpr/infra/9/default/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
: exit status 128