12
3

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.

github actionsでGCRにイメージをPushする

Posted at

初めに

こんにちわ、すえけん(@sueken5)です。

今回の記事ではgithub actionsを使ってgcrにイメージをpushする方法を紹介します。

workflow

.github/docker_build.yaml
name: docker_build

on: [push]

env:
  GCP_PROJECT: ${{ secrets.GCP_PROJECT_ID }}
  GCP_REGION: ${{ secrets.GCP_REGION }}

jobs:
  build:
    runs-on: ubuntu-18.04
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v1
      - name: GCP Authenticate
        uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
        with:
          version: '275.0.0'
          service_account_email: ${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }}
          service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
      - name: Configure docker to use the gcloud cli
        run: gcloud auth configure-docker --quiet
      - name: Build a docker image
        run: docker build -t asia.gcr.io/${{ secrets.GCP_PROJECT_ID }}/sueken:${GITHUB_SHA::7} ./canary
      - name: Push the docker image
        run: docker push asia.gcr.io/${{ secrets.GCP_PROJECT_ID }}/sueken:${GITHUB_SHA::7}

ワークフローはこんな感じです。

必要なシークレット

必要なシークレットは4つあります。

  • GCP_PROJECT_ID(gcpのプロジェクトID)
  • GCP_REGION(リージョン)
  • GCP_SERVICE_ACCOUNT_EMAIL(storage.adminの権限を持つサービスアカウントのemail)
  • GCP_SERVICE_ACCOUNT_KEY(サービスアカウントのjsonキーをbase64でエンコードしたもの)

注意なのですが、GCP_SERVICE_ACCOUNT_KEYはbase64でエンコードする必要があります。

まとめ

github actionsは開拓のしがいがあってとても良いです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?