1
1

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】CloudRun にデポロイする

1
Posted at

事前準備

  • Service Account の作成
  • Service Account ロールの付与
  • Service Account Key の作成及び base64
  • GitHub Repo -> Settings -> SecretsSecrets の追加

Build Script

name: example

on:
  push:
    branches:
      - master

env:
  GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
  GCP_REGION: ${{ secrets.GCP_REGION }}
  ECR_REGISTRY: gcr.io/${{ secrets.GCP_PROJECT }}
  ECR_REPOSITORY: Example
  CLOUDRUN_SERVICE: Example

jobs:
  # Docker Build
  Build:
    runs-on: ubuntu-latest

    steps:
      # checkout
      - uses: actions/checkout@master

      # install nodejs
      - uses: actions/setup-node@master
        with:
          node-version: 12.x

      # GCP Login
      - name: GCP Authenticate
        uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
        with:
          version: '290.0.1'
          service_account_email: ${{ secrets.GCP_SA_EMAIL }}
          service_account_key: ${{ secrets.GCP_SA_KEY }}
          export_default_credentials: true

      # Library install
      - name: install and build
        run: |
          yarn install
          yarn build

      # Configure docker to use the gcloud command-line tool as a credential helper
      - name: Set up docker to authenticate via gcloud command-line tool.
        run: |
          gcloud auth configure-docker

      # GCR Push
      - name: Push the docker image
        run: |
          docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest
          docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest

      # CloudRun Deploy
      - name: Deploy to Cloud Run
        run: |
          gcloud run deploy $CLOUDRUN_SERVICE \
            --image $ECR_REGISTRY/$ECR_REPOSITORY:latest \
            --project $GCP_PROJECT \
            --region $GCP_REGION \
            --platform managed \
            --quiet
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?