Skip to content

Commit

Permalink
ADD: automatic deploy to CloudRun via Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
fileformat committed Sep 10, 2023
1 parent db6af3e commit 9c6e696
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/gcr-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: build

on:
push:
branches:
- main

# Environment variables available to all jobs and steps in this workflow
env:
RUN_PROJECT: ${{ secrets.RUN_PROJECT }}
RUN_REGION: ${{ secrets.RUN_REGION }}
RUN_SERVICE: ${{ secrets.RUN_SERVICE }}

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1

# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@main
with:
project_id: ${{ env.RUN_PROJECT }}
service_account_key: ${{ secrets.GCP_SA_KEY }}

# Configure gcloud CLI
- name: gcloud Set up
run: |
gcloud config set project $RUN_PROJECT
# Build and push image to Google Container Registry
- name: Build
run: |
docker build \
--build-arg COMMIT=${GITHUB_SHA:0:7} \
--build-arg LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
--tag gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA .
- name: GCloud auth to docker
run: |
gcloud auth configure-docker
- name: Push to registry
run: |
docker push gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest

steps:
# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@main
with:
project_id: ${{ env.RUN_PROJECT }}
service_account_key: ${{ secrets.GCP_SA_KEY }}

# Configure gcloud CLI
- name: gcloud Set up
run: |
gcloud config set project $RUN_PROJECT
# Deploy to CloudRun
- name: Deploy $RUN_SERVICE
run: |
gcloud run deploy $RUN_SERVICE \
--allow-unauthenticated \
--image gcr.io/$RUN_PROJECT/$RUN_SERVICE:$GITHUB_SHA \
--platform managed \
--project ${RUN_PROJECT} \
--region $RUN_REGION

0 comments on commit 9c6e696

Please sign in to comment.