|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + environment: |
| 5 | + required: false |
| 6 | + type: string |
| 7 | + default: "staging" |
| 8 | + core_app: |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + description: "Core App Name" |
| 12 | + default: "api-polygon-tokens" |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + id-token: write |
| 17 | + |
| 18 | +env: |
| 19 | + REGISTRY: europe-west2-docker.pkg.dev/prj-polygonlabs-shared-prod/polygonlabs-docker-prod |
| 20 | + IMAGE_NAME: ${{ inputs.core_app }}-${{ inputs.environment }} |
| 21 | + OIDC_PROVIDER: projects/23849419004/locations/global/workloadIdentityPools/polygonlabs-shared-prod/providers/oidc-shared-prod |
| 22 | + OIDC_SERVICE_ACCOUNT: shared-prod-oidc-sa@prj-polygonlabs-shared-prod.iam.gserviceaccount.com |
| 23 | + |
| 24 | +jobs: |
| 25 | + docker-release: |
| 26 | + name: Build and push docker image to GitHub Container Registry |
| 27 | + runs-on: ubuntu-latest |
| 28 | + environment: ${{ inputs.environment }} |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Setup node |
| 34 | + uses: actions/setup-node@v2 |
| 35 | + with: |
| 36 | + node-version: 18.16.1 |
| 37 | + |
| 38 | + - name: Cache dependencies |
| 39 | + id: cache |
| 40 | + uses: actions/cache@v3 |
| 41 | + with: |
| 42 | + path: ./node_modules |
| 43 | + key: modules-${{ hashFiles('package-lock.json') }} |
| 44 | + restore-keys: | |
| 45 | + modules-${{ hashFiles('package-lock.json') }}- |
| 46 | +
|
| 47 | + - name: Check cache hit |
| 48 | + id: check_cache |
| 49 | + if: steps.cache.outcome != 'failure' |
| 50 | + run: echo "cache_hit=${{ steps.cache.outputs.cache-hit == 'true' }}" >> $GITHUB_OUTPUT |
| 51 | + |
| 52 | + - name: Install dependencies |
| 53 | + if: steps.check_cache.outputs.cache_hit != 'true' |
| 54 | + run: npm ci |
| 55 | + |
| 56 | + - name: Build tokenlists |
| 57 | + run: npm run build |
| 58 | + |
| 59 | + - name: Set up Docker Buildx |
| 60 | + uses: docker/setup-buildx-action@v3 |
| 61 | + |
| 62 | + - name: Authenticate with GCP via OIDC |
| 63 | + uses: google-github-actions/auth@v2 |
| 64 | + with: |
| 65 | + token_format: access_token |
| 66 | + workload_identity_provider: ${{ env.OIDC_PROVIDER }} |
| 67 | + service_account: ${{ env.OIDC_SERVICE_ACCOUNT }} |
| 68 | + |
| 69 | + - name: Configure Artifact Registry authentication |
| 70 | + run: | |
| 71 | + echo '{"credHelpers": {"europe-west2-docker.pkg.dev": "gcloud"}}' > ~/.docker/config.json |
| 72 | +
|
| 73 | + - name: Extract metadata (tags, labels) for Docker |
| 74 | + id: meta |
| 75 | + uses: docker/metadata-action@v5 |
| 76 | + with: |
| 77 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 78 | + tags: | |
| 79 | + type=ref,event=branch |
| 80 | + type=ref,event=pr |
| 81 | + type=semver,pattern={{version}} |
| 82 | + type=semver,pattern={{major}}.{{minor}} |
| 83 | + flavor: | |
| 84 | + latest=false |
| 85 | +
|
| 86 | + - name: Push to GCP Artifact Registry |
| 87 | + uses: docker/build-push-action@v6 |
| 88 | + with: |
| 89 | + push: true |
| 90 | + tags: ${{ steps.meta.outputs.tags }} |
| 91 | + labels: ${{ steps.meta.outputs.labels }} |
| 92 | + cache-from: type=gha |
| 93 | + cache-to: type=gha,mode=max |
| 94 | + |
0 commit comments