Skip to content

Commit 81fb002

Browse files
committed
GCP Deployment for docker image updated.
1 parent 5ea49e6 commit 81fb002

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
environment:
5+
required: false
6+
type: string
7+
default: "dev"
8+
core_app:
9+
required: false
10+
type: string
11+
description: "Core app name"
12+
default: "polygon-docs"
13+
14+
env:
15+
REGISTRY: europe-west2-docker.pkg.dev/prj-polygonlabs-shared-prod/polygonlabs-docker-prod
16+
IMAGE_NAME: ${{ inputs.core_app }}
17+
OIDC_PROVIDER: projects/23849419004/locations/global/workloadIdentityPools/polygonlabs-shared-prod/providers/oidc-shared-prod
18+
OIDC_SERVICE_ACCOUNT: shared-prod-oidc-sa@prj-polygonlabs-shared-prod.iam.gserviceaccount.com
19+
20+
jobs:
21+
build_and_deploy:
22+
runs-on: ubuntu-latest
23+
environment: ${{ inputs.environment }}
24+
permissions:
25+
id-token: write
26+
contents: write
27+
pull-requests: write
28+
steps:
29+
- uses: actions/setup-python@v4
30+
with:
31+
python-version: '3.11'
32+
33+
- name: Install pipenv
34+
run: pip install pipenv
35+
36+
- name: Checkout Code Repository
37+
uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 0
40+
41+
- name: Authenticate GitHub CLI
42+
run: gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
43+
44+
- name: Build Site
45+
run: |
46+
python build_branches.py -env "${{ inputs.environment }}"
47+
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
- name: Authenticate with GCP via OIDC
52+
uses: google-github-actions/auth@v2
53+
with:
54+
token_format: access_token
55+
workload_identity_provider: ${{ env.OIDC_PROVIDER }}
56+
service_account: ${{ env.OIDC_SERVICE_ACCOUNT }}
57+
58+
- name: Configure Artifact Registry authentication
59+
run: |
60+
echo '{"credHelpers": {"europe-west2-docker.pkg.dev": "gcloud"}}' > ~/.docker/config.json
61+
62+
- name: Extract metadata (tags, labels) for Docker
63+
id: meta
64+
uses: docker/metadata-action@v5
65+
with:
66+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
67+
tags: |
68+
type=ref,event=branch
69+
type=ref,event=pr
70+
type=semver,pattern={{version}}
71+
type=semver,pattern={{major}}.{{minor}}
72+
flavor: |
73+
latest=false
74+
75+
- name: Push to GCP Artifact Registry
76+
uses: docker/build-push-action@v6
77+
with:
78+
file: ${{ inputs.dockerfile_path }}
79+
context: ${{ inputs.dockerfile_context }}
80+
push: true
81+
tags: ${{ steps.meta.outputs.tags }}
82+
labels: ${{ steps.meta.outputs.labels }}
83+
cache-from: type=gha
84+
cache-to: type=gha,mode=max

.github/workflows/deploy_gcp.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Docs Deployment GCP
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
push:
7+
branches:
8+
- dev
9+
- main
10+
workflow_dispatch:
11+
inputs:
12+
environment:
13+
required: false
14+
type: choice
15+
description: "Select the environment to deploy to (only required for production deployment)"
16+
options:
17+
- staging
18+
- prod
19+
20+
jobs:
21+
deploy:
22+
if: |
23+
(github.event_name == 'pull_request' && startsWith(github.head_ref, 'hosted/')) ||
24+
(github.event_name == 'push' && github.ref == 'refs/heads/dev') ||
25+
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
26+
(github.event_name == 'workflow_dispatch' && inputs.environment == 'prod')
27+
uses: ./.github/workflows/build_and_deploy_gcp.yml
28+
with:
29+
environment: ${{ inputs.environment ||
30+
(github.ref == 'refs/heads/dev' && 'dev') ||
31+
(github.ref == 'refs/heads/main' && 'staging') ||
32+
(github.event_name == 'pull_request' && 'dev') ||
33+
'dev' }}
34+
secrets: inherit

0 commit comments

Comments
 (0)