Skip to content

Commit da2a8d9

Browse files
committed
Refactor Github workflows to use new devbox setup
This gets the CI environment very close to matching the dev environment.
1 parent f4393f5 commit da2a8d9

File tree

5 files changed

+122
-158
lines changed

5 files changed

+122
-158
lines changed
Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
1-
# This workflow build and push a Docker container to Google Artifact Registry
2-
# and deploy it on Cloud Run when a commit is pushed to the "main"
3-
# branch.
4-
#
5-
# To configure this workflow:
6-
#
7-
# 1. Enable the following Google Cloud APIs:
8-
#
9-
# - Artifact Registry (artifactregistry.googleapis.com)
10-
# - Cloud Run (run.googleapis.com)
11-
# - IAM Credentials API (iamcredentials.googleapis.com)
12-
#
13-
# You can learn more about enabling APIs at
14-
# https://support.google.com/googleapi/answer/6158841.
15-
#
16-
# 2. Create and configure a Workload Identity Provider for GitHub:
17-
# https://github.com/google-github-actions/auth#preferred-direct-workload-identity-federation.
18-
#
19-
# Depending on how you authenticate, you will need to grant an IAM principal
20-
# permissions on Google Cloud:
21-
#
22-
# - Artifact Registry Administrator (roles/artifactregistry.admin)
23-
# - Cloud Run Developer (roles/run.developer)
24-
#
25-
# You can learn more about setting IAM permissions at
26-
# https://cloud.google.com/iam/docs/manage-access-other-resources
27-
#
28-
# 3. Change the values in the "env" block to match your values.
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.
293

30-
name: 'Build and Deploy to Cloud Run'
4+
name: 'Build and Deploy Builder API to Cloud Run'
315

326
on:
337
push:
348
branches:
359
- main
3610
paths:
3711
- 'builder-api/**'
12+
- 'devbox.json'
13+
- 'devbox.lock'
3814

3915
env:
4016
PROJECT_ID: 'benefit-decision-toolkit-play'
@@ -53,43 +29,39 @@ jobs:
5329

5430
steps:
5531
- name: 'Checkout'
56-
uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions/checkout@v4
57-
58-
59-
# Configure Workload Identity Federation and generate an access token.
60-
#
61-
# See https://github.com/google-github-actions/auth for more options,
62-
# including authenticating via a JSON credentials file.
32+
uses: 'actions/checkout@v4'
33+
34+
# Devbox needs a .env file to exist, even if it's empty
35+
# TODO: Make this useful in this and other workflows by just consolidating env vars
36+
# here (so that we don't need to manage multiple places)
37+
- name: 'Create .env file'
38+
run: touch .env
39+
40+
# Setup devbox which includes all our dependencies: Maven, JDK 21, Quarkus, etc.
41+
- name: 'Install devbox'
42+
uses: 'jetify-com/[email protected]'
43+
with:
44+
enable-cache: true
45+
46+
# Configure Workload Identity Federation and generate an access token
6347
- id: 'auth'
6448
name: 'Authenticate to Google Cloud'
6549
uses: 'google-github-actions/auth@v2'
6650
with:
6751
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
6852
service_account: cicd-build-deploy-api@benefit-decision-toolkit-play.iam.gserviceaccount.com
6953
project_id: ${{ env.PROJECT_ID }}
70-
71-
- name: 'Set up Cloud SDK'
72-
uses: 'google-github-actions/setup-gcloud@v2'
73-
74-
# BEGIN - Docker auth and build
7554

