|
| 1 | +name: Deploy Notifications Job to Cloud RUN |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "migrate-noti-job-to-gcp" ] |
| 6 | + paths: |
| 7 | + - '**/*' |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + environment: |
| 11 | + description: 'Select the environment to deploy to' |
| 12 | + required: true |
| 13 | + default: 'development' |
| 14 | + branch: |
| 15 | + description: 'Branch to deploy from' |
| 16 | + required: true |
| 17 | + default: 'main' |
| 18 | + |
| 19 | +env: |
| 20 | + SERVICE: notifications-job |
| 21 | + REGION: us-central1 |
| 22 | + |
| 23 | +jobs: |
| 24 | + deploy: |
| 25 | + environment: ${{ github.event.inputs.environment }} |
| 26 | + permissions: |
| 27 | + contents: 'read' |
| 28 | + id-token: 'write' |
| 29 | + |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Validate Environment Input |
| 33 | + run: | |
| 34 | + if [[ "${{ github.event.inputs.environment }}" != "development" && "${{ github.event.inputs.environment }}" != "prod" ]]; then |
| 35 | + echo "Invalid environment: ${{ github.event.inputs.environment }}. Must be 'development' or 'prod'." |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | +
|
| 39 | + # To workaround "no space left on device" issue of GitHub-hosted runner |
| 40 | + - name: Delete huge unnecessary tools folder |
| 41 | + run: rm -rf /opt/hostedtoolcache |
| 42 | + |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Google Auth |
| 47 | + id: auth |
| 48 | + uses: 'google-github-actions/auth@v2' |
| 49 | + with: |
| 50 | + credentials_json: ${{ secrets.GCP_CREDENTIALS }} |
| 51 | + |
| 52 | + - name: Login to GCR |
| 53 | + run: gcloud auth configure-docker |
| 54 | + |
| 55 | + - name: Set up Docker Buildx |
| 56 | + uses: docker/setup-buildx-action@v3 |
| 57 | + |
| 58 | + - name: Google Service Account |
| 59 | + run: echo "${{ secrets.GCP_SERVICE_ACCOUNT }}" | base64 -d > ./backend/google-credentials.json |
| 60 | + |
| 61 | + - name: Build and Push Docker image |
| 62 | + uses: docker/build-push-action@v6 |
| 63 | + with: |
| 64 | + context: . |
| 65 | + file: ./backend/modal/Dockerfile.notifications_job |
| 66 | + push: true |
| 67 | + tags: gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:latest |
| 68 | + cache-from: type=registry,ref=gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:buildcache |
| 69 | + cache-to: type=registry,ref=gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:buildcache,mode=max |
| 70 | + |
| 71 | + - name: Deploy to Cloud Run |
| 72 | + id: deploy |
| 73 | + uses: google-github-actions/deploy-cloudrun@v2 |
| 74 | + with: |
| 75 | + job: ${{ env.SERVICE }} |
| 76 | + region: ${{ env.REGION }} |
| 77 | + image: gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }} |
| 78 | + |
| 79 | + # If required, use the Cloud Run url output in later steps |
| 80 | + - name: Show Output |
| 81 | + run: echo ${{ steps.deploy.outputs.url }} |
0 commit comments