fix double header problem #204
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy to Cloud Run | |
on: | |
push: | |
branches: [ "main" ] | |
env: | |
FRONTEND_IMAGE: aphorist-frontend | |
BACKEND_IMAGE: aphorist-backend | |
REGION: us-central1 | |
USE_GKE_GCLOUD_AUTH_PLUGIN: True | |
PROJECT_ID: ${{ secrets.PROJECT_ID }} | |
BACKEND_URL: "https://backend-132704325993.us-central1.run.app" | |
FRONTEND_URL: "https://frontend-132704325993.us-central1.run.app" | |
jobs: | |
setup-build-publish-deploy: | |
name: Setup, Build, Publish, and Deploy | |
runs-on: ubuntu-latest | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- id: 'auth' | |
name: 'Authenticate to Google Cloud' | |
uses: 'google-github-actions/auth@v1' | |
with: | |
credentials_json: '${{ secrets.SERVICE_ACCOUNT_KEY }}' | |
- name: Set up Cloud SDK | |
uses: 'google-github-actions/setup-gcloud@v1' | |
with: | |
project_id: ${{ secrets.PROJECT_ID }} | |
- name: Configure Docker | |
run: | | |
gcloud auth configure-docker | |
- name: Build Frontend Docker image | |
run: | | |
docker build -t gcr.io/${{ secrets.PROJECT_ID }}/$FRONTEND_IMAGE:$GITHUB_SHA -f frontend/Dockerfile.prod ./frontend | |
- name: Build Backend Docker image | |
run: | | |
docker build -t gcr.io/${{ secrets.PROJECT_ID }}/$BACKEND_IMAGE:$GITHUB_SHA -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/${{ secrets.PROJECT_ID }}/$FRONTEND_IMAGE:$GITHUB_SHA | |
docker push gcr.io/${{ secrets.PROJECT_ID }}/$BACKEND_IMAGE:$GITHUB_SHA | |
- name: Deploy Backend to Cloud Run | |
run: | | |
# Create env vars file with all necessary origins | |
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 | |
echo "Environment configuration:" | |
cat env.yaml | |
gcloud run deploy backend \ | |
--image gcr.io/${{ secrets.PROJECT_ID }}/$BACKEND_IMAGE:$GITHUB_SHA \ | |
--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: Seed Default Stories | |
run: | | |
curl -X POST "$BACKEND_URL/api/seed-default-stories" \ | |
-H "Content-Type: application/json" | |
- name: Deploy Frontend to Cloud Run | |
run: | | |
# Build the frontend image with the backend URL | |
docker build \ | |
--build-arg REACT_APP_API_URL=$BACKEND_URL \ | |
-t gcr.io/${{ secrets.PROJECT_ID }}/$FRONTEND_IMAGE:$GITHUB_SHA \ | |
-f frontend/Dockerfile.prod ./frontend | |
# Push the new image | |
docker push gcr.io/${{ secrets.PROJECT_ID }}/$FRONTEND_IMAGE:$GITHUB_SHA | |
# Deploy to Cloud Run | |
gcloud run deploy frontend \ | |
--image gcr.io/${{ secrets.PROJECT_ID }}/$FRONTEND_IMAGE:$GITHUB_SHA \ | |
--platform managed \ | |
--region $REGION \ | |
--port 8080 \ | |
--timeout 300s \ | |
--cpu=1 \ | |
--memory=512Mi \ | |
--min-instances=1 \ | |
--allow-unauthenticated | |
- name: Verify Deployment | |
run: | | |
echo "Frontend URL: $(gcloud run services describe frontend --platform managed --region $REGION --format 'value(status.url)')" | |
echo "Backend URL: $(gcloud run services describe backend --platform managed --region $REGION --format 'value(status.url)')" | |
# Test backend health | |
curl -i "$BACKEND_URL/health" | |
- name: Setup Firebase CLI | |
run: npm install -g firebase-tools | |
- name: Deploy Firebase Hosting | |
run: firebase deploy --only hosting --project ${{ secrets.PROJECT_ID }} | |
env: | |
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} |