Skip to content

Commit 4aa884a

Browse files
Push identical image to all Docker registries
The current GitHub Actions workflow builds and pushes separate Docker images for each registry. This results in the images published to each registry having a different hash, despite having the same version tag. This change modifies the Docker publishing job in the release workflow so that a single step builds and publishes the same Docker image to all Docker registries. For reproducability, the timestamp of the image is also set to the last commit timestamp. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
1 parent 0ebbe15 commit 4aa884a

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

.github/workflows/release.yaml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ jobs:
3939
permissions:
4040
contents: read
4141
packages: write
42-
strategy:
43-
fail-fast: false
44-
matrix:
45-
DOCKER_REGISTRY:
46-
- "docker.io"
47-
- "ghcr.io"
4842
steps:
4943
- name: Set up QEMU
5044
uses: docker/setup-qemu-action@v3
@@ -57,28 +51,42 @@ jobs:
5751
max-parallelism = 1
5852
- name: Checkout
5953
uses: actions/checkout@v4
60-
- name: Login to the ${{ matrix.DOCKER_REGISTRY }} Container Registry
54+
- name: Login to Docker Hub
55+
# If testing on a fork, login error may occur and can be ignored
56+
continue-on-error: true
6157
uses: docker/login-action@v3
6258
with:
63-
registry: ${{ matrix.DOCKER_REGISTRY }}
64-
username: ${{ matrix.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
65-
password: ${{ matrix.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
59+
username: ${{ secrets.DOCKERHUB_USERNAME }}
60+
password: ${{ secrets.DOCKERHUB_TOKEN }}
61+
- name: Login to GitHub Container Registry
62+
uses: docker/login-action@v3
63+
with:
64+
registry: ghcr.io
65+
username: ${{ github.repository_owner }}
66+
password: ${{ secrets.GITHUB_TOKEN }}
6667
- name: Docker meta
6768
id: meta
6869
uses: docker/metadata-action@v5
6970
with:
70-
images: ${{ matrix.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-nodeenv
71+
# If testing on a fork, Docker Hub publish might fail so place it last
72+
images: |
73+
ghcr.io/${{ github.repository_owner }}/fabric-nodeenv
74+
${{ github.repository_owner }}/fabric-nodeenv
7175
tags: |
7276
type=semver,pattern={{version}}
7377
type=semver,pattern={{major}}.{{minor}}
7478
type=semver,pattern={{major}}.{{minor}}.{{patch}}
79+
- name: Get Git commit timestamps
80+
run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
7581
- name: Build and push image
7682
id: push
77-
uses: docker/build-push-action@v5
83+
uses: docker/build-push-action@v6
7884
with:
7985
platforms: linux/amd64,linux/arm64
8086
file: docker/fabric-nodeenv/Dockerfile
8187
context: docker/fabric-nodeenv
8288
tags: ${{ steps.meta.outputs.tags }}
8389
push: ${{ github.event_name != 'pull_request' }}
8490
labels: ${{ steps.meta.outputs.labels }}
91+
env:
92+
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}

0 commit comments

Comments
 (0)