Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Last active February 21, 2022 16:28
Show Gist options
  • Save jmaicaaan/6ee49cafc8125f942110928aefc6bb35 to your computer and use it in GitHub Desktop.
Save jmaicaaan/6ee49cafc8125f942110928aefc6bb35 to your computer and use it in GitHub Desktop.
[Tutorial] Setting up cloud-run.yml for Github Actions
name: nextjs-cloud-run
on:
push:
branches:
- master
- main
env:
CLOUD_RUN_PROJECT_ID: ${{ secrets.CLOUD_RUN_PROJECT_NAME }}
CLOUD_RUN_REGION: asia-northeast1
# project-name but it can be anything you want
REPO_NAME: nextjs-app01-website
jobs:
build-and-deploy:
name: Setup, Build, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# This step is where our service account will be authenticated
- uses: google-github-actions/setup-gcloud@v0.2.0
with:
project_id: ${{ secrets.CLOUD_RUN_PROJECT_NAME }}
service_account_key: ${{ secrets.CLOUD_RUN_SERVICE_ACCOUNT }}
service_account_email: ${{ secrets.CLOUD_RUN_SERVICE_ACCOUNT_EMAIL }}
- name: Enable the necessary APIs and enable docker auth
run: |-
gcloud services enable containerregistry.googleapis.com
gcloud services enable run.googleapis.com
gcloud --quiet auth configure-docker
- name: Build and tag image
run: |-
docker build . --tag "gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA"
- name: Push image to GCR
run: |-
docker push gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA
- name: Deploy
run: |-
gcloud components install beta --quiet
gcloud beta run deploy $REPO_NAME --image gcr.io/$CLOUD_RUN_PROJECT_ID/$REPO_NAME:$GITHUB_SHA \
--project $CLOUD_RUN_PROJECT_ID \
--platform managed \
--region $CLOUD_RUN_REGION \
--allow-unauthenticated \
--quiet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment