1+ # This workflow uses devbox for dependency management and builds/deploys the screener API
2+ # to Cloud Run when a commit is pushed to the "main" branch.
3+
4+ name : ' Build and Deploy Screener API to Cloud Run'
5+
6+ on :
7+ push :
8+ branches :
9+ - 157-offline-dev
10+ paths :
11+ - ' screener-api/**'
12+ - ' devbox.json'
13+ - ' devbox.lock'
14+
15+ env :
16+ PROJECT_ID : ' benefit-decision-toolkit-play'
17+ REGION : ' us-central1'
18+ SERVICE : ' benefit-decision-toolkit-play'
19+ API_NAME : ' screener-api'
20+ WORKLOAD_IDENTITY_PROVIDER : ' projects/1034049717668/locations/global/workloadIdentityPools/github-actions-google-cloud/providers/github'
21+
22+ jobs :
23+ deploy :
24+ runs-on : ' ubuntu-latest'
25+
26+ permissions :
27+ contents : ' read'
28+ id-token : ' write'
29+
30+ steps :
31+ - name : ' Checkout'
32+ uses : ' actions/checkout@v4'
33+
34+ # Devbox needs a .env file to exist, even if it's empty
35+ - name : ' Create .env file'
36+ run : touch .env
37+
38+ # Setup devbox which includes all our dependencies: Maven, JDK 21, Quarkus, etc.
39+ - name : ' Install devbox'
40+ uses :
' jetify-com/[email protected] ' 41+ with :
42+ enable-cache : true
43+
44+ # Configure Workload Identity Federation and generate an access token
45+ - id : ' auth'
46+ name : ' Authenticate to Google Cloud'
47+ uses : ' google-github-actions/auth@v2'
48+ with :
49+ workload_identity_provider : ' ${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
50+ service_account : cicd-build-deploy-api@benefit-decision-toolkit-play.iam.gserviceaccount.com
51+ project_id : ${{ env.PROJECT_ID }}
52+
53+ # Configure Docker to use gcloud as a credential helper (using devbox gcloud)
54+ - name : ' Configure Docker'
55+ run : |
56+ devbox run -- gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
57+
58+ # Build the Quarkus app with Maven using devbox environment
59+ - name : ' Build Quarkus App'
60+ working-directory : screener-api
61+ run : |
62+ devbox run build-screener-api-ci
63+
64+ - name : ' Build and Push Container'
65+ working-directory : screener-api
66+ run : |-
67+ DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.API_NAME }}:latest"
68+ docker build -f src/main/docker/Dockerfile.jvm --tag "${DOCKER_TAG}" .
69+ docker push "${DOCKER_TAG}"
70+
71+ - name : ' Deploy to Cloud Run'
72+ uses : ' google-github-actions/deploy-cloudrun@v2'
73+ with :
74+ service : ' ${{ env.API_NAME }}'
75+ region : ' ${{ env.REGION }}'
76+ image : ' ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.API_NAME }}:latest'
77+ service_account : ' screener-api-service-account@${{ env.PROJECT_ID }}.iam.gserviceaccount.com'
78+ flags : ' --allow-unauthenticated --max-instances=2'
79+ env_vars : |
80+ QUARKUS_GOOGLE_CLOUD_PROJECT_ID=${{ env.PROJECT_ID }}
81+ GCS_BUCKET_NAME=${{ env.PROJECT_ID }}.firebasestorage.app
82+
83+ # If required, use the Cloud Run URL output in later steps
84+ - name : ' Show output'
85+ run : |
86+ echo ${{ steps.deploy.outputs.url }}
0 commit comments