Skip to content

Commit b7179e2

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 <[email protected]>
1 parent a65c043 commit b7179e2

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

.github/workflows/release.yml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ jobs:
4747
TARGET: ${{ matrix.publish_target }}
4848
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4949

50-
# Publish to docker registries docker.io and ghcr.io
50+
# Publish to Docker registries: docker.io and ghcr.io
5151
publishdocker:
52-
strategy:
53-
fail-fast: false
54-
matrix:
55-
DOCKER_REGISTRY:
56-
- 'docker.io'
57-
- 'ghcr.io'
5852
runs-on: ubuntu-latest
5953
needs: test
6054
permissions:
@@ -78,28 +72,42 @@ jobs:
7872
buildkitd-config-inline: |
7973
[worker.oci]
8074
max-parallelism = 1
81-
- name: Login to the ${{ matrix.DOCKER_REGISTRY }} Container Registry
75+
- name: Login to Docker Hub
76+
# If testing on a fork, login error may occur and can be ignored
77+
continue-on-error: true
8278
uses: docker/login-action@v3
8379
with:
84-
registry: ${{ matrix.DOCKER_REGISTRY }}
85-
username: ${{ matrix.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
86-
password: ${{ matrix.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
80+
username: ${{ secrets.DOCKERHUB_USERNAME }}
81+
password: ${{ secrets.DOCKERHUB_TOKEN }}
82+
- name: Login to GitHub Container Registry
83+
uses: docker/login-action@v3
84+
with:
85+
registry: ghcr.io
86+
username: ${{ github.repository_owner }}
87+
password: ${{ secrets.GITHUB_TOKEN }}
8788
- name: Docker meta
8889
id: meta
8990
uses: docker/metadata-action@v5
9091
with:
91-
images: ${{ matrix.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-javaenv
92+
# If testing on a fork, Docker Hub publish might fail so place it last
93+
images: |
94+
ghcr.io/${{ github.repository_owner }}/fabric-javaenv
95+
docker.io/${{ github.repository_owner }}/fabric-javaenv
9296
tags: |
9397
type=semver,pattern={{version}}
9498
type=semver,pattern={{major}}.{{minor}}
9599
type=semver,pattern={{major}}.{{minor}}.{{patch}}
100+
- name: Get Git commit timestamps
101+
run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
96102
- name: Build and push image
97103
id: push
98-
uses: docker/build-push-action@v5
104+
uses: docker/build-push-action@v6
99105
with:
100106
platforms: linux/amd64,linux/arm64
101107
file: fabric-chaincode-docker/Dockerfile
102108
context: fabric-chaincode-docker
103109
tags: ${{ steps.meta.outputs.tags }}
104110
push: ${{ github.event_name != 'pull_request' }}
105111
labels: ${{ steps.meta.outputs.labels }}
112+
env:
113+
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}

0 commit comments

Comments
 (0)