Skip to content

Commit 82a255d

Browse files
committed
feat: implement multi-service CI/CD with Workload Identity Federation
1 parent 6263d23 commit 82a255d

File tree

4 files changed

+144
-6
lines changed

4 files changed

+144
-6
lines changed

.github/workflows/cd-extract.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Deploy Data Extract Job
2+
3+
# Only run when merged changes happen in data_extract folder
4+
on:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- 'data_extract/**'
10+
11+
permissions:
12+
contents: 'read'
13+
id-token: 'write'
14+
15+
# Service configurations in GCP
16+
env:
17+
REGION: us-east1
18+
REPO_NAME: operations-artifacts
19+
IMAGE_NAME: extractor
20+
JOB_NAME: drive-extractor
21+
22+
jobs:
23+
build-and-deploy:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout Code
27+
uses: actions/checkout@v4
28+
29+
# Handshake to GCP
30+
- name: Authenticate to Google Cloud
31+
id: auth
32+
uses: google-github-actions/auth@v2
33+
with:
34+
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
35+
service_account: ${{ secrets.DEPLOYER_SA_EMAIL }}
36+
37+
- name: Set up Cloud SDK
38+
uses: google-github-actions/setup-gcloud@v2
39+
40+
# Handshake to Artifact registry
41+
- name: Configure Docker Auth
42+
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
43+
44+
45+
- name: Build and Push Docker Image
46+
run: |
47+
# Full image path using the Git Commit Hash (github.sha)
48+
IMAGE_PATH="${{ env.REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
49+
50+
# Build from root to ensure COPY commands find the files
51+
docker build -f data_extract/Dockerfile -t $IMAGE_PATH .
52+
53+
# Push to Artifact Registry
54+
docker push $IMAGE_PATH
55+
56+
57+
- name: Deploy to Cloud Run Job
58+
run: |
59+
IMAGE_PATH="${{ env.REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
60+
61+
gcloud run jobs deploy ${{ env.JOB_NAME }} \
62+
--image $IMAGE_PATH \
63+
--region ${{ env.REGION }} \
64+
--service-account ${{ secrets.EXTRACTOR_SA_EMAIL }}

.github/workflows/cd-pipeline.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Deploy Data Pipeline Job
2+
3+
# Only run when merged changes happen in data_pipeline folder
4+
on:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- 'data_pipeline/**'
10+
11+
permissions:
12+
contents: 'read'
13+
id-token: 'write'
14+
15+
# Service configurations in GCP
16+
env:
17+
REGION: us-east1
18+
REPO_NAME: operations-artifacts
19+
IMAGE_NAME: pipeline
20+
JOB_NAME: operations-pipeline
21+
22+
jobs:
23+
build-and-deploy:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout Code
27+
uses: actions/checkout@v4
28+
29+
# Handshake to GCP
30+
- name: Authenticate to Google Cloud
31+
id: auth
32+
uses: google-github-actions/auth@v2
33+
with:
34+
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
35+
service_account: ${{ secrets.DEPLOYER_SA_EMAIL }}
36+
37+
- name: Set up Cloud SDK
38+
uses: google-github-actions/setup-gcloud@v2
39+
40+
# Handshake to Artifact registry
41+
- name: Configure Docker Auth
42+
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
43+
44+
45+
- name: Build and Push Docker Image
46+
run: |
47+
# Full image path using the Git Commit Hash (github.sha)
48+
IMAGE_PATH="${{ env.REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
49+
50+
# Build from root to ensure COPY commands find the files
51+
docker build -f data_pipeline/Dockerfile -t $IMAGE_PATH .
52+
53+
# Push to Artifact Registry
54+
docker push $IMAGE_PATH
55+
56+
57+
- name: Deploy to Cloud Run Job
58+
run: |
59+
IMAGE_PATH="${{ env.REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
60+
61+
gcloud run jobs deploy ${{ env.JOB_NAME }} \
62+
--image $IMAGE_PATH \
63+
--region ${{ env.REGION }} \
64+
--service-account ${{ secrets.PIPELINE_SA_EMAIL }}

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI/CD Pipeline
1+
name: CI - Code Quality & Tests
22

33
on:
44
pull_request:
@@ -19,21 +19,21 @@ jobs:
1919
with:
2020
python-version: "3.11"
2121

22-
- name: Install dependencies
22+
- name: Install Dependencies
2323
run: |
2424
python -m pip install --upgrade pip
2525
pip install -r dev-requirements.txt
2626
2727
- name: Set PYTHONPATH
2828
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
2929

30-
- name: Check formatting
30+
- name: Check Code Formatting
3131
run: black --check .
3232

33-
- name: Lint with ruff
33+
- name: Ruff Linting
3434
run: ruff check .
3535

36-
- name: Run tests with coverage enforcement
36+
- name: Run Tests with Coverage
3737
run: |
3838
pytest \
3939
--cov=data_pipeline \

dev-requirements.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
# extract
2+
google-api-python-client
3+
google-auth-httplib2
4+
google-auth-oauthlib
5+
6+
httplib2
7+
pyparsing<3.0.0
8+
tzdata
9+
10+
# pipeline
111
pandas==2.1.4
212
pytest==9.0.2
313
pyarrow==19.0.0
414
black==24.3.0
515
ruff==0.0.264
6-
google-cloud-storage==3.9.0
16+
google-cloud-storage
717
pytest-cov

0 commit comments

Comments
 (0)