76-
# Configure Docker to use gcloud as a credential helper
55+
# Configure Docker to use gcloud as a credential helper (using devbox gcloud)
7756
- name: 'Configure Docker'
7857
run: |
79-
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
80-
81-
# Download Java version
82-
- name: Set up Java 21
83-
uses: actions/setup-java@v3
84-
with:
85-
distribution: temurin
86-
java-version: 21
58+
devbox run -- gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
8759
88-
# Build the Quarkus app with Maven
60+
# Build the Quarkus app with Maven using devbox environment
8961
- name: 'Build Quarkus App'
9062
working-directory: builder-api
9163
run: |
92-
./mvnw package -DskipTests
64+
devbox run build-builder-api-ci
9365
9466
- name: 'Build and Push Container'
9567
working-directory: builder-api
@@ -99,21 +71,18 @@ jobs:
9971
docker push "${DOCKER_TAG}"
10072
10173
- name: 'Deploy to Cloud Run'
102-
103-
# END - Docker auth and build
104-
105-
uses: 'google-github-actions/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17' # google-github-actions/deploy-cloudrun@v2
74+
uses: 'google-github-actions/deploy-cloudrun@v2'
10675
with:
10776
service: '${{ env.API_NAME }}'
10877
region: '${{ env.REGION }}'
109-
# NOTE: If using a pre-built image, update the image name below:
110-
11178
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.API_NAME }}:latest'
11279
service_account: 'builder-api-service-account@${{ env.PROJECT_ID }}.iam.gserviceaccount.com'
11380
flags: '--allow-unauthenticated --max-instances=2'
81+
env_vars: |
82+
QUARKUS_GOOGLE_CLOUD_PROJECT_ID=${{ env.PROJECT_ID }}
83+
GCS_BUCKET_NAME=${{ env.PROJECT_ID }}.firebasestorage.app
11484
11585
# If required, use the Cloud Run URL output in later steps
11686
- name: 'Show output'
117-
run: |2-
118-
119-
echo ${{ steps.deploy.outputs.url }}
87+
run: |
88+
echo ${{ steps.deploy.outputs.url }}
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
name: Build and Deploy to Firebase Hosting
1+
# This workflow uses devbox for dependency management and builds/deploys the builder frontend
2+
# to Firebase Hosting when a commit is pushed to the "main" branch.
3+
4+
name: 'Build and Deploy Builder Frontend to Firebase Hosting'
25

36
on:
47
push:
58
branches:
69
- main
710
paths:
811
- 'builder-frontend/**'
12+
- 'devbox.json'
13+
- 'devbox.lock'
914

1015
env:
1116
PROJECT_ID: 'benefit-decision-toolkit-play'
@@ -24,10 +29,17 @@ jobs:
2429
- name: Checkout repository
2530
uses: actions/checkout@v4
2631

27-
# Configure Workload Identity Federation and generate an access token.
28-
#
29-
# See https://github.com/google-github-actions/auth for more options,
30-
# including authenticating via a JSON credentials file.
32+
# Devbox needs a .env file to exist, even if it's empty
33+
- name: 'Create .env file'
34+
run: touch .env
35+
36+
# Setup devbox which includes Node.js, Firebase CLI, and Google Cloud SDK
37+
- name: 'Install devbox'
38+
uses: 'jetify-com/[email protected]'
39+
with:
40+
enable-cache: true
41+
42+
# Configure Workload Identity Federation and generate an access token
3143
- id: 'auth'
3244
name: 'Authenticate to Google Cloud'
3345
uses: 'google-github-actions/auth@v2'
@@ -36,28 +48,21 @@ jobs:
3648
service_account: cicd-build-deploy-api@benefit-decision-toolkit-play.iam.gserviceaccount.com
3749
project_id: ${{ env.PROJECT_ID }}
3850

39-
- name: Setup Node.js
40-
uses: actions/setup-node@v4
41-
with:
42-
node-version: '18'
43-
4451
- name: Cache node modules
45-
uses: actions/cache@v3
52+
uses: actions/cache@v4
4653
with:
4754
path: builder-frontend/node_modules
4855
key: ${{ runner.os }}-node-${{ hashFiles('builder-frontend/package-lock.json') }}
4956
restore-keys: |
5057
${{ runner.os }}-node-
51-
cache: 'npm'
52-
cache-dependency-path: 'builder-frontend/package-lock.json'
5358
5459
- name: Install dependencies
5560
working-directory: builder-frontend
56-
run: npm ci
61+
run: devbox run install-builder-frontend-ci
5762

5863
- name: Build application
5964
working-directory: builder-frontend
60-
run: npm run build
65+
run: devbox run build-builder-frontend-ci
6166
env:
6267
VITE_API_URL: ${{ secrets.VITE_API_URL}}
6368
VITE_SCREENER_BASE_URL: ${{ secrets.VITE_SCREENER_BASE_URL}}
@@ -69,8 +74,5 @@ jobs:
6974
VITE_APP_ID: ${{ secrets.VITE_APP_ID}}
7075
VITE_MEASUREMENT_ID: ${{ secrets.VITE_MEASUREMENT_ID}}
7176

