Skip to content

Commit 4ee754f

Browse files
authored
Update docker-publish.yml
1 parent 575f575 commit 4ee754f

File tree

1 file changed

+31
-73
lines changed

1 file changed

+31
-73
lines changed

.github/workflows/docker-publish.yml

Lines changed: 31 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,56 @@
1-
name: Docker
2-
31
# This workflow uses actions that are not certified by GitHub.
42
# They are provided by a third-party and are governed by
53
# separate terms of service, privacy policy, and support
64
# documentation.
75

8-
on:
9-
schedule:
10-
- cron: '19 4 * * *'
11-
push:
12-
branches: [ "master" ]
13-
# Publish semver tags as releases.
14-
tags: [ 'v*.*.*' ]
15-
pull_request:
16-
branches: [ "master" ]
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# To get a newer version, you will need to update the SHA.
8+
# You can also reference a tag or branch, but the action may change without warning.
179

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 }}
10+
name: Publish Docker image
2311

12+
on:
13+
release:
14+
types: [published]
2415

2516
jobs:
26-
build:
27-
17+
push_to_registry:
18+
name: Push Docker image to Docker Hub
2819
runs-on: ubuntu-latest
2920
permissions:
30-
contents: read
3121
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-
22+
contents: read
23+
attestations: write
3624
steps:
37-
- name: Checkout repository
25+
- name: Check out the repo
3826
uses: actions/checkout@v4
3927

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@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
45-
with:
46-
cosign-release: 'v2.1.1'
47-
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-
- name: Set up Docker Buildx
52-
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
53-
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
28+
- name: Log in to Docker Hub
29+
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
5930
with:
60-
registry: ${{ env.REGISTRY }}
61-
username: ${{ github.actor }}
62-
password: ${{ secrets.GITHUB_TOKEN }}
31+
username: ${{ secrets.DOCKER_USERNAME }}
32+
password: ${{ secrets.DOCKER_PASSWORD }}
6333

64-
# Extract metadata (tags, labels) for Docker
65-
# https://github.com/docker/metadata-action
66-
- name: Extract Docker metadata
34+
- name: Extract metadata (tags, labels) for Docker
6735
id: meta
68-
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
36+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
6937
with:
70-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38+
images: my-docker-hub-namespace/my-docker-hub-repository
7139

72-
# Build and push Docker image with Buildx (don't push on PR)
73-
# https://github.com/docker/build-push-action
7440
- name: Build and push Docker image
75-
id: build-and-push
76-
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
41+
id: push
42+
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
7743
with:
7844
context: .
79-
push: ${{ github.event_name != 'pull_request' }}
45+
file: ./Dockerfile
46+
push: true
8047
tags: ${{ steps.meta.outputs.tags }}
8148
labels: ${{ steps.meta.outputs.labels }}
82-
cache-from: type=gha
83-
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}
49+
50+
51+
- name: Generate artifact attestation
52+
uses: actions/attest-build-provenance@v1
53+
with:
54+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
55+
subject-digest: ${{ steps.push.outputs.digest }}
56+
push-to-registry: true

0 commit comments

Comments
 (0)