mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
546 lines
20 KiB
YAML
546 lines
20 KiB
YAML
name: Deploy Preview to Cloud Run
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
cache_key:
|
|
description: Optional cache key component to force invalidation of the build cache.
|
|
required: false
|
|
default: ""
|
|
pull_request:
|
|
types:
|
|
- opened
|
|
- reopened
|
|
- synchronize
|
|
|
|
env:
|
|
PROJECT_ID: metagame-thegame
|
|
REGISTRY_REGION: us-east4
|
|
REGISTRY_REPO: thegame
|
|
DEPLOYMENT_DOMAIN: a.run.app
|
|
CLOUDRUN_SUFFIX: mjhnbmqqna-uk
|
|
DEPLOYMENT_ENV: Test-PR-${{github.event.number}}
|
|
DB_NAME: hasura-pr-${{github.event.number}}
|
|
BACKEND_SERVICE: backend-pr-${{github.event.number}}
|
|
FRONTEND_SERVICE: frontend-pr-${{github.event.number}}
|
|
BACKEND_PORT: 4000
|
|
HASURA_PORT: 8080
|
|
FRONTEND_PORT: 3000
|
|
HASURA_SECRET: metagame_secret
|
|
GA4_ID: G-B1NKK3Q1BP
|
|
|
|
jobs:
|
|
start-deployment:
|
|
name: Generate Deployment Start Message
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
deployment_id: ${{steps.create-message.outputs.deployment_id}}
|
|
|
|
steps:
|
|
- name: Start Deployment
|
|
uses: bobheadxi/deployments@v1
|
|
id: create-message
|
|
with:
|
|
step: start
|
|
token: ${{github.token}}
|
|
env: ${{env.DEPLOYMENT_ENV}}
|
|
desc: "Test instance deployment for PR #${{github.event.number}} of ${{github.event.pull_request.head.label}} by ${{github.event.pull_request.user.login}}"
|
|
ref: ${{github.head_ref}}
|
|
auto_inactive: false
|
|
logs: https://github.com/${{github.repository}}/commit/${{github.event.after}}/checks
|
|
|
|
cancel-previous:
|
|
name: Cancel Existing Runs
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Cancel Existing Runs
|
|
uses: styfle/cancel-workflow-action@0.10.0
|
|
with:
|
|
access_token: ${{github.token}}
|
|
|
|
env:
|
|
name: Environment Variables
|
|
runs-on: ubuntu-latest
|
|
needs: [cancel-previous]
|
|
|
|
outputs:
|
|
PROJECT_ID: ${{env.PROJECT_ID}}
|
|
REGISTRY_REGION: ${{env.REGISTRY_REGION}}
|
|
REGISTRY_REPO: ${{env.REGISTRY_REPO}}
|
|
DEPLOYMENT_DOMAIN: ${{env.DEPLOYMENT_DOMAIN}}
|
|
CLOUDRUN_SUFFIX: ${{env.CLOUDRUN_SUFFIX}}
|
|
DB_NAME: ${{env.DB_NAME}}
|
|
BACKEND_SERVICE: ${{env.BACKEND_SERVICE}}
|
|
FRONTEND_SERVICE: ${{env.FRONTEND_SERVICE}}
|
|
BACKEND_PORT: ${{env.BACKEND_PORT}}
|
|
HASURA_PORT: ${{env.HASURA_PORT}}
|
|
FRONTEND_PORT: ${{env.FRONTEND_PORT}}
|
|
HASURA_SECRET: ${{env.HASURA_SECRET}}
|
|
CLOUDRUN_REGION: ${{steps.first.outputs.CLOUDRUN_REGION}}
|
|
CLOUDSQL_INSTANCE_NAME: ${{steps.first.outputs.CLOUDSQL_INSTANCE_NAME}}
|
|
CLOUDSQL_CONNECTION_NAME: ${{steps.first.outputs.CLOUDSQL_CONNECTION_NAME}}
|
|
HASURA_SERVICE: ${{steps.first.outputs.HASURA_SERVICE}}
|
|
DOCKER_REGISTRY: ${{steps.first.outputs.DOCKER_REGISTRY}}
|
|
BACKEND_HOST: ${{steps.first.outputs.BACKEND_HOST}}
|
|
FRONTEND_URL: ${{steps.first.outputs.FRONTEND_URL}}
|
|
DB_PASSWORD: ${{steps.first.outputs.DB_PASSWORD}}
|
|
HASURA_HOST: ${{steps.second.outputs.HASURA_HOST}}
|
|
DOCKER_PATH: ${{steps.second.outputs.DOCKER_PATH}}
|
|
SC_MIGRATE_URL: ${{steps.second.outputs.SC_MIGRATE_URL}}
|
|
DB_HOST: ${{steps.second.outputs.DB_HOST}}
|
|
GRAPHQL_URL: ${{steps.third.outputs.GRAPHQL_URL}}
|
|
BACKEND_TAG: ${{steps.third.outputs.BACKEND_TAG}}
|
|
HASURA_TAG: ${{steps.third.outputs.HASURA_TAG}}
|
|
FRONTEND_TAG: ${{steps.third.outputs.FRONTEND_TAG}}
|
|
|
|
steps:
|
|
- name: First Intepolation of Variables
|
|
id: first
|
|
run: |
|
|
echo "::set-output name=CLOUDRUN_REGION::${{env.REGISTRY_REGION}}"
|
|
echo "::set-output name=CLOUDSQL_INSTANCE_NAME::${{env.REGISTRY_REPO}}"
|
|
echo "::set-output name=CLOUDSQL_CONNECTION_NAME::\
|
|
${{env.PROJECT_ID}}:${{env.REGISTRY_REGION}}:${{env.REGISTRY_REPO}}"
|
|
echo "::set-output name=HASURA_SERVICE::${{env.DB_NAME}}"
|
|
echo "::set-output name=DOCKER_REGISTRY::${{env.REGISTRY_REGION}}-docker.pkg.dev"
|
|
echo "::set-output name=BACKEND_HOST::\
|
|
${{env.BACKEND_SERVICE}}-${{env.CLOUDRUN_SUFFIX}}.${{env.DEPLOYMENT_DOMAIN}}"
|
|
echo "::set-output name=FRONTEND_URL::\
|
|
https://${{env.FRONTEND_SERVICE}}-${{env.CLOUDRUN_SUFFIX}}.${{env.DEPLOYMENT_DOMAIN}}"
|
|
echo "::set-output name=DB_PASSWORD::$(head -c 48 /dev/urandom | tr -cd [:alnum:])"
|
|
|
|
- name: Those Variables May Now Be Interpolated
|
|
id: second
|
|
run: |
|
|
echo "::set-output name=HASURA_HOST::\
|
|
${{steps.first.outputs.HASURA_SERVICE}}-${{env.CLOUDRUN_SUFFIX}}.${{env.DEPLOYMENT_DOMAIN}}"
|
|
echo "::set-output name=DOCKER_PATH::\
|
|
${{steps.first.outputs.DOCKER_REGISTRY}}/${{env.PROJECT_ID}}/${{env.REGISTRY_REPO}}"
|
|
echo "::set-output name=SC_MIGRATE_URL::\
|
|
https://${{steps.first.outputs.BACKEND_HOST}}/actions/migrateSourceCredAccounts?force=true"
|
|
echo "::set-output name=DB_HOST::\
|
|
/${{env.DB_NAME}}?host=/cloudsql/${{steps.first.outputs.CLOUDSQL_CONNECTION_NAME}}"
|
|
|
|
- name: And That Result Again In Another Step
|
|
id: third
|
|
run: |
|
|
echo "::set-output name=GRAPHQL_URL::\
|
|
https://${{steps.second.outputs.HASURA_HOST}}/v1/graphql"
|
|
echo "::set-output name=BACKEND_TAG::\
|
|
${{steps.second.outputs.DOCKER_PATH}}/backend:pr-${{github.event.number}}"
|
|
echo "::set-output name=HASURA_TAG::\
|
|
${{steps.second.outputs.DOCKER_PATH}}/hasura:pr-${{github.event.number}}"
|
|
echo "::set-output name=FRONTEND_TAG::\
|
|
${{steps.second.outputs.DOCKER_PATH}}/frontend:pr-${{github.event.number}}"
|
|
|
|
delete-db:
|
|
name: Delete SQL User & Database
|
|
runs-on: ubuntu-latest
|
|
needs: [env]
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Delete SQL User: ${{needs.env.outputs.DB_NAME}}"
|
|
continue-on-error: true
|
|
run: |
|
|
gcloud -q sql users delete ${{needs.env.outputs.DB_NAME}} \
|
|
-i ${{needs.env.outputs.CLOUDSQL_INSTANCE_NAME}}
|
|
|
|
- name: "Delete Database: ${{needs.env.outputs.DB_NAME}}"
|
|
continue-on-error: true
|
|
run: |
|
|
wget -q https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
|
|
chmod u+x cloud_sql_proxy
|
|
./cloud_sql_proxy -instances ${{needs.env.outputs.CLOUDSQL_CONNECTION_NAME}} \
|
|
-dir /tmp/cloudsql &
|
|
PID=$!
|
|
sleep 10
|
|
PGPASSWORD=${{secrets.GCP_POSTGRES_PASSWORD}} \
|
|
dropdb -h /tmp/cloudsql/${{needs.env.outputs.CLOUDSQL_CONNECTION_NAME}} \
|
|
-U postgres ${{needs.env.outputs.DB_NAME}} -f
|
|
kill $PID
|
|
|
|
create-db:
|
|
name: Create New SQL User & Database
|
|
runs-on: ubuntu-latest
|
|
needs: [env, delete-db]
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Create SQL User: ${{needs.env.outputs.DB_NAME}}"
|
|
run: |
|
|
gcloud -q sql users create ${{needs.env.outputs.DB_NAME}} \
|
|
-i ${{needs.env.outputs.CLOUDSQL_INSTANCE_NAME}} \
|
|
--password ${{needs.env.outputs.DB_PASSWORD}}
|
|
|
|
- name: "Create Database: ${{needs.env.outputs.DB_NAME}}"
|
|
run: |
|
|
gcloud -q sql databases create ${{needs.env.outputs.DB_NAME}} \
|
|
-i ${{needs.env.outputs.CLOUDSQL_INSTANCE_NAME}}
|
|
|
|
undeploy-backend:
|
|
name: Undeploy Backend
|
|
runs-on: ubuntu-latest
|
|
needs: [env]
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Delete Service: ${{needs.env.outputs.BACKEND_SERVICE}}"
|
|
continue-on-error: true
|
|
run: |
|
|
gcloud -q run services delete ${{needs.env.outputs.BACKEND_SERVICE}} \
|
|
--region ${{needs.env.outputs.CLOUDRUN_REGION}}
|
|
|
|
delete-backend:
|
|
name: Delete Backend Container Image
|
|
runs-on: ubuntu-latest
|
|
needs: [env]
|
|
|
|
steps:
|
|
- name: "Login to Registry: ${{needs.env.outputs.DOCKER_REGISTRY}}"
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{needs.env.outputs.DOCKER_REGISTRY}}
|
|
username: _json_key
|
|
password: ${{secrets.GCP_SA_KEY}}
|
|
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Delete Container Image: ${{needs.env.outputs.BACKEND_TAG}}"
|
|
continue-on-error: true
|
|
run: gcloud -q artifacts docker images delete ${{needs.env.outputs.BACKEND_TAG}}
|
|
|
|
build-backend:
|
|
name: Build Backend Container Image
|
|
runs-on: ubuntu-latest
|
|
needs: [env, delete-backend, undeploy-backend]
|
|
|
|
steps:
|
|
- name: "Checkout: ${{github.event.pull_request.head.label}}"
|
|
uses: actions/checkout@v2
|
|
with:
|
|
ref: ${{github.event.pull_request.head.sha}}
|
|
|
|
- name: "Build Container Image: ${{needs.env.outputs.BACKEND_TAG}}"
|
|
uses: mattes/cached-docker-build-action@v1
|
|
with:
|
|
args: |
|
|
. -f docker/backend/Dockerfile \
|
|
--tag ${{needs.env.outputs.BACKEND_TAG}} \
|
|
--build-arg GRAPHQL_URL=${{needs.env.outputs.GRAPHQL_URL}}
|
|
cache_key: "${{github.event.inputs.cache_key}}-${{hashFiles('packages/backend/**', 'packages/utils/**', 'package.json')}}"
|
|
|
|
- name: "Login to Registry: ${{needs.env.outputs.DOCKER_REGISTRY}}"
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{needs.env.outputs.DOCKER_REGISTRY}}
|
|
username: _json_key
|
|
password: ${{secrets.GCP_SA_KEY}}
|
|
|
|
- name: "Push Container Image: ${{needs.env.outputs.BACKEND_TAG}}"
|
|
run: docker push ${{needs.env.outputs.BACKEND_TAG}}
|
|
|
|
deploy-backend:
|
|
name: Deploy Backend
|
|
runs-on: ubuntu-latest
|
|
needs: [env, create-db, build-backend]
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Deploy Container Image: ${{needs.env.outputs.BACKEND_TAG}}"
|
|
run: |
|
|
gcloud -q run deploy ${{needs.env.outputs.BACKEND_SERVICE}} \
|
|
--image ${{needs.env.outputs.BACKEND_TAG}} \
|
|
--region ${{needs.env.outputs.CLOUDRUN_REGION}} \
|
|
--port ${{needs.env.outputs.BACKEND_PORT}} \
|
|
--cpu 1 \
|
|
--memory 768Mi \
|
|
--ingress all \
|
|
--allow-unauthenticated \
|
|
--max-instances 1 \
|
|
--set-env-vars HASURA_GRAPHQL_ADMIN_SECRET=${{needs.env.outputs.HASURA_SECRET}} \
|
|
--set-env-vars GITHUB_API_TOKEN=${{secrets.GH_API_TOKEN}} \
|
|
--set-env-vars SOURCECRED_LEDGER_BRANCH=master \
|
|
--set-env-vars GRAPHQL_URL=${{needs.env.outputs.GRAPHQL_URL}} \
|
|
--set-env-vars DISCORD_BOT_TOKEN=${{secrets.DISCORD_BOT_TOKEN}}
|
|
|
|
undeploy-hasura:
|
|
name: Undeploy Hasura
|
|
runs-on: ubuntu-latest
|
|
needs: [env]
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Delete Service: ${{needs.env.outputs.HASURA_SERVICE}}"
|
|
continue-on-error: true
|
|
run: |
|
|
gcloud -q run services delete ${{needs.env.outputs.HASURA_SERVICE}} \
|
|
--region ${{needs.env.outputs.CLOUDRUN_REGION}}
|
|
|
|
delete-hasura:
|
|
name: Delete Hasura Container Image
|
|
runs-on: ubuntu-latest
|
|
needs: [env]
|
|
|
|
steps:
|
|
- name: "Login to Registry: ${{needs.env.outputs.DOCKER_REGISTRY}}"
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{needs.env.outputs.DOCKER_REGISTRY}}
|
|
username: _json_key
|
|
password: ${{secrets.GCP_SA_KEY}}
|
|
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Delete Container Image: ${{needs.env.outputs.HASURA_TAG}}"
|
|
continue-on-error: true
|
|
run: gcloud -q artifacts docker images delete ${{needs.env.outputs.HASURA_TAG}}
|
|
|
|
build-hasura:
|
|
name: Build Hasura Container Image
|
|
runs-on: ubuntu-latest
|
|
needs: [env, delete-hasura, undeploy-hasura]
|
|
|
|
steps:
|
|
- name: "Checkout: ${{github.event.pull_request.head.label}}"
|
|
uses: actions/checkout@v2
|
|
with:
|
|
ref: ${{github.event.pull_request.head.sha}}
|
|
|
|
- name: "Build Container Image: ${{needs.env.outputs.HASURA_TAG}}"
|
|
uses: mattes/cached-docker-build-action@v1
|
|
with:
|
|
args: |
|
|
./hasura -f hasura/Dockerfile \
|
|
--tag ${{needs.env.outputs.HASURA_TAG}} \
|
|
--build-arg BACKEND_HOST=${{needs.env.outputs.BACKEND_HOST}} \
|
|
--build-arg BACKEND_PROTOCOL=https
|
|
cache_key: "${{github.event.inputs.cache_key}}-${{hashFiles('hasura/**', 'package.json')}}"
|
|
|
|
- name: "Login to Registry: ${{needs.env.outputs.DOCKER_REGISTRY}}"
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{needs.env.outputs.DOCKER_REGISTRY}}
|
|
username: _json_key
|
|
password: ${{secrets.GCP_SA_KEY}}
|
|
|
|
- name: "Push Container Image: ${{needs.env.outputs.HASURA_TAG}}"
|
|
run: docker push ${{needs.env.outputs.HASURA_TAG}}
|
|
|
|
deploy-hasura:
|
|
name: Deploy Hasura
|
|
runs-on: ubuntu-latest
|
|
needs: [env, build-hasura, deploy-backend]
|
|
|
|
env:
|
|
db: ${{needs.env.outputs.DB_NAME}}
|
|
pass: ${{needs.env.outputs.DB_PASSWORD}}
|
|
host: ${{needs.env.outputs.DB_HOST}}
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Deploy Container Image: ${{needs.env.outputs.HASURA_TAG}}"
|
|
run: |
|
|
gcloud -q run deploy ${{needs.env.outputs.HASURA_SERVICE}} \
|
|
--image ${{needs.env.outputs.HASURA_TAG}} \
|
|
--region ${{needs.env.outputs.CLOUDRUN_REGION}} \
|
|
--port ${{needs.env.outputs.HASURA_PORT}} \
|
|
--cpu 1 \
|
|
--memory 512Mi \
|
|
--ingress all \
|
|
--allow-unauthenticated \
|
|
--add-cloudsql-instances ${{needs.env.outputs.CLOUDSQL_CONNECTION_NAME}} \
|
|
--max-instances 1 \
|
|
--set-env-vars HASURA_GRAPHQL_DATABASE_URL=postgres://${{env.db}}:${{env.pass}}@${{env.host}} \
|
|
--set-env-vars HASURA_GRAPHQL_ADMIN_SECRET=${{needs.env.outputs.HASURA_SECRET}} \
|
|
--set-env-vars HASURA_GRAPHQL_SERVER_PORT=${{needs.env.outputs.HASURA_PORT}} \
|
|
--set-env-vars HASURA_GRAPHQL_ENABLE_CONSOLE=true
|
|
|
|
undeploy-frontend:
|
|
name: Undeploy Frontend
|
|
runs-on: ubuntu-latest
|
|
needs: [env]
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Delete Service: ${{needs.env.outputs.FRONTEND_SERVICE}}"
|
|
continue-on-error: true
|
|
run: |
|
|
gcloud -q run services delete ${{needs.env.outputs.FRONTEND_SERVICE}} \
|
|
--region ${{needs.env.outputs.CLOUDRUN_REGION}}
|
|
|
|
delete-frontend:
|
|
name: Delete Frontend Container Image
|
|
runs-on: ubuntu-latest
|
|
needs: [env]
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Delete Container Image: ${{needs.env.outputs.FRONTEND_TAG}}"
|
|
continue-on-error: true
|
|
run: gcloud -q artifacts docker images delete ${{needs.env.outputs.FRONTEND_TAG}}
|
|
|
|
build-frontend:
|
|
name: Build Frontend Container Image
|
|
runs-on: ubuntu-latest
|
|
needs: [env, delete-frontend, undeploy-frontend, deploy-hasura, seed-db]
|
|
|
|
steps:
|
|
- name: "Checkout: ${{github.event.pull_request.head.label}}"
|
|
uses: actions/checkout@v2
|
|
with:
|
|
ref: ${{github.event.pull_request.head.sha}}
|
|
|
|
- name: "Build Container Image: ${{needs.env.outputs.FRONTEND_TAG}}"
|
|
uses: mattes/cached-docker-build-action@v1
|
|
with:
|
|
args: |
|
|
. -f docker/frontend/Dockerfile \
|
|
--tag ${{needs.env.outputs.FRONTEND_TAG}} \
|
|
--build-arg GRAPHQL_URL=${{needs.env.outputs.GRAPHQL_URL}} \
|
|
--build-arg NEXT_PUBLIC_FRONTEND_URL=${{needs.env.outputs.FRONTEND_URL}} \
|
|
--build-arg NEXT_PUBLIC_YOUTUBE_API_KEY=${{secrets.YOUTUBE_API_KEY}}
|
|
cache_key: "${{github.event.inputs.cache_key}}-${{hashFiles('packages/web/**', 'packages/design-system/**', 'packages/utils/**', 'package.json')}}"
|
|
|
|
- name: "Login to Registry: ${{needs.env.outputs.DOCKER_REGISTRY}}"
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{needs.env.outputs.DOCKER_REGISTRY}}
|
|
username: _json_key
|
|
password: ${{secrets.GCP_SA_KEY}}
|
|
|
|
- name: "Push Container Image: ${{needs.env.outputs.FRONTEND_TAG}}"
|
|
run: docker push ${{needs.env.outputs.FRONTEND_TAG}}
|
|
|
|
deploy-frontend:
|
|
name: Deploy Frontend
|
|
runs-on: ubuntu-latest
|
|
needs: [env, build-frontend]
|
|
|
|
steps:
|
|
- name: Set Up gcloud CLI
|
|
uses: google-github-actions/setup-gcloud@v0.6.0
|
|
with:
|
|
project_id: ${{needs.env.outputs.PROJECT_ID}}
|
|
service_account_key: ${{secrets.GCP_SA_KEY}}
|
|
export_default_credentials: true
|
|
|
|
- name: "Deploy Container Image: ${{needs.env.outputs.FRONTEND_SERVICE}}"
|
|
run: |
|
|
gcloud -q run deploy ${{needs.env.outputs.FRONTEND_SERVICE}} \
|
|
--image ${{needs.env.outputs.FRONTEND_TAG}} \
|
|
--region ${{needs.env.outputs.CLOUDRUN_REGION}} \
|
|
--port ${{needs.env.outputs.FRONTEND_PORT}} \
|
|
--cpu 1 \
|
|
--memory 512Mi \
|
|
--ingress all \
|
|
--max-instances 1 \
|
|
--allow-unauthenticated \
|
|
--set-env-vars WEB3_STORAGE_TOKEN=${{secrets.WEB3_STORAGE_TOKEN}} \
|
|
--set-env-vars OPENSEA_API_KEY=${{secrets.OPENSEA_API_KEY}} \
|
|
--set-env-vars NEXT_PUBLIC_IMGIX_TOKEN=${{secrets.IMGIX_TOKEN}} \
|
|
--set-env-vars NEXT_PUBLIC_YOUTUBE_API_KEY=${{secrets.YOUTUBE_API_KEY}} \
|
|
--set-env-vars NEXT_PUBLIC_GRAPHQL_URL=${{needs.env.outputs.GRAPHQL_URL}} \
|
|
--set-env-vars NEXT_PUBLIC_FRONTEND_URL=${{needs.env.outputs.FRONTEND_URL}}
|
|
|
|
seed-db:
|
|
name: Seed Database
|
|
runs-on: ubuntu-latest
|
|
needs: [env, deploy-hasura]
|
|
|
|
steps:
|
|
- name: "Checkout: ${{github.event.pull_request.head.label}}"
|
|
uses: actions/checkout@v2
|
|
with:
|
|
ref: ${{github.event.pull_request.head.sha}}
|
|
|
|
- name: Seed Database
|
|
continue-on-error: true
|
|
run: |
|
|
mv package.json package.json.temp
|
|
npm install --no-package-lock --no-save node-fetch bottleneck
|
|
mv package.json.temp package.json
|
|
SOURCE_GRAPHQL_URL="${{needs.env.outputs.GRAPHQL_URL}}" \
|
|
ACCOUNT_MIGRATION_URL="${{needs.env.outputs.SC_MIGRATE_URL}}" \
|
|
yarn hasura:seed-db
|
|
|
|
finish-deployment:
|
|
name: Finish Deployment
|
|
runs-on: ubuntu-latest
|
|
needs: [env, start-deployment, deploy-frontend]
|
|
if: always()
|
|
|
|
env:
|
|
result: ${{needs.deploy-frontend.result}}
|
|
|
|
steps:
|
|
- name: Finish Deployment
|
|
uses: bobheadxi/deployments@v1
|
|
with:
|
|
step: finish
|
|
token: ${{github.token}}
|
|
env: ${{env.DEPLOYMENT_ENV}}
|
|
env_url: ${{needs.env.outputs.FRONTEND_URL}}
|
|
status: ${{env.result == 'skipped' && 'cancelled' || env.result}}
|
|
deployment_id: ${{needs.start-deployment.outputs.deployment_id}}
|