Skip to content

Add preview channel

Add preview channel #4

# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools
name: Deploy to Firebase Hosting on PR
on: pull_request
env:
FRONTEND_IMAGE: aphorist-frontend-preview
BACKEND_IMAGE: aphorist-backend-preview
REGION: us-central1
USE_GKE_GCLOUD_AUTH_PLUGIN: True
PROJECT_ID: aphorist
BACKEND_URL: "https://backend-preview-${{ github.event.pull_request.number }}-132704325993.us-central1.run.app"
FRONTEND_URL: "https://frontend-preview-${{ github.event.pull_request.number }}-132704325993.us-central1.run.app"
permissions:
checks: write
contents: read
pull-requests: write
id-token: write
jobs:
build_and_preview:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_APHORIST }}'
- name: Set up Cloud SDK
uses: 'google-github-actions/setup-gcloud@v1'
with:
project_id: '${{ env.PROJECT_ID }}'
- name: Configure Docker
run: |
gcloud auth configure-docker
- name: Build Frontend Docker image
run: |
docker build -t gcr.io/${{ env.PROJECT_ID }}/$FRONTEND_IMAGE:${{ github.event.pull_request.number }} -f frontend/Dockerfile.prod ./frontend
- name: Build Backend Docker image
run: |
docker build -t gcr.io/${{ env.PROJECT_ID }}/$BACKEND_IMAGE:${{ github.event.pull_request.number }} -f backend/Dockerfile.prod ./backend --build-arg BACKEND_URL=$BACKEND_URL --build-arg FRONTEND_URL=$FRONTEND_URL
- name: Push Docker images
run: |
docker push gcr.io/${{ env.PROJECT_ID }}/$FRONTEND_IMAGE:${{ github.event.pull_request.number }}
docker push gcr.io/${{ env.PROJECT_ID }}/$BACKEND_IMAGE:${{ github.event.pull_request.number }}
- name: Deploy Backend Preview
run: |
cat > env.yaml << EOF
DB_TYPE: firebase
NODE_ENV: production
CORS_ORIGIN: "$FRONTEND_URL,https://aphorist.firebaseapp.com,https://aphorist.web.app,https://aphori.st,https://www.aphori.st,$BACKEND_URL"
EOF
gcloud run deploy backend-preview-${{ github.event.pull_request.number }} \
--image gcr.io/${{ env.PROJECT_ID }}/$BACKEND_IMAGE:${{ github.event.pull_request.number }} \
--platform managed \
--region $REGION \
--port 5000 \
--env-vars-file env.yaml \
--set-secrets "FIREBASE_CREDENTIAL=firebase-admin-key:latest,\
FIREBASE_DATABASE_URL=firebase-database-url:latest,\
EMAIL_HOST=EMAIL_HOST:latest,\
EMAIL_PORT=EMAIL_PORT:latest,\
EMAIL_USERNAME=EMAIL_USERNAME:latest,\
EMAIL_PASSWORD=EMAIL_PASSWORD:latest,\
MAGIC_LINK_SECRET=JWT_SECRET:latest,\
AUTH_TOKEN_SECRET=JWT_SECRET:latest" \
--allow-unauthenticated
- name: Deploy Frontend Preview
run: |
docker build \
--build-arg REACT_APP_API_URL=$BACKEND_URL \
-t gcr.io/${{ env.PROJECT_ID }}/$FRONTEND_IMAGE:${{ github.event.pull_request.number }} \
-f frontend/Dockerfile.prod ./frontend
docker push gcr.io/${{ env.PROJECT_ID }}/$FRONTEND_IMAGE:${{ github.event.pull_request.number }}
gcloud run deploy frontend-preview-${{ github.event.pull_request.number }} \
--image gcr.io/${{ env.PROJECT_ID }}/$FRONTEND_IMAGE:${{ github.event.pull_request.number }} \
--platform managed \
--region $REGION \
--port 8080 \
--timeout 300s \
--cpu=1 \
--memory=512Mi \
--min-instances=1 \
--allow-unauthenticated
- name: Install Frontend Dependencies
run: |
cd frontend
yarn install --frozen-lockfile
- name: Build Frontend
run: |
cd frontend
yarn build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_APHORIST }}
projectId: aphorist