3
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 2.0でGlide管理のGoをGAEにデプロイする

Posted at

Dockerイメージの用意

GitHubで以下のDockerfileを上げて、Docker Hubと連携するなどしてコンテナをダウンロードできる状態にしてください。

Dockerfile
FROM golang:1.9.0
ENV _HOME=/root

RUN apt-get update
RUN apt-get install -y unzip

RUN curl https://glide.sh/get | sh

RUN mkdir $_HOME/download
RUN curl -o $_HOME/download/go_appengine_sdk_1.9.58.zip https://storage.googleapis.com/appengine-sdks/featured/go_appengine_sdk_linux_amd64-1.9.58.zip
RUN unzip -q -d $_HOME $_HOME/download/go_appengine_sdk_1.9.58.zip
ENV PATH=$_HOME/go_appengine:$PATH

RUN curl -sSL https://sdk.cloud.google.com | bash -s -- --disable-prompts
ENV PATH=$_HOME/google-cloud-sdk/bin:$PATH

サービス アカウント キーの取得

  • 場所
    • ツールとサービスAPIとサービス認証情報認証情報を作成 → `サービス アカウント キー
  • 役割
    • App EngineApp Engine デプロイ担当者
  • キーのタイプ
    • JSON

gcloudコマンドで上記で取得したJSONキーファイルを使って認証し、そこから取得できるアクセストークンを使ってgo_appengine_sdkでビルドします。
プロジェクトルートにservice_account_keysフォルダを作成しそこに適宜名前をつけて保存してください。
※公開リポジトリでは必ず下記の作業を行なってください。

CircleCI設定ファイル作成

プロジェクトルートに.circleciフォルダを作成し、その中にconfig.ymlを作成します。

  • docker_hub_namespace/docker_hub_repository_nameはDocker Hubで作成したリポジトリ情報を入れてください
    • Docker Hubでプライベートなリポジトリの場合は、authusernamepasswordを設定することでDockerイメージを取得できます(※GitHubの公開リポジトリには絶対上げない)
  • project_nameには、チェックアウトするソースのプロジェクト名を指定してください
  • appcfg.pyコマンドの最後の引数には、app.yamlがあるディレクトリを指定してください
.circleci/config.yml
version: 2

jobs:
  build:

    docker:
      - image: docker_hub_namespace/docker_hub_repository_name
        auth: # Case Private Repository
          username: username
          password: password

    working_directory: /go/src/project_name

    steps:
      - checkout

      - run: glide i

      - deploy:
          command: |
            if [ "${CIRCLE_BRANCH}" == "develop" ]; then
              gcloud auth activate-service-account --key-file ./service_account_keys/develop.json
              appcfg.py update --oauth2_access_token $(gcloud auth print-access-token) app
            elif [ "${CIRCLE_BRANCH}" == "master" ]; then
              gcloud auth activate-service-account --key-file ./service_account_keys/master.json
              appcfg.py update --oauth2_access_token $(gcloud auth print-access-token) app
            fi

参考: プロジェクトツリー

project_name
 ├─.circleci
 │ └─config.yml
 ├─app
 │ ├─app.yaml
 │ └─index.go
 ├─server
 │ ├─index.go
 │ ├─foo.go
 │ └─bar.go
 ├─glide.lock
 └─glide.yaml

参考文献

3
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
3
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?