|
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. |
| 1 | +name: Docker Build & Publish |
7 | 2 |
|
8 | 3 | on: |
9 | | - schedule: |
10 | | - - cron: '43 7 * * *' |
11 | 4 | push: |
12 | | - branches: [ "master" ] |
13 | | - # Publish semver tags as releases. |
14 | | - tags: [ 'v*.*.*' ] |
| 5 | + branches: ["master"] |
| 6 | + tags: ["v*.*.*"] |
15 | 7 | pull_request: |
16 | | - branches: [ "master" ] |
| 8 | + branches: ["master"] |
| 9 | + workflow_dispatch: |
17 | 10 |
|
18 | 11 | env: |
19 | | - # Use docker.io for Docker Hub if empty |
20 | | - REGISTRY: ghcr.io |
21 | | - # github.repository as <account>/<repo> |
| 12 | + REGISTRY_GHCR: ghcr.io |
| 13 | + REGISTRY_DOCKER: docker.io |
22 | 14 | IMAGE_NAME: ${{ github.repository }} |
23 | 15 |
|
| 16 | +concurrency: |
| 17 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
24 | 19 |
|
25 | 20 | jobs: |
26 | 21 | build: |
27 | | - |
28 | 22 | runs-on: ubuntu-latest |
29 | 23 | permissions: |
30 | 24 | contents: read |
31 | 25 | packages: write |
32 | | - # This is used to complete the identity challenge |
33 | | - # with sigstore/fulcio when running outside of PRs. |
34 | 26 | id-token: write |
| 27 | + attestations: write |
35 | 28 |
|
36 | 29 | steps: |
37 | 30 | - name: Checkout repository |
38 | 31 | uses: actions/checkout@v4 |
39 | 32 |
|
40 | | - # Install the cosign tool except on PR |
41 | | - # https://github.com/sigstore/cosign-installer |
42 | 33 | - name: Install cosign |
43 | 34 | if: github.event_name != 'pull_request' |
44 | | - uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 |
45 | | - with: |
46 | | - cosign-release: 'v2.2.4' |
| 35 | + uses: sigstore/cosign-installer@v3 |
| 36 | + |
| 37 | + - name: Set up QEMU |
| 38 | + uses: docker/setup-qemu-action@v3 |
47 | 39 |
|
48 | | - # Set up BuildKit Docker container builder to be able to build |
49 | | - # multi-platform images and export cache |
50 | | - # https://github.com/docker/setup-buildx-action |
51 | 40 | - name: Set up Docker Buildx |
52 | | - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 41 | + uses: docker/setup-buildx-action@v3 |
53 | 42 |
|
54 | | - # Login against a Docker registry except on PR |
55 | | - # https://github.com/docker/login-action |
56 | | - - name: Log into registry ${{ env.REGISTRY }} |
| 43 | + - name: Log into GHCR |
57 | 44 | if: github.event_name != 'pull_request' |
58 | | - uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 |
| 45 | + uses: docker/login-action@v3 |
59 | 46 | with: |
60 | | - registry: ${{ env.REGISTRY }} |
| 47 | + registry: ${{ env.REGISTRY_GHCR }} |
61 | 48 | username: ${{ github.actor }} |
62 | 49 | password: ${{ secrets.GITHUB_TOKEN }} |
63 | 50 |
|
64 | | - # Extract metadata (tags, labels) for Docker |
65 | | - # https://github.com/docker/metadata-action |
| 51 | + - name: Log into Docker Hub |
| 52 | + if: github.event_name != 'pull_request' && vars.PUBLISH_TO_DOCKERHUB == 'true' |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ${{ env.REGISTRY_DOCKER }} |
| 56 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 57 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Extract version |
| 60 | + id: version |
| 61 | + run: | |
| 62 | + VERSION=$(grep ':version' package.ring | head -1 | sed 's/.*"\([^"]*\)".*/\1/') |
| 63 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 64 | + echo "Extracted version: $VERSION" |
| 65 | +
|
66 | 66 | - name: Extract Docker metadata |
67 | 67 | id: meta |
68 | | - uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 |
| 68 | + uses: docker/metadata-action@v5 |
69 | 69 | with: |
70 | | - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 70 | + images: | |
| 71 | + ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }} |
| 72 | + ${{ vars.PUBLISH_TO_DOCKERHUB == 'true' && format('{0}/{1}', env.REGISTRY_DOCKER, env.IMAGE_NAME) || '' }} |
| 73 | + tags: | |
| 74 | + # Set latest tag for master branch |
| 75 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} |
| 76 | + # Version from package.ring |
| 77 | + type=raw,value=${{ steps.version.outputs.version }},enable=${{ github.ref == 'refs/heads/master' }} |
| 78 | + # Git tag (v1.2.3 -> 1.2.3) |
| 79 | + type=semver,pattern={{version}} |
| 80 | + # Git tag (v1.2.3 -> 1.2) |
| 81 | + type=semver,pattern={{major}}.{{minor}} |
| 82 | + # Git short SHA |
| 83 | + type=sha,prefix=sha-,format=short |
| 84 | + labels: | |
| 85 | + org.opencontainers.image.title=DistroMap API |
| 86 | + org.opencontainers.image.description=Linux distribution release information API |
| 87 | + org.opencontainers.image.vendor=ysdragon |
71 | 88 |
|
72 | | - # Build and push Docker image with Buildx (don't push on PR) |
73 | | - # https://github.com/docker/build-push-action |
74 | 89 | - name: Build and push Docker image |
75 | 90 | id: build-and-push |
76 | | - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 |
| 91 | + uses: docker/build-push-action@v6 |
77 | 92 | with: |
78 | 93 | context: . |
| 94 | + platforms: linux/amd64,linux/arm64 |
79 | 95 | push: ${{ github.event_name != 'pull_request' }} |
80 | 96 | tags: ${{ steps.meta.outputs.tags }} |
81 | 97 | labels: ${{ steps.meta.outputs.labels }} |
82 | 98 | cache-from: type=gha |
83 | 99 | cache-to: type=gha,mode=max |
| 100 | + build-args: | |
| 101 | + VERSION=${{ steps.version.outputs.version }} |
| 102 | + BUILD_DATE=${{ github.event.head_commit.timestamp }} |
| 103 | + VCS_REF=${{ github.sha }} |
| 104 | +
|
| 105 | + - name: Generate artifact attestation |
| 106 | + if: github.event_name != 'pull_request' |
| 107 | + uses: actions/attest-build-provenance@v2 |
| 108 | + with: |
| 109 | + subject-name: ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }} |
| 110 | + subject-digest: ${{ steps.build-and-push.outputs.digest }} |
| 111 | + push-to-registry: true |
84 | 112 |
|
85 | | - # Sign the resulting Docker image digest except on PRs. |
86 | | - # This will only write to the public Rekor transparency log when the Docker |
87 | | - # repository is public to avoid leaking data. If you would like to publish |
88 | | - # transparency data even for private images, pass --force to cosign below. |
89 | | - # https://github.com/sigstore/cosign |
90 | 113 | - name: Sign the published Docker image |
91 | | - if: ${{ github.event_name != 'pull_request' }} |
| 114 | + if: github.event_name != 'pull_request' |
92 | 115 | env: |
93 | | - # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable |
94 | 116 | TAGS: ${{ steps.meta.outputs.tags }} |
95 | 117 | DIGEST: ${{ steps.build-and-push.outputs.digest }} |
96 | | - # This step uses the identity token to provision an ephemeral certificate |
97 | | - # against the sigstore community Fulcio instance. |
98 | 118 | run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
| 119 | + |
| 120 | + - name: Build Summary |
| 121 | + run: | |
| 122 | + echo "## Build Summary" >> $GITHUB_STEP_SUMMARY |
| 123 | + echo "- **Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "- **Platforms:** linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "- **Digest:** ${{ steps.build-and-push.outputs.digest }}" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "### Tags" >> $GITHUB_STEP_SUMMARY |
| 127 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 128 | + echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY |
| 129 | + echo '```' >> $GITHUB_STEP_SUMMARY |
0 commit comments