Skip to content

Commit

Permalink
Merge pull request #29 from onflow/main
Browse files Browse the repository at this point in the history
Add Cloud Run support
  • Loading branch information
sjonpaulbrown authored Jun 4, 2024
2 parents 099245d + 6d69cce commit c7c4f9f
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 543 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/deploy-to-cloudrun-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: "Deploy to Production Cloud Run"

on:
push:
branches:
- prod-gcp

env:

# DB VARS
db_username: ${{ secrets.DB_USERNAME }}
db_password: ${{ secrets.DB_PASSWORD }}
db_hostname: ${{ secrets.DB_HOSTNAME }}
db_port: ${{ secrets.DB_PORT }}
db_name: ${{ secrets.DB_NAME }}
backend_api: ${{ secrets.BACKEND_API }}
tx_options: ${{ secrets.TX_OPTIONS }}
hotjar_site_id: ${{ secrets.HOTJAR_STAGE_ID }}
sentry_url: ${{ secrets.SENTRY_STAGE_URL }}

# GCP VARS
BACKEND_DOCKER_IMAGE_URL: ${{ vars.BACKEND_GCP_DOCKER_IMAGE_URL }}:${{ github.sha }}
FRONTEND_DOCKER_IMAGE_URL: ${{ vars.FRONTEND_GCP_DOCKER_IMAGE_URL }}:${{ github.sha }}
GAR_LOCATION: ${{ vars.GCP_GAR_LOCATION }}
PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}
SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.SERVICE_ACCOUNT }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ env.PROJECT_ID }}

- name: Build CAST Backend
run: |-
gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev
docker build -t ${{ env.BACKEND_DOCKER_IMAGE_URL }} --file backend/Dockerfile ./backend
docker push ${{ env.BACKEND_DOCKER_IMAGE_URL }}
- name: Build CAST Frontend
env:
BACKEND: ${{ env.backend_api }}
run: |
gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev
docker build -f ./frontend/Dockerfile ./frontend -t ${{ env.FRONTEND_DOCKER_IMAGE_URL }}
docker push ${{ env.FRONTEND_DOCKER_IMAGE_URL }}
deploy-production-backend:
needs: [build]
environment: production
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GCP_SERVICE_ACCOUNT }}

- name: Deploy Backend to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ vars.BACKEND_GCP_SERVICE }}
image: ${{ env.BACKEND_DOCKER_IMAGE_URL }}

- name: Deploy Frontend to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ vars.FRONTEND_GCP_SERVICE }}
image: ${{ env.FRONTEND_DOCKER_IMAGE_URL }}

96 changes: 96 additions & 0 deletions .github/workflows/deploy-to-cloudrun-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: "Deploy to Staging Cloud Run"

on:
push:
branches:
- staging

env:

# DB VARS
db_username: ${{ secrets.DB_USERNAME }}
db_password: ${{ secrets.DB_PASSWORD }}
db_hostname: ${{ secrets.DB_HOSTNAME }}
db_port: ${{ secrets.DB_PORT }}
db_name: ${{ secrets.DB_NAME }}
backend_api: ${{ secrets.BACKEND_API }}
tx_options: ${{ secrets.TX_OPTIONS }}
hotjar_site_id: ${{ secrets.HOTJAR_STAGE_ID }}
sentry_url: ${{ secrets.SENTRY_STAGE_URL }}

# GCP VARS
BACKEND_DOCKER_IMAGE_URL: ${{ vars.BACKEND_GCP_DOCKER_IMAGE_URL }}:${{ github.sha }}
FRONTEND_DOCKER_IMAGE_URL: ${{ vars.FRONTEND_GCP_DOCKER_IMAGE_URL }}:${{ github.sha }}
GAR_LOCATION: ${{ vars.GCP_GAR_LOCATION }}
PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}
SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.SERVICE_ACCOUNT }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ env.PROJECT_ID }}

- name: Docker Auth
run: |-
gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev
docker build -t ${{ env.BACKEND_DOCKER_IMAGE_URL }} --file backend/Dockerfile ./backend
docker push ${{ env.BACKEND_DOCKER_IMAGE_URL }}
- name: build and push frontend - stage -
env:
BACKEND: ${{ env.backend_api }}
run: |
gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev
docker build -f ./frontend/Dockerfile.stage ./frontend -t ${{ env.FRONTEND_DOCKER_IMAGE_URL }}
docker push ${{ env.FRONTEND_DOCKER_IMAGE_URL }}
deploy-staging-backend:
needs: [build]
environment: staging
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GCP_SERVICE_ACCOUNT }}

- name: Deploy Backend to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ vars.BACKEND_GCP_SERVICE }}
image: ${{ env.BACKEND_DOCKER_IMAGE_URL }}

- name: Deploy Frontend to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ vars.FRONTEND_GCP_SERVICE }}
image: ${{ env.FRONTEND_DOCKER_IMAGE_URL }}

27 changes: 0 additions & 27 deletions .github/workflows/update-dev.yaml

This file was deleted.

161 changes: 0 additions & 161 deletions .github/workflows/update-prod.yaml

This file was deleted.

Loading

0 comments on commit c7c4f9f

Please sign in to comment.