Skip to content

Commit f5f4d41

Browse files
authored
Merge pull request 0xPolygon#2596 from 0xPolygon/SPEC-889-Add-github-workflow-to-publish-docker-img
GCP Deployment for docker image updated.
2 parents dc6f275 + 2e598b1 commit f5f4d41

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
permissions:
21+
contents: read
22+
id-token: write
23+
24+
jobs:
25+
build_and_deploy:
26+
runs-on: ubuntu-latest
27+
environment: ${{ inputs.environment }}
28+
permissions:
29+
id-token: write
30+
contents: write
31+
pull-requests: write
32+
steps:
33+
- uses: actions/setup-python@v4
34+
with:
35+
python-version: '3.11'
36+
37+
- name: Install pipenv
38+
run: pip install pipenv
39+
40+
- name: Checkout Code Repository
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
45+
- name: Authenticate GitHub CLI
46+
run: gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
47+
48+
- name: Build Site
49+
run: |
50+
python build_branches.py -env "${{ inputs.environment }}"
51+
52+
- name: Set up Docker Buildx
53+
uses: docker/setup-buildx-action@v3
54+
55+
- name: Authenticate with GCP via OIDC
56+
uses: google-github-actions/auth@v2
57+
with:
58+
token_format: access_token
59+
workload_identity_provider: ${{ env.OIDC_PROVIDER }}
60+
service_account: ${{ env.OIDC_SERVICE_ACCOUNT }}
61+
62+
- name: Configure Artifact Registry authentication
63+
run: |
64+
echo '{"credHelpers": {"europe-west2-docker.pkg.dev": "gcloud"}}' > ~/.docker/config.json
65+
66+
- name: Extract metadata (tags, labels) for Docker
67+
id: meta
68+
uses: docker/metadata-action@v5
69+
with:
70+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
71+
tags: |
72+
type=ref,event=branch
73+
type=ref,event=pr
74+
type=semver,pattern={{version}}
75+
type=semver,pattern={{major}}.{{minor}}
76+
flavor: |
77+
latest=false
78+
79+
- name: Push to GCP Artifact Registry
80+
uses: docker/build-push-action@v6
81+
with:
82+
file: ${{ inputs.dockerfile_path }}
83+
context: ${{ inputs.dockerfile_context }}
84+
push: true
85+
tags: ${{ steps.meta.outputs.tags }}
86+
labels: ${{ steps.meta.outputs.labels }}
87+
cache-from: type=gha
88+
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)