Debian Codegraph @

.github/workflows/docker-publish.yml

raw symbols SCIP
1 name: Docker
2
3 # This workflow uses actions that are not certified by GitHub.
4 # They are provided by a third-party and are governed by
5 # separate terms of service, privacy policy, and support
6 # documentation.
7
8 on:
9 workflow_dispatch:
10 push:
11 branches: [ "master" ]
12 # Publish semver tags as releases.
13 tags: [ 'v*.*.*' ]
14 pull_request:
15 branches: [ "master" ]
16
17 env:
18 # Use docker.io for Docker Hub if empty
19 REGISTRY: ghcr.io
20
21 jobs:
22 build:
23
24 runs-on: ubuntu-latest
25 permissions:
26 contents: read
27 packages: write
28 # This is used to complete the identity challenge
29 # with sigstore/fulcio when running outside of PRs.
30 id-token: write
31
32 steps:
33 - name: Setup environment
34 shell: bash
35 run: |
36 printf >> "${GITHUB_ENV}" -- '%s=%s\n' \
37 'IMAGE_NAME' "${GITHUB_REPOSITORY@L}"
38
39 - name: Checkout repository
40 uses: actions/checkout@v6
41
42 # Install the cosign tool except on PR
43 # https://github.com/sigstore/cosign-installer
44 - name: Install cosign
45 if: github.event_name != 'pull_request'
46 uses: sigstore/cosign-installer@v3
47
48 # Add support for more platforms with QEMU
49 # https://github.com/docker/setup-qemu-action
50 - name: Set up QEMU
51 uses: docker/setup-qemu-action@v3
52
53 # Set up BuildKit Docker container builder to be able to build
54 # multi-platform images and export cache
55 # https://github.com/docker/setup-buildx-action
56 - name: Set up Docker Buildx
57 uses: docker/setup-buildx-action@v3
58
59 # Login against a Docker registry except on PR
60 # https://github.com/docker/login-action
61 - name: Log into registry ${{ env.REGISTRY }}
62 if: github.event_name != 'pull_request'
63 uses: docker/login-action@v3
64 with:
65 registry: ${{ env.REGISTRY }}
66 username: ${{ github.actor }}
67 password: ${{ secrets.GITHUB_TOKEN }}
68
69 # Extract metadata (tags, labels) for Docker
70 # https://github.com/docker/metadata-action
71 - name: Extract Docker metadata
72 id: meta
73 uses: docker/metadata-action@v5
74 with:
75 images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
76
77 # Build and push Docker image with Buildx (don't push on PR)
78 # https://github.com/docker/build-push-action
79 - name: Build and push Docker image
80 id: build-and-push
81 uses: docker/build-push-action@v6
82 with:
83 context: .
84 platforms: linux/arm64,linux/amd64
85 pull: true
86 push: ${{ github.event_name != 'pull_request' }}
87 tags: ${{ steps.meta.outputs.tags }}
88 labels: ${{ steps.meta.outputs.labels }}
89 cache-from: type=gha
90 cache-to: type=gha,mode=max
91
92 # Sign the resulting Docker image digest except on PRs.
93 # This will only write to the public Rekor transparency log when the Docker
94 # repository is public to avoid leaking data. If you would like to publish
95 # transparency data even for private images, pass --force to cosign below.
96 # https://github.com/sigstore/cosign
97 - name: Sign the published Docker image
98 if: ${{ github.event_name != 'pull_request' }}
99 env:
100 # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
101 TAGS: ${{ steps.meta.outputs.tags }}
102 DIGEST: ${{ steps.build-and-push.outputs.digest }}
103 # This step uses the identity token to provision an ephemeral certificate
104 # against the sigstore community Fulcio instance.
105 run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}