Skip to content

Commit 0bc1c14

Browse files
authored
Refactor Docker publish workflow for GitHub Actions
1 parent 189f0ab commit 0bc1c14

1 file changed

Lines changed: 21 additions & 70 deletions

File tree

Lines changed: 21 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,49 @@
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: Publish Container
72

83
on:
9-
schedule:
10-
- cron: '30 6 * * *'
114
push:
12-
branches: [ "main" ]
13-
# Publish semver tags as releases.
14-
tags: [ 'v*.*.*' ]
15-
pull_request:
16-
branches: [ "main" ]
17-
18-
env:
19-
# Use docker.io for Docker Hub if empty
20-
REGISTRY: ghcr.io
21-
# github.repository as <account>/<repo>
22-
IMAGE_NAME: ${{ github.repository }}
23-
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
workflow_dispatch:
2410

2511
jobs:
26-
build:
27-
12+
build-and-push:
2813
runs-on: ubuntu-latest
2914
permissions:
3015
contents: read
3116
packages: write
32-
# This is used to complete the identity challenge
33-
# with sigstore/fulcio when running outside of PRs.
34-
id-token: write
35-
3617
steps:
37-
- name: Checkout repository
18+
- name: Checkout
3819
uses: actions/checkout@v4
3920

40-
# Install the cosign tool except on PR
41-
# https://github.com/sigstore/cosign-installer
42-
- name: Install cosign
43-
if: github.event_name != 'pull_request'
44-
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
45-
with:
46-
cosign-release: 'v2.2.4'
21+
- name: Set up QEMU
22+
uses: docker/setup-qemu-action@v3
4723

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
5124
- name: Set up Docker Buildx
52-
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
25+
uses: docker/setup-buildx-action@v3
5326

54-
# Login against a Docker registry except on PR
55-
# https://github.com/docker/login-action
56-
- name: Log into registry ${{ env.REGISTRY }}
57-
if: github.event_name != 'pull_request'
58-
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
27+
- name: Log in to GitHub Container Registry
28+
uses: docker/login-action@v3
5929
with:
60-
registry: ${{ env.REGISTRY }}
61-
username: ${{ github.actor }}
30+
registry: ghcr.io
31+
username: ${{ github.repository_owner }}
6232
password: ${{ secrets.GITHUB_TOKEN }}
6333

64-
# Extract metadata (tags, labels) for Docker
65-
# https://github.com/docker/metadata-action
6634
- name: Extract Docker metadata
6735
id: meta
68-
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
36+
uses: docker/metadata-action@v5
6937
with:
70-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38+
images: ghcr.io/${{ github.repository_owner }}/traefiklens
7139

72-
# Build and push Docker image with Buildx (don't push on PR)
73-
# https://github.com/docker/build-push-action
74-
- name: Build and push Docker image
75-
id: build-and-push
76-
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
40+
- name: Build and push image
41+
uses: docker/build-push-action@v5
7742
with:
7843
context: .
79-
push: ${{ github.event_name != 'pull_request' }}
44+
push: true
8045
tags: ${{ steps.meta.outputs.tags }}
8146
labels: ${{ steps.meta.outputs.labels }}
47+
platforms: linux/amd64,linux/arm64
8248
cache-from: type=gha
8349
cache-to: type=gha,mode=max
84-
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-
- name: Sign the published Docker image
91-
if: ${{ github.event_name != 'pull_request' }}
92-
env:
93-
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
94-
TAGS: ${{ steps.meta.outputs.tags }}
95-
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-
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)