デプロイソースを整備する

This commit is contained in:
ry.yamafuji 2025-12-05 23:01:26 +09:00
parent 2edea8d13c
commit 3c1c8159d4
2 changed files with 35 additions and 0 deletions

View File

@ -56,4 +56,13 @@ jobs:
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/sa.json"
./scripts/deploy/plan_terraform.sh
- name: Exec Terraform apply shell
run: |
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/sa.json"
./scripts/deploy/apply_terraform.sh
- name: Clean up Gcloud auth file
run: |
rm -f $HOME/sa.json
echo "Cleaned up Gcloud auth file."

View File

@ -0,0 +1,26 @@
#!/bin/bash
# Safe mode(when error,kill script)
set -euo pipefail
# 変数の設定({HOME}/hash.txt からハッシュ値を取得)
TF_DIR=${TF_DIR:-terraform}
ENV=${ENV:-dev}
cd "$TF_DIR"
# --- デプロイ条件 ---
if [[ "${BRANCH_NAME:-}" =~ ^.*deploy$ ]]; then
echo "Start terraform apply (ENV=${ENV}, DIR=${TF_DIR}) ..."
else
echo "Skip terraform apply (branch=${BRANCH_NAME:-})"
exit 0
fi
# --- plan 結果があるか確認 ---
if [[ ! -f tfplan ]]; then
echo "ERROR: tfplan not found in $(pwd). Run plan step first." >&2
exit 1
fi
terraform apply -auto-approve tfplan