72-
- name: Install Firebase CLI
73-
run: npm install -g firebase-tools
74-
7577
- name: Deploy to Firebase Hosting
76-
run: firebase deploy --only hosting:builder-frontend
78+
run: devbox run -- firebase deploy --only hosting:builder-frontend
Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
1-
# This workflow build and push a Docker container to Google Artifact Registry
2-
# and deploy it on Cloud Run when a commit is pushed to the "main"
3-
# branch.
4-
#
5-
# To configure this workflow:
6-
#
7-
# 1. Enable the following Google Cloud APIs:
8-
#
9-
# - Artifact Registry (artifactregistry.googleapis.com)
10-
# - Cloud Run (run.googleapis.com)
11-
# - IAM Credentials API (iamcredentials.googleapis.com)
12-
#
13-
# You can learn more about enabling APIs at
14-
# https://support.google.com/googleapi/answer/6158841.
15-
#
16-
# 2. Create and configure a Workload Identity Provider for GitHub:
17-
# https://github.com/google-github-actions/auth#preferred-direct-workload-identity-federation.
18-
#
19-
# Depending on how you authenticate, you will need to grant an IAM principal
20-
# permissions on Google Cloud:
21-
#
22-
# - Artifact Registry Administrator (roles/artifactregistry.admin)
23-
# - Cloud Run Developer (roles/run.developer)
24-
#
25-
# You can learn more about setting IAM permissions at
26-
# https://cloud.google.com/iam/docs/manage-access-other-resources
27-
#
28-
# 3. Change the values in the "env" block to match your values.
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.
293

30-
name: 'Build and Deploy to Cloud Run'
4+
name: 'Build and Deploy Screener API to Cloud Run'
315

326
on:
337
push:
348
branches:
359
- main
3610
paths:
3711
- 'screener-api/**'
12+
- 'devbox.json'
13+
- 'devbox.lock'
3814

3915
env:
4016
PROJECT_ID: 'benefit-decision-toolkit-play'
@@ -53,13 +29,19 @@ jobs:
5329

5430
steps:
5531
- name: 'Checkout'
56-
uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions/checkout@v4
32+
uses: 'actions/checkout@v4'
5733

34+
# Devbox needs a .env file to exist, even if it's empty
35+
- name: 'Create .env file'
36+
run: touch .env
5837

59-
# Configure Workload Identity Federation and generate an access token.
60-
#
61-
# See https://github.com/google-github-actions/auth for more options,
62-
# including authenticating via a JSON credentials file.
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
6345
- id: 'auth'
6446
name: 'Authenticate to Google Cloud'
6547
uses: 'google-github-actions/auth@v2'
@@ -68,28 +50,16 @@ jobs:
6850
service_account: cicd-build-deploy-api@benefit-decision-toolkit-play.iam.gserviceaccount.com
6951
project_id: ${{ env.PROJECT_ID }}
7052

71-
- name: 'Set up Cloud SDK'
72-
uses: 'google-github-actions/setup-gcloud@v2'
73-
74-
# BEGIN - Docker auth and build
75-
76-
# Configure Docker to use gcloud as a credential helper
53+
# Configure Docker to use gcloud as a credential helper (using devbox gcloud)
7754
- name: 'Configure Docker'
7855
run: |
79-
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
80-
81-
# Download Java version
82-
- name: Set up Java 21
83-
uses: actions/setup-java@v3
84-
with:
85-
distribution: temurin
86-
java-version: 21
56+
devbox run -- gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
8757
88-
# Build the Quarkus app with Maven
58+
# Build the Quarkus app with Maven using devbox environment
8959
- name: 'Build Quarkus App'
9060
working-directory: screener-api
9161
run: |
92-
./mvnw package -DskipTests
62+
devbox run build-screener-api-ci
9363
9464
- name: 'Build and Push Container'
9565
working-directory: screener-api
@@ -99,21 +69,18 @@ jobs:
9969
docker push "${DOCKER_TAG}"
10070
10171
- name: 'Deploy to Cloud Run'
102-
103-
# END - Docker auth and build
104-
105-
uses: 'google-github-actions/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17' # google-github-actions/deploy-cloudrun@v2
72+
uses: 'google-github-actions/deploy-cloudrun@v2'
10673
with:
10774
service: '${{ env.API_NAME }}'
10875
region: '${{ env.REGION }}'
109-
# NOTE: If using a pre-built image, update the image name below:
110-
11176
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.API_NAME }}:latest'
11277
service_account: 'screener-api-service-account@${{ env.PROJECT_ID }}.iam.gserviceaccount.com'
11378
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
11482
11583
# If required, use the Cloud Run URL output in later steps
11684
- name: 'Show output'
117-
run: |2-
118-
119-
echo ${{ steps.deploy.outputs.url }}
85+
run: |
86+
echo ${{ steps.deploy.outputs.url }}

0 commit comments

Comments
 (0)