6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CircleCIでGAE/Go 1.12 へデプロイする

Posted at

やりたいこと

  • GitHubにPushしたタイミングでGAEにデプロイする
  • CircleCIを使って実現する

circleci/gcp-cli @1.8.2 を使ってGAEへデプロイする

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

GitHub

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?