0
0

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.

WerckerからGAEにデプロイ

Posted at

werckerからGAEにデプロイした時にハマったポイントを纏めてみました。

前提

Rails5.1でwerckerからGAEにデプロイするようにしています。
Rubyなので、フレキシブル環境になります。

ただ、Rails以外でも使える部分はあるのかな?って思います。

最終的なwrecker.yml

box: ruby:2.4.1
deploy:
  steps:
    - bundle-install:
        without: test,development
    - create-file:
        name: write credentials.json
        filename: .credentials.json
        overwrite: true
        hide-from-log: true
        content: $GCLOUD_CREDENTIALS
    - script:
        name: Install gcloud
        code: |
          curl https://sdk.cloud.google.com | bash
          source /root/google-cloud-sdk/completion.bash.inc
          source /root/google-cloud-sdk/path.bash.inc
    - script:
        name: deploy to google app engine
        code: |
          gcloud auth activate-service-account $GCLOUD_SERVICE_ACCOUNT --key-file .credentials.json --project $GCLOUD_PROJECT_ID
          gcloud app deploy

解説

bundle-install

- bundle-install:
    without: test,development

これは、試していないけど、多分いらない

create-file

- create-file:
    name: write credentials.json
    filename: .credentials.json
    overwrite: true
    hide-from-log: true
    content: $GCLOUD_CREDENTIALS

$GCLOUD_CREDENTIALSは、サービスアカウントの認証キーのjsonです。p12だとバイナリ?で、wercker管理画面から設定できないので、jsonにしています。

注意点は、jsonファイル中の改行文字\nはエスケープしてあげないと\\nないとビルドが落ちます。

werckerがファイルつくるときに、\nを改行コードに変換してしまっているのではないかな?

Install gcloud

- script:
    name: Install gcloud
    code: |
      curl https://sdk.cloud.google.com | bash
      source /root/google-cloud-sdk/completion.bash.inc
      source /root/google-cloud-sdk/path.bash.inc

boxをgoogle/cloud-sdkにしている人は、不要だと思いますが、rubyにしている私は必要でした。 gcloudコマンド利用できるようにしています。

deploy to google app engine

- script:
    name: deploy to google app engine
    code: |
      gcloud auth activate-service-account $GCLOUD_SERVICE_ACCOUNT --key-file .credentials.json --project $GCLOUD_PROJECT_ID
      gcloud app deploy

$GCLOUD_SERVICE_ACCOUNTはサービスアカウントのメールアドレス(xxxxx@xxxxxx.iam.gserviceaccount.com)
$GCLOUD_PROJECT_IDはProjectID

注意点は、サービスアカウントに権限がないと落ちます。
私の場合は、以下でした。
スクリーンショット 2018-01-02 8.55.01.png

以下は必須。

  • App Engine 管理者(デプロイ担当者でも大丈夫かも)
  • Cloud Container Builder(フレキシブル環境だから?)
  • Cumpute Admin(フレキシブル環境だから?)

他は、CloudStorage、StackDriverとか利用するので、入れましたが、ないとダメなのか試していないです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?