やりたいこと
- GitHubにPushしたタイミングでGAEにデプロイする
- CircleCIを使って実現する
circleci/gcp-cli @1.8.2 を使ってGAEへデプロイする
- Orbクイックスタートガイドの通りやる
CircleCI側の設定
-
BUILD SETTINGS >> Environment Variables に環境変数を設定する必要がある
- GOOGLE_PROJECT_ID
- GOOGLE_COMPUTE_ZONE
- GCLOUD_SERVICE_KEY
-
ServiceKeyはJsonをそのままValueにコピーする
{
"type": "service_account",
"project_id": "[PROJECT-ID]",
"private_key_id": "[KEY-ID]",
"private_key": "-----BEGIN PRIVATE KEY-----\n[PRIVATE-KEY]\n-----END PRIVATE KEY-----\n",
"client_email": "[SERVICE-ACCOUNT-EMAIL]",
"client_id": "[CLIENT-ID]",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[SERVICE-ACCOUNT-EMAIL]"
}
config.yaml
config.yaml
version: 2.1
orbs:
gcp-cli: circleci/gcp-cli@1.8.2
jobs:
test:
working_directory: ~/workspace
docker:
- image: circleci/golang:1.12
environment:
GO111MODULE: "on"
steps:
- checkout
- run: go test -v ./...
- persist_to_workspace:
root: .
paths:
- .
build:
working_directory: ~/workspace
docker:
- image: circleci/golang:1.12
steps:
- attach_workspace:
at: .
- restore_cache:
name: Restore go modules cache
keys:
- v1-dependencies-{{ checksum "go.mod" }}
- run: go build ./api/main.go
- save_cache:
name: Save go modules cache
key: v1-dependencies-{{ checksum "go.mod" }}
paths:
- /go/pkg/mod/cache
- persist_to_workspace:
root: .
paths:
- .
deploy-develop:
working_directory: ~/workspace
docker:
- image: google/cloud-sdk:latest
steps:
- attach_workspace:
at: .
- gcp-cli/initialize
- run:
name: Deploy to Google App Engine
command: |
gcloud --quiet app deploy ./api/app-develop.yaml --project=$GOOGLE_PROJECT_ID --version=$CIRCLE_BRANCH
workflows:
version: 2
build:
jobs:
- test
- build:
requires:
- test
- deploy-develop:
requires:
- build