|
| 1 | +name: "Build and Push Docker image" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + release: |
| 8 | + types: |
| 9 | + - published |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: ghcr.io |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref }} |
| 16 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' && github.ref_type != 'tag' }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + name: Build ${{ matrix.name }} - ${{ matrix.label }} |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - name: GitHub Actions |
| 25 | + dockerfile: Dockerfile.gha |
| 26 | + label: ${{ github.repository_owner }}/temporal-gha-service |
| 27 | + - name: Official |
| 28 | + dockerfile: Dockerfile |
| 29 | + label: ${{ github.repository_owner }}/temporal-dev-server |
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + packages: write |
| 33 | + id-token: write |
| 34 | + |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + |
| 39 | + # Install the cosign tool except on PR |
| 40 | + # https://github.com/sigstore/cosign-installer |
| 41 | + # - name: Install cosign |
| 42 | + # if: github.event_name != 'pull_request' |
| 43 | + # uses: sigstore/[email protected] |
| 44 | + # with: |
| 45 | + # cosign-release: "v2.1.1" |
| 46 | + |
| 47 | + # Set up BuildKit Docker container builder to be able to build |
| 48 | + # multi-platform images and export cache |
| 49 | + # https://github.com/docker/setup-buildx-action |
| 50 | + - name: Set up Docker Buildx |
| 51 | + |
| 52 | + with: |
| 53 | + install: true |
| 54 | + |
| 55 | + # Login against a Docker registry except on PR |
| 56 | + # https://github.com/docker/login-action |
| 57 | + - name: Log into registry ${{ env.REGISTRY }} |
| 58 | + if: github.event_name != 'pull_request' |
| 59 | + |
| 60 | + with: |
| 61 | + registry: ${{ env.REGISTRY }} |
| 62 | + username: ${{ github.actor }} |
| 63 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + |
| 65 | + # Extract metadata (tags, labels) for Docker |
| 66 | + # https://github.com/docker/metadata-action |
| 67 | + - name: Extract Docker metadata (${{ matrix.name }}) |
| 68 | + id: meta |
| 69 | + |
| 70 | + with: |
| 71 | + images: "${{ env.REGISTRY }}/${{ matrix.label }}" |
| 72 | + |
| 73 | + # Build and push Docker image with Buildx (don't push on PR) |
| 74 | + # https://github.com/docker/build-push-action |
| 75 | + - name: Build and push Docker image (${{ matrix.name }}) |
| 76 | + id: build-and-push |
| 77 | + |
| 78 | + with: |
| 79 | + context: . |
| 80 | + file: ${{ matrix.dockerfile }} |
| 81 | + push: ${{ github.event_name != 'pull_request' }} |
| 82 | + tags: ${{ steps.meta.outputs.tags }} |
| 83 | + labels: ${{ steps.meta.outputs.labels }} |
| 84 | + cache-from: type=gha |
| 85 | + cache-to: type=gha,mode=max |
| 86 | + |
| 87 | + # Sign the resulting Docker image digest except on PRs. |
| 88 | + # This will only write to the public Rekor transparency log when the Docker |
| 89 | + # repository is public to avoid leaking data. If you would like to publish |
| 90 | + # transparency data even for private images, pass --force to cosign below. |
| 91 | + # https://github.com/sigstore/cosign |
| 92 | + # - name: Sign the published Docker image |
| 93 | + # if: ${{ github.event_name != 'pull_request' }} |
| 94 | + # env: |
| 95 | + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable |
| 96 | + # COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} |
| 97 | + # COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} |
| 98 | + # DIGEST: ${{ steps.build-and-push.outputs.digest }} |
| 99 | + # TAGS: ${{ steps.meta.outputs.tags }} |
| 100 | + # This step uses the identity token to provision an ephemeral certificate |
| 101 | + # against the sigstore community Fulcio instance. |
| 102 | + # run: echo "${TAGS}" | xargs -I {} cosign sign --yes --key env://COSIGN_PRIVATE_KEY {}@${DIGEST} |
0 commit comments