Skip to content

multiple ui fixes (#1729) #262

multiple ui fixes (#1729)

multiple ui fixes (#1729) #262

# This is used to deploy the frontend at metagame.wtf and test.metagame.wtf
# Eventually we will switch the associated backend deployments over to Google Cloud
# as well, at which time we can just use the single gcp_deploy.yaml file
# for both PR deployments AND our stage/prod environments
name: Update Frontend Deployment on Cloud Run
on:
workflow_dispatch:
inputs:
cache_key:
description: Optional cache key component to force invalidation of the build cache.
required: false
default: ""
push:
branches:
- develop
- master
env:
PROJECT_ID: metagame-thegame
REGISTRY_REGION: us-east4
REGISTRY_REPO: thegame
DEPLOYMENT_DOMAIN: a.run.app
CLOUDRUN_SUFFIX: mjhnbmqqna-uk
DEPLOYMENT_ENV: ${{github.ref_name}}
FRONTEND_SERVICE: frontend-${{github.ref_name}}
FRONTEND_PORT: 3000
FRONTEND_TARGET: production
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: "Frontend deployment for #${{github.ref_name}} by ${{github.event.pusher.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/[email protected]
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}}
FRONTEND_SERVICE: ${{env.FRONTEND_SERVICE}}
FRONTEND_PORT: ${{env.FRONTEND_PORT}}
CLOUDRUN_REGION: ${{env.CLOUDRUN_REGION}}
DOCKER_REGISTRY: ${{env.DOCKER_REGISTRY}}
FRONTEND_URL: ${{env.FRONTEND_URL}}
DOCKER_PATH: ${{env.DOCKER_PATH}}
GRAPHQL_URL: ${{env.GRAPHQL_URL}}
FRONTEND_TAG: ${{env.FRONTEND_TAG}}
APP_ENV: ${{env.APP_ENV}}
GOOGLE_CAL_PROJECT_NUMBER: ${{env.GOOGLE_CAL_PROJECT_NUMBER}}
GOOGLE_CAL_CLIENT_EMAIL: ${{env.GOOGLE_CAL_CLIENT_EMAIL}}
GOOGLE_CAL_CALENDAR_ID: ${{env.GOOGLE_CAL_CALENDAR_ID}}
steps:
- name: First Interpolation of Variables
id: first
run: |
echo "CLOUDRUN_REGION=${{env.REGISTRY_REGION}}" >> $GITHUB_ENV
echo "DOCKER_REGISTRY=${{env.REGISTRY_REGION}}-docker.pkg.dev" >> $GITHUB_ENV
if [[ ${{github.ref_name}} == 'master' ]]; then
echo "APP_ENV=production" >> $GITHUB_ENV
echo "HASURA_HOST=api.metagame.wtf" >> $GITHUB_ENV
echo "FRONTEND_URL=https://metagame.wtf" >> $GITHUB_ENV
else
echo "APP_ENV=test" >> $GITHUB_ENV
echo "HASURA_HOST=api-staging.metagame.wtf" >> $GITHUB_ENV
echo "FRONTEND_URL=https://test.metagame.wtf" >> $GITHUB_ENV
fi
- name: Those Variables May Now Be Interpolated
id: second
run: |
echo "DOCKER_PATH=\
${{env.DOCKER_REGISTRY}}/${{env.PROJECT_ID}}/${{env.REGISTRY_REPO}}" >> $GITHUB_ENV
echo "GRAPHQL_URL=\
https://${{env.HASURA_HOST}}/v1/graphql" >> $GITHUB_ENV
- name: And That Result Again In Another Step
id: third
run: |
echo "FRONTEND_TAG=\
${{env.DOCKER_PATH}}/frontend:${{github.ref_name}}" >> $GITHUB_ENV
build-frontend:
name: Build Frontend Container Image
runs-on: ubuntu-latest
needs: [env]
steps:
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: "Login to Registry: ${{needs.env.outputs.DOCKER_REGISTRY}}"
uses: docker/login-action@v3
with:
registry: ${{needs.env.outputs.DOCKER_REGISTRY}}
username: _json_key
password: ${{secrets.GCP_SA_KEY}}
- name: "Build & Push Container Image: ${{needs.env.outputs.FRONTEND_TAG}}"
uses: docker/build-push-action@v5
with:
file: docker/frontend/Dockerfile
tags: ${{needs.env.outputs.FRONTEND_TAG}}
build-args: |
TARGET=${{env.FRONTEND_TARGET}}
APP_ENV=${{env.APP_ENV}}
GRAPHQL_URL=${{needs.env.outputs.GRAPHQL_URL}}
FRONTEND_URL=${{needs.env.outputs.FRONTEND_URL}}
YOUTUBE_API_KEY=${{secrets.YOUTUBE_API_KEY}}
IMGIX_TOKEN=${{secrets.IMGIX_TOKEN}}
HONEYBADGER_API_KEY=${{secrets.HONEYBADGER_API_KEY}}
GOOGLE_ANALYTICS_ID=${{secrets.GOOGLE_ANALYTICS_ID}}
USERBACK_TOKEN=${{secrets.USERBACK_TOKEN}}
WEB3_STORAGE_TOKEN=${{secrets.WEB3_STORAGE_TOKEN}}
OPENSEA_API_KEY=${{secrets.OPENSEA_API_KEY}}
GCAL_PRIVATE_KEY=${{secrets.GCAL_PRIVATE_KEY}}
GCAL_CLIENT_EMAIL=${{secrets.GCAL_CLIENT_EMAIL}}
GCAL_PROJECT_NUMBER=${{secrets.GCAL_PROJECT_NUMBER}}
GCAL_CALENDAR_ID=${{secrets.GCAL_CALENDAR_ID}}
WEB3_STORAGE_DID=${{secrets.WEB3_STORAGE_DID}}
WEB3_STORAGE_PROOF=${{secrets.WEB3_STORAGE_PROOF}}
WEB3_STORAGE_KEY=${{secrets.WEB3_STORAGE_KEY}}
push: true
deploy-frontend:
name: Deploy Frontend
runs-on: ubuntu-latest
needs: [env, build-frontend]
steps:
- name: Set Up gcloud CLI
uses: google-github-actions/[email protected]
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 1Gi \
--ingress all \
--min-instances 1 \
--allow-unauthenticated \
--set-env-vars GCAL_PRIVATE_KEY="${{secrets.GCAL_PRIVATE_KEY}}" \
--set-env-vars GCAL_PROJECT_NUMBER="${{secrets.GCAL_PROJECT_NUMBER}}" \
--set-env-vars GCAL_CLIENT_EMAIL="${{secrets.GCAL_CLIENT_EMAIL}}" \
--set-env-vars OPENSEA_API_KEY="${{secrets.OPENSEA_API_KEY}}" \
--set-env-vars NEXT_PUBLIC_GCAL_CALENDAR_ID="${{secrets.GCAL_CALENDAR_ID}}" \
--set-env-vars NEXT_PUBLIC_GOOGLE_ANALYTICS_ID="${{secrets.GOOGLE_ANALYTICS_ID}}" \
--set-env-vars NEXT_PUBLIC_YOUTUBE_API_KEY="${{secrets.YOUTUBE_API_KEY}}" \
--set-env-vars NEXT_PUBLIC_WEB3_STORAGE_DID="${{secrets.WEB3_STORAGE_DID}}" \
--set-env-vars NEXT_PUBLIC_WEB3_STORAGE_PROOF="${{secrets.WEB3_STORAGE_PROOF}}" \
--set-env-vars NEXT_PUBLIC_WEB3_STORAGE_KEY="${{secrets.WEB3_STORAGE_KEY}}" \
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}}