|
| 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 |
0 commit comments