Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCP deployment update #701

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/deploy_gcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Polygon Webflow APIs
on:
push:
branches:
- master
- dev
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
docker-release:
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/dev') ||
(github.event_name == 'push' && github.ref == 'refs/heads/master')
uses: ./.github/workflows/docker_publish_gcp.yaml
with:
core_app: api-polygon-tokens
environment: ${{ (github.ref == 'refs/heads/dev' && 'dev') || (github.ref == 'refs/heads/master' && 'prod') }}
94 changes: 94 additions & 0 deletions .github/workflows/docker_publish_gcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
on:
workflow_call:
inputs:
environment:
required: false
type: string
default: "staging"
core_app:
required: true
type: string
description: "Core App Name"
default: "api-polygon-tokens"

permissions:
contents: read
id-token: write

env:
REGISTRY: europe-west2-docker.pkg.dev/prj-polygonlabs-shared-prod/polygonlabs-docker-prod
IMAGE_NAME: ${{ inputs.core_app }}-${{ inputs.environment }}
OIDC_PROVIDER: projects/23849419004/locations/global/workloadIdentityPools/polygonlabs-shared-prod/providers/oidc-shared-prod
OIDC_SERVICE_ACCOUNT: shared-prod-oidc-sa@prj-polygonlabs-shared-prod.iam.gserviceaccount.com

jobs:
docker-release:
name: Build and push docker image to GitHub Container Registry
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 18.16.1

- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
modules-${{ hashFiles('package-lock.json') }}-

- name: Check cache hit
id: check_cache
if: steps.cache.outcome != 'failure'
run: echo "cache_hit=${{ steps.cache.outputs.cache-hit == 'true' }}" >> $GITHUB_OUTPUT

- name: Install dependencies
if: steps.check_cache.outputs.cache_hit != 'true'
run: npm ci

- name: Build tokenlists
run: npm run build

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Authenticate with GCP via OIDC
uses: google-github-actions/auth@v2
with:
token_format: access_token
workload_identity_provider: ${{ env.OIDC_PROVIDER }}
service_account: ${{ env.OIDC_SERVICE_ACCOUNT }}

- name: Configure Artifact Registry authentication
run: |
echo '{"credHelpers": {"europe-west2-docker.pkg.dev": "gcloud"}}' > ~/.docker/config.json

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
flavor: |
latest=false

- name: Push to GCP Artifact Registry
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max