Skip to content

Commit 2e2b07f

Browse files
committed
build: make DockerHub login and push non-fatal in docker workflow
Allow the docker workflow to succeed even when DockerHub credentials are unavailable (e.g. for forks), while keeping ghcr.io path strict.
1 parent e8a8df1 commit 2e2b07f

1 file changed

Lines changed: 44 additions & 14 deletions

File tree

.github/workflows/docker.yml

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
password: ${{ secrets.PKG_TOKEN }}
4949

5050
- name: login to DockerHub
51+
continue-on-error: true
5152
uses: docker/login-action@v4
5253
with:
5354
username: ${{ github.actor }}
@@ -67,6 +68,7 @@ jobs:
6768

6869
- name: build and push to DockerHub by digest
6970
id: build-dockerhub
71+
continue-on-error: true
7072
uses: docker/build-push-action@v7
7173
with:
7274
context: .
@@ -77,13 +79,19 @@ jobs:
7779
GIT_BRANCH=${{ github.event.workflow_run.head_branch }}
7880
outputs: type=image,name=umputun/ukeeper-readability,push-by-digest=true,name-canonical=true,push=true
7981

80-
- name: export digests
82+
- name: export ghcr digest
8183
env:
8284
DIGEST_GHCR: ${{ steps.build-ghcr.outputs.digest }}
83-
DIGEST_DOCKERHUB: ${{ steps.build-dockerhub.outputs.digest }}
8485
run: |
85-
mkdir -p /tmp/digests/ghcr /tmp/digests/dockerhub
86+
mkdir -p /tmp/digests/ghcr
8687
touch "/tmp/digests/ghcr/${DIGEST_GHCR#sha256:}"
88+
89+
- name: export dockerhub digest
90+
if: steps.build-dockerhub.outcome == 'success'
91+
env:
92+
DIGEST_DOCKERHUB: ${{ steps.build-dockerhub.outputs.digest }}
93+
run: |
94+
mkdir -p /tmp/digests/dockerhub
8795
touch "/tmp/digests/dockerhub/${DIGEST_DOCKERHUB#sha256:}"
8896
8997
- name: upload ghcr digest
@@ -94,6 +102,7 @@ jobs:
94102
retention-days: 1
95103

96104
- name: upload dockerhub digest
105+
if: steps.build-dockerhub.outcome == 'success'
97106
uses: actions/upload-artifact@v7
98107
with:
99108
name: digests-dockerhub-${{ matrix.artifact }}
@@ -116,24 +125,41 @@ jobs:
116125
merge-multiple: true
117126

118127
- name: download dockerhub digests
128+
id: download-dockerhub
129+
continue-on-error: true
119130
uses: actions/download-artifact@v8
120131
with:
121132
path: /tmp/digests/dockerhub
122133
pattern: digests-dockerhub-*
123134
merge-multiple: true
124135

125-
- name: verify all digests present
136+
- name: verify ghcr digests present
126137
run: |
127-
for registry in ghcr dockerhub; do
128-
expected=2
129-
actual=$(find /tmp/digests/$registry -maxdepth 1 -type f | wc -l)
130-
if [ "$actual" -ne "$expected" ]; then
131-
echo "Expected $expected digests for $registry, found $actual"
132-
ls -la /tmp/digests/$registry
133-
exit 1
134-
fi
135-
done
136-
echo "All digests present"
138+
expected=2
139+
actual=$(find /tmp/digests/ghcr -maxdepth 1 -type f | wc -l)
140+
if [ "$actual" -ne "$expected" ]; then
141+
echo "Expected $expected digests for ghcr, found $actual"
142+
ls -la /tmp/digests/ghcr
143+
exit 1
144+
fi
145+
echo "All ghcr digests present"
146+
147+
- name: verify dockerhub digests present
148+
id: verify-dockerhub
149+
continue-on-error: true
150+
run: |
151+
if [ ! -d /tmp/digests/dockerhub ]; then
152+
echo "No dockerhub digests directory, skipping"
153+
exit 1
154+
fi
155+
expected=2
156+
actual=$(find /tmp/digests/dockerhub -maxdepth 1 -type f | wc -l)
157+
if [ "$actual" -ne "$expected" ]; then
158+
echo "Expected $expected digests for dockerhub, found $actual"
159+
ls -la /tmp/digests/dockerhub
160+
exit 1
161+
fi
162+
echo "All dockerhub digests present"
137163
138164
- name: set up Docker Buildx
139165
uses: docker/setup-buildx-action@v4
@@ -146,6 +172,8 @@ jobs:
146172
password: ${{ secrets.PKG_TOKEN }}
147173

148174
- name: login to DockerHub
175+
if: steps.verify-dockerhub.outcome == 'success'
176+
continue-on-error: true
149177
uses: docker/login-action@v4
150178
with:
151179
username: ${{ github.actor }}
@@ -178,6 +206,8 @@ jobs:
178206
$(printf 'ghcr.io/ukeeper/ukeeper-readability@sha256:%s ' *)
179207
180208
- name: create DockerHub manifest and push
209+
if: steps.verify-dockerhub.outcome == 'success'
210+
continue-on-error: true
181211
working-directory: /tmp/digests/dockerhub
182212
env:
183213
REF: ${{ steps.tags.outputs.ref }}

0 commit comments

Comments
 (0)