From 6d141ca131d2a2194ef43a87398c5af827fad8d5 Mon Sep 17 00:00:00 2001 From: "ry.yamafuji" Date: Fri, 5 Dec 2025 20:40:52 +0900 Subject: [PATCH] =?UTF-8?q?CD=E3=82=BD=E3=83=BC=E3=82=B9=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?(gcp=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy_to_gcp.yml | 38 +++++++++++++++++++++++++++++ .gitignore | 7 ++++++ scripts/deploy/init_terraform.sh | 19 +++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .github/workflows/deploy_to_gcp.yml create mode 100644 scripts/deploy/init_terraform.sh diff --git a/.github/workflows/deploy_to_gcp.yml b/.github/workflows/deploy_to_gcp.yml new file mode 100644 index 0000000..051d0dd --- /dev/null +++ b/.github/workflows/deploy_to_gcp.yml @@ -0,0 +1,38 @@ +name: Gitea Deploy to GCP + +on: + workflow_dispatch: + + pull_request: + branches: + - deploy-prd + - deploy-dev + paths: + - 'src/**' + - 'terraform/**' + +jobs: + deploy: + name: Deploy to GCP + runs-on: gcloud-tf + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Check Deploy Tools + run: | + gcloud --version + terraform --version + + + # - name: Set up Cloud SDK + # uses: google-github-actions/setup-gcloud@v1 + # with: + # project_id: ${{ secrets.GCP_PROJECT_ID }} + # service_account_key: ${{ secrets.GCP_SA_KEY }} + # export_default_credentials: true + + # - name: Run deployment script + # run: | + # chmod +x ./deploy.sh + # ./deploy.sh diff --git a/.gitignore b/.gitignore index 00b439c..2015f53 100644 --- a/.gitignore +++ b/.gitignore @@ -172,3 +172,10 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +# terraform.tfstate files +_*.tfvars +.terraform/ +.terraform.lock.hcl +*.tfstate +*.tfstate.backup +*deploy.env \ No newline at end of file diff --git a/scripts/deploy/init_terraform.sh b/scripts/deploy/init_terraform.sh new file mode 100644 index 0000000..7e57d64 --- /dev/null +++ b/scripts/deploy/init_terraform.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Safe mode(when error,kill script) +set -euo pipefail + +TF_DIR=${TF_DIR:-terraform} + +# GCS S3などで保存する +TF_STATE_BUCKET=${TF_STATE_BUCKET:-cicd-tfstate-bucket} +ENV=${ENV:-dev} +REPO_NAME=${REPO_NAME:-unknown} + +cd "$TF_DIR" + +# --- terraform init 実行 --- +terraform init \ + -backend-config="bucket=${TF_STATE_BUCKET}" \ + -backend-config="prefix=${REPO_NAME}/${ENV}" \ + \ No newline at end of file