事前準備
- Service Account の作成
- Service Account ロールの付与
- Service Account Key の作成及び
base64化 -
GitHub Repo -> Settings -> SecretsでSecretsの追加
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