1- name : Reusable deploy to gcp workflow
1+ name : Reusable build workflow
22
33on :
44 workflow_call :
55 inputs :
66 environment :
77 required : true
88 type : string
9- description : ' The environment to deploy to (e.g., beta, prod)'
9+ description : ' The environment to build for (e.g., beta, prod)'
1010
1111env :
12- TF_BACKEND_bucket : ${{ vars.PROJECT_ID }}-state
13- # TF_VAR_whatever will be picked up as terraform variables.
14- TF_VAR_org_id : ${{ secrets.ORG_ID }}
15- TF_VAR_billing_account : ${{ secrets.BILLING_ACCOUNT }}
16- TF_VAR_github_repo_owner_id : ${{ github.repository_owner_id }}
17- TF_VAR_github_repo : ${{ github.repository }}
18- TF_VAR_project_id : ${{ vars.PROJECT_ID }}
19- TF_VAR_region : ${{ vars.REGION }}
20- TF_VAR_full_container_tag : ${{ github.sha }}
21- TF_VAR_simulation_container_tag : ${{ github.sha }}
22- TF_VAR_container_tag : ${{ github.sha }}
23- BUILD_TAG : ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
24- COMMIT_TAG : ${{ github.sha }}
12+ PROJECT_ID : ${{ vars.PROJECT_ID }}
13+ REGION : ${{ vars.REGION }}
14+ REPO : api-v2
15+
2516jobs :
26- # api build steps are separated so they can run in parallel.
2717 build_simulation_api_image :
28- # Any runner supporting Node 20 or newer
18+ name : Build simulation API image
2919 runs-on : ubuntu-latest
3020 environment : ${{ inputs.environment }}
31- name : Build simulation API image
3221
3322 permissions :
3423 contents : " read"
35- # Required to auth against gcp
3624 id-token : " write"
3725
3826 steps :
39- - name : checkout repo
27+ - name : Checkout repo
4028 uses : actions/checkout@v4
29+
4130 - uses : " google-github-actions/auth@v2"
4231 with :
4332 workload_identity_provider : " ${{ vars._GITHUB_IDENTITY_POOL_PROVIDER_NAME }}"
4433 service_account : " builder@${{ vars.PROJECT_ID }}.iam.gserviceaccount.com"
45- - name : " Set up Cloud SDK"
34+
35+ - name : Set up Cloud SDK
4636 uses : " google-github-actions/setup-gcloud@v2"
37+
38+ - name : Configure Docker for Artifact Registry
39+ run : gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
40+
41+ - name : Set up Docker Buildx
42+ uses : docker/setup-buildx-action@v3
43+
44+ - name : Build and push simulation API
45+ uses : docker/build-push-action@v5
4746 with :
48- version : " >= 363.0.0"
49- - name : Build application
50- run : make -f Makefile.deploy publish-simulation-api-docker TAG=${{ github.sha }} PROJECT_ID=${{ vars.PROJECT_ID }} LOG_DIR=gs://${{ vars.PROJECT_ID }}-buildlogs
47+ context : .
48+ file : projects/policyengine-api-simulation/Dockerfile
49+ push : true
50+ tags : |
51+ ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO }}/policyengine-api-simulation:${{ github.sha }}
52+ ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO }}/policyengine-api-simulation:latest
53+ cache-from : type=gha
54+ cache-to : type=gha,mode=max
55+ platforms : linux/amd64
5156
5257 build_full_api_image :
53- # Any runner supporting Node 20 or newer
58+ name : Build full API image
5459 runs-on : ubuntu-latest
5560 environment : ${{ inputs.environment }}
56- name : Build full API image
5761
58- # Add "id-token" with the intended permissions.
5962 permissions :
6063 contents : " read"
61- # required to auth against GCP
6264 id-token : " write"
6365
6466 steps :
65- - name : checkout repo
67+ - name : Checkout repo
6668 uses : actions/checkout@v4
69+
6770 - uses : " google-github-actions/auth@v2"
6871 with :
6972 workload_identity_provider : " ${{ vars._GITHUB_IDENTITY_POOL_PROVIDER_NAME }}"
7073 service_account : " builder@${{ vars.PROJECT_ID }}.iam.gserviceaccount.com"
71- - name : " Set up Cloud SDK"
74+
75+ - name : Set up Cloud SDK
7276 uses : " google-github-actions/setup-gcloud@v2"
77+
78+ - name : Configure Docker for Artifact Registry
79+ run : gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
80+
81+ - name : Set up Docker Buildx
82+ uses : docker/setup-buildx-action@v3
83+
84+ - name : Build and push full API
85+ uses : docker/build-push-action@v5
7386 with :
74- version : " >= 363.0.0"
75- - name : Build application
76- run : make -f Makefile.deploy publish-full-api-docker TAG=${{ github.sha }} PROJECT_ID=${{ vars.PROJECT_ID }} LOG_DIR=gs://${{ vars.PROJECT_ID }}-buildlogs
87+ context : .
88+ file : projects/policyengine-api-full/Dockerfile
89+ push : true
90+ tags : |
91+ ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO }}/policyengine-api-full:${{ github.sha }}
92+ ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO }}/policyengine-api-full:latest
93+ cache-from : type=gha
94+ cache-to : type=gha,mode=max
95+ platforms : linux/amd64
7796
7897 build_tagger_api_image :
79- # Any runner supporting Node 20 or newer
98+ name : Build tagger API image
8099 runs-on : ubuntu-latest
81100 environment : ${{ inputs.environment }}
82- name : Build tagger API image
83101
84- # Add "id-token" with the intended permissions.
85102 permissions :
86103 contents : " read"
87- # required to auth against GCP
88104 id-token : " write"
89105
90106 steps :
91- - name : checkout repo
107+ - name : Checkout repo
92108 uses : actions/checkout@v4
109+
93110 - uses : " google-github-actions/auth@v2"
94111 with :
95112 workload_identity_provider : " ${{ vars._GITHUB_IDENTITY_POOL_PROVIDER_NAME }}"
96113 service_account : " builder@${{ vars.PROJECT_ID }}.iam.gserviceaccount.com"
97- - name : " Set up Cloud SDK"
114+
115+ - name : Set up Cloud SDK
98116 uses : " google-github-actions/setup-gcloud@v2"
117+
118+ - name : Configure Docker for Artifact Registry
119+ run : gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
120+
121+ - name : Set up Docker Buildx
122+ uses : docker/setup-buildx-action@v3
123+
124+ - name : Build and push tagger API
125+ uses : docker/build-push-action@v5
99126 with :
100- version : " >= 363.0.0"
101- - name : Build application
102- run : make -f Makefile.deploy publish-tagger-api-docker TAG=${{ github.sha }} PROJECT_ID=${{ vars.PROJECT_ID }} LOG_DIR=gs://${{ vars.PROJECT_ID }}-buildlogs
127+ context : .
128+ file : projects/policyengine-api-tagger/Dockerfile
129+ push : true
130+ tags : |
131+ ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO }}/policyengine-api-tagger:${{ github.sha }}
132+ ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO }}/policyengine-api-tagger:latest
133+ cache-from : type=gha
134+ cache-to : type=gha,mode=max
135+ platforms : linux/amd64
0 commit comments