Skip to content

Commit cc863d3

Browse files
committed
Update docker-publish.yml
Signed-off-by: Md Imran <[email protected]>
1 parent e622f4b commit cc863d3

File tree

1 file changed

+48
-24
lines changed

1 file changed

+48
-24
lines changed

.github/workflows/docker-publish.yml

+48-24
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,89 @@
1-
name: Docker Latest Version
2-
31
on:
42
push:
5-
branches:
6-
- "master"
3+
branches: [ "master" ]
4+
# Publish semver tags as releases.
5+
tags: [ 'v*.*.*' ]
76
pull_request:
8-
branches:
9-
- "master"
10-
workflow_dispatch:
7+
branches: [ "master" ]
118

129
env:
13-
# Docker Hub registry URL (use docker.io for Docker Hub)
14-
REGISTRY: docker.io/narmidm
15-
IMAGE_NAME: k8s-pod-cpu-stressor
10+
# Use docker.io for Docker Hub if empty
11+
REGISTRY: docker.io
12+
# github.repository as <account>/<repo>
13+
IMAGE_NAME: ${{ github.repository }}
14+
1615

1716
jobs:
1817
build:
18+
1919
runs-on: ubuntu-latest
2020
permissions:
2121
contents: read
2222
packages: write
23+
# This is used to complete the identity challenge
24+
# with sigstore/fulcio when running outside of PRs.
2325
id-token: write
26+
2427
steps:
2528
- name: Checkout repository
2629
uses: actions/checkout@v4
2730

28-
# Install cosign tool, only run if it's not a pull request
31+
# Install the cosign tool except on PR
32+
# https://github.com/sigstore/cosign-installer
2933
- name: Install cosign
3034
if: github.event_name != 'pull_request'
31-
uses: sigstore/[email protected]
35+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
3236
with:
3337
cosign-release: 'v2.2.4'
3438

35-
# Set up Docker Buildx for multi-platform builds
39+
# Set up BuildKit Docker container builder to be able to build
40+
# multi-platform images and export cache
41+
# https://github.com/docker/setup-buildx-action
3642
- name: Set up Docker Buildx
37-
uses: docker/[email protected]
43+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
3844

39-
# Login to Docker Hub if not a pull request
40-
- name: Login to Docker Hub
45+
# Login against a Docker registry except on PR
46+
# https://github.com/docker/login-action
47+
- name: Log into registry ${{ env.REGISTRY }}
4148
if: github.event_name != 'pull_request'
42-
uses: docker/login-action@v3
49+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
4350
with:
44-
username: ${{ vars.DOCKERHUB_USERNAME }}
45-
password: ${{ secrets.DOCKERHUB_TOKEN }}
51+
registry: ${{ env.REGISTRY }}
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
4654

4755
# Extract metadata (tags, labels) for Docker
56+
# https://github.com/docker/metadata-action
4857
- name: Extract Docker metadata
4958
id: meta
50-
uses: docker/[email protected]
59+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
5160
with:
5261
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
53-
tags: latest
5462

55-
# Build and push Docker image, skip pushing on PRs
63+
# Build and push Docker image with Buildx (don't push on PR)
64+
# https://github.com/docker/build-push-action
5665
- name: Build and push Docker image
5766
id: build-and-push
58-
uses: docker/[email protected]
67+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
5968
with:
6069
context: .
6170
push: ${{ github.event_name != 'pull_request' }}
62-
tags: latest
71+
tags: ${{ steps.meta.outputs.tags }}
6372
labels: ${{ steps.meta.outputs.labels }}
6473
cache-from: type=gha
6574
cache-to: type=gha,mode=max
75+
76+
# Sign the resulting Docker image digest except on PRs.
77+
# This will only write to the public Rekor transparency log when the Docker
78+
# repository is public to avoid leaking data. If you would like to publish
79+
# transparency data even for private images, pass --force to cosign below.
80+
# https://github.com/sigstore/cosign
81+
# - name: Sign the published Docker image
82+
# if: ${{ github.event_name != 'pull_request' }}
83+
# env:
84+
# # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
85+
# TAGS: ${{ steps.meta.outputs.tags }}
86+
# DIGEST: ${{ steps.build-and-push.outputs.digest }}
87+
# # This step uses the identity token to provision an ephemeral certificate
88+
# # against the sigstore community Fulcio instance.
89+
# run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)