Skip to content

Commit 0899cee

Browse files
committed
actions: test gcloud CLI via devbox
1 parent 4baed25 commit 0899cee

File tree

2 files changed

+118
-6
lines changed

2 files changed

+118
-6
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# This workflow uses devbox for dependency management and builds/deploys the builder API
2+
# to Cloud Run when a commit is pushed to the "main" branch.
3+
4+
name: 'Build and Deploy Builder API to Cloud Run'
5+
6+
on:
7+
push:
8+
branches:
9+
# - 157-offline-dev
10+
- main
11+
paths:
12+
- 'builder-api/**'
13+
- 'devbox.json'
14+
- 'devbox.lock'
15+
16+
env:
17+
PROJECT_ID: 'benefit-decision-toolkit-play'
18+
REGION: 'us-central1'
19+
SERVICE: 'benefit-decision-toolkit-play'
20+
API_NAME: 'builder-api'
21+
WORKLOAD_IDENTITY_PROVIDER: 'projects/1034049717668/locations/global/workloadIdentityPools/github-actions-google-cloud/providers/github'
22+
23+
jobs:
24+
deploy:
25+
runs-on: 'ubuntu-latest'
26+
27+
permissions:
28+
contents: 'read'
29+
id-token: 'write'
30+
31+
steps:
32+
- name: 'Checkout'
33+
uses: 'actions/checkout@v4'
34+
35+
# Setup devbox which includes all our dependencies: Maven, JDK 21, Quarkus, etc.
36+
- name: 'Install devbox'
37+
uses: 'jetify-com/[email protected]'
38+
with:
39+
enable-cache: true
40+
41+
# Configure Workload Identity Federation and generate an access token
42+
- id: 'auth'
43+
name: 'Authenticate to Google Cloud'
44+
uses: 'google-github-actions/auth@v2'
45+
with:
46+
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
47+
service_account: cicd-build-deploy-api@benefit-decision-toolkit-play.iam.gserviceaccount.com
48+
project_id: ${{ env.PROJECT_ID }}
49+
50+
- name: 'Set up Cloud SDK'
51+
uses: 'google-github-actions/setup-gcloud@v2'
52+
53+
# Configure Docker to use gcloud as a credential helper
54+
- name: 'Configure Docker'
55+
run: |
56+
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: builder-api
61+
run: |
62+
devbox run -- ./mvnw package -DskipTests
63+
64+
- name: 'Build and Push Container'
65+
working-directory: builder-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: 'builder-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 }}.appspot.com
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 }}

.github/workflows/test-devbox.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,51 @@ on:
55
branches:
66
- 157-offline-dev
77

8+
env:
9+
PROJECT_ID: 'benefit-decision-toolkit-play'
10+
REGION: 'us-central1'
11+
SERVICE: 'benefit-decision-toolkit-play'
12+
API_NAME: 'builder-api'
13+
WORKLOAD_IDENTITY_PROVIDER: 'projects/1034049717668/locations/global/workloadIdentityPools/github-actions-google-cloud/providers/github'
14+
815
jobs:
916
test:
1017
runs-on: ubuntu-latest
1118
steps:
1219
- uses: actions/checkout@v3
1320

14-
- name: Copy .env file
15-
run: cp .env.example .env
21+
# - name: Create .env file
22+
# run: |-
23+
# echo "QUARKUS_GOOGLE_CLOUD_PROJECT_ID=${{ secrets.QUARKUS_GOOGLE_CLOUD_PROJECT_ID }}" >> .env
24+
# run: cp .env.example .env
25+
# instead of copying, we need to use gh secrets to create the .env file with the "real" values
26+
# e.g:
27+
# echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
28+
# echo "API_KEY=${{ secrets.API_KEY }}" >> .env
29+
# Add other variables as needed
1630

1731
- name: Install devbox
1832
uses: jetify-com/[email protected]
1933
with:
2034
enable-cache: true
2135

22-
- name: Check devbox env variables
23-
run: devbox run -- env
36+
# Configure Workload Identity Federation and generate an access token
37+
- id: 'auth'
38+
name: 'Authenticate to Google Cloud'
39+
uses: 'google-github-actions/auth@v2'
40+
with:
41+
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
42+
service_account: cicd-build-deploy-api@benefit-decision-toolkit-play.iam.gserviceaccount.com
43+
project_id: ${{ env.PROJECT_ID }}
44+
45+
- name: 'Use gcloud CLI via Devbox?'
46+
run: 'devbox run -- gcloud info'
47+
48+
# - name: Check devbox env variables
49+
# run: devbox run -- env
2450

25-
- name: Run a script called test
26-
run: devbox run setup
51+
# - name: Run a script called test
52+
# run: devbox run setup
2753

2854
- name: Run arbitrary commands
2955
run: devbox run -- echo "done!"

0 commit comments

Comments
 (0)