Merge pull request #27 from codeuniversity/data-start-date #33
This file contains hidden or 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: Auto Deploy to Google Cloud | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_SA_KEY }} | |
| BACKEND_IMAGE_NAME: europe-west3-docker.pkg.dev/thf-climate-cloud/thf-climate/thf-climate | |
| FRONTEND_IMAGE_NAME: europe-west3-docker.pkg.dev/thf-climate-cloud/thf-climate-frontend/thf-climate-frontend | |
| steps: | |
| # Step 1: Checkout the code | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| # Step 2: Decode and Write the Service Account Key to a file properly | |
| - name: Set up Google Cloud credentials | |
| run: | | |
| echo "${{ secrets.GCP_SA_KEY_BASE64 }}" | base64 --decode > ${HOME}/gcloud-service-key.json | |
| # Step 3: Set up Google Cloud SDK | |
| - name: Set up Google Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v1 | |
| with: | |
| project_id: ${{ secrets.GCP_PROJECT_ID }} | |
| service_account_key: ${{ secrets.GCP_SA_KEY }} | |
| export_default_credentials: true | |
| # Step 4: Activate Service Account Explicitly | |
| - name: Activate Service Account | |
| run: | | |
| gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json | |
| gcloud config set account $(gcloud config get-value core/account) | |
| # Step 5: Configure Docker for Google Artifact Registry | |
| - name: Configure Docker for Google Artifact Registry | |
| run: | | |
| gcloud auth configure-docker europe-west3-docker.pkg.dev | |
| # Step 6: Build and Deploy the backend | |
| - name: Build Docker image (backend) | |
| working-directory: ./backend | |
| run: | | |
| docker buildx build --platform linux/amd64 -t $BACKEND_IMAGE_NAME:latest . | |
| - name: Push Docker image to Artifact Registry (backend) | |
| working-directory: ./backend | |
| run: | | |
| docker push $BACKEND_IMAGE_NAME:latest | |
| - name: Deploy to Cloud Run (backend) | |
| working-directory: ./backend | |
| run: | | |
| gcloud run deploy thf-climate-run \ | |
| --image=$BACKEND_IMAGE_NAME:latest \ | |
| --port=8000 \ | |
| --region=europe-west3 \ | |
| --allow-unauthenticated \ | |
| --platform=managed \ | |
| --min-instances=1 \ | |
| --max-instances=5 | |
| # Step 7: Build and Deploy the frontend | |
| - name: Build Docker image (frontend) | |
| working-directory: ./frontend | |
| run: | | |
| docker buildx build --platform linux/amd64 -t $FRONTEND_IMAGE_NAME:latest . | |
| - name: Push Docker image to Artifact Registry (frontend) | |
| working-directory: ./frontend | |
| run: | | |
| docker push $FRONTEND_IMAGE_NAME:latest | |
| - name: Deploy to Cloud Run (frontend) | |
| working-directory: ./frontend | |
| run: | | |
| gcloud run deploy thf-climate-frontend-run \ | |
| --image=$FRONTEND_IMAGE_NAME:latest \ | |
| --port=80 \ | |
| --region=europe-west3 \ | |
| --allow-unauthenticated \ | |
| --platform=managed \ | |
| --min-instances=1 \ | |
| --max-instances=5 |