Skip to content

Commit 2fea273

Browse files
Merge pull request #141 from CodeForPhilly/GH_actions_deploy_pipeline
CICD: Added GitHub actions workflow for building and deploying builde…
2 parents 5eef816 + 55810df commit 2fea273

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.
29+
30+
name: 'Build and Deploy to Cloud Run'
31+
32+
on:
33+
push:
34+
branches:
35+
- '"main"'
36+
paths:
37+
- 'builder-api/**'
38+
39+
env:
40+
PROJECT_ID: 'benefit-decision-toolkit-play'
41+
REGION: 'us-central1'
42+
SERVICE: 'benefit-decision-toolkit-play'
43+
API_NAME: 'builder-api'
44+
WORKLOAD_IDENTITY_PROVIDER: 'projects/1034049717668/locations/global/workloadIdentityPools/github-actions-google-cloud/providers/github'
45+
46+
jobs:
47+
deploy:
48+
runs-on: 'ubuntu-latest'
49+
50+
permissions:
51+
contents: 'read'
52+
id-token: 'write'
53+
54+
steps:
55+
- name: 'Checkout'
56+
uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions/checkout@v4
57+
58+
# Configure Workload Identity Federation and generate an access token.
59+
#
60+
# See https://github.com/google-github-actions/auth for more options,
61+
# including authenticating via a JSON credentials file.
62+
- id: 'auth'
63+
name: 'Authenticate to Google Cloud'
64+
uses: 'google-github-actions/auth@f112390a2df9932162083945e46d439060d66ec2' # google-github-actions/auth@v2
65+
with:
66+
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
67+
68+
# BEGIN - Docker auth and build
69+
#
70+
# If you already have a container image, you can omit these steps.
71+
- name: 'Docker Auth'
72+
uses: 'docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567' # docker/login-action@v3
73+
with:
74+
username: 'oauth2accesstoken'
75+
password: '${{ steps.auth.outputs.auth_token }}'
76+
registry: '${{ env.REGION }}-docker.pkg.dev'
77+
78+
- name: 'Build and Push Container'
79+
run: |-
80+
cd "${{ env.API_NAME }}"
81+
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.API_NAME }}:latest"
82+
docker build -f src/main/docker/Dockerfile.jvm --tag "${DOCKER_TAG}" .
83+
docker push "${DOCKER_TAG}"
84+
85+
- name: 'Deploy to Cloud Run'
86+
87+
# END - Docker auth and build
88+
89+
uses: 'google-github-actions/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17' # google-github-actions/deploy-cloudrun@v2
90+
with:
91+
service: '${{ env.SERVICE }}'
92+
region: '${{ env.REGION }}'
93+
# NOTE: If using a pre-built image, update the image name below:
94+
95+
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.API_NAME }}:latest'
96+
# If required, use the Cloud Run URL output in later steps
97+
- name: 'Show output'
98+
run: |2-
99+
100+
echo ${{ steps.deploy.outputs.url }}

0 commit comments

Comments
 (0)