CDソース追加(gcp )

This commit is contained in:
ry.yamafuji 2025-12-05 20:40:52 +09:00
parent 6cb9f550f7
commit 6d141ca131
3 changed files with 64 additions and 0 deletions

38
.github/workflows/deploy_to_gcp.yml vendored Normal file
View File

@ -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

7
.gitignore vendored
View File

@ -172,3 +172,10 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
# terraform.tfstate files
_*.tfvars
.terraform/
.terraform.lock.hcl
*.tfstate
*.tfstate.backup
*deploy.env

View File

@ -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}" \