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