Skip to content

Commit c36597a

Browse files
authored
HDDS-11634. Publish images to Docker Hub from GitHub workflow (#33)
1 parent 445b14f commit c36597a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

Diff for: .github/workflows/build-and-tag.yaml

+21-4
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,25 @@ jobs:
3333
if: ${{ github.ref_type == 'tag' }}
3434
runs-on: ubuntu-latest
3535
env:
36+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
3637
IMAGE_ID: ${{ needs.build.outputs.image-id }}
38+
REGISTRIES: ghcr.io # docker.io is appended dynamically
3739
steps:
3840
- name: Generate tags
3941
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
4042
with:
4143
images: |
42-
ghcr.io/${{ github.repository_owner }}/ozone-runner
44+
${{ github.repository_owner }}/ozone-runner
4345
tags: |
4446
type=ref,event=tag
4547
flavor: |
4648
latest=false
4749
50+
- name: Add Docker Hub to targets
51+
if: ${{ env.DOCKERHUB_USER }}
52+
run: |
53+
echo "REGISTRIES=${{ env.REGISTRIES }} docker.io" >> $GITHUB_ENV
54+
4855
- name: Pull image
4956
run: |
5057
docker pull "$IMAGE_ID"
@@ -56,9 +63,19 @@ jobs:
5663
username: ${{ github.repository_owner }}
5764
password: ${{ secrets.GITHUB_TOKEN }}
5865

66+
- name: Login to Docker Hub
67+
if: ${{ env.DOCKERHUB_USER }}
68+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
69+
with:
70+
username: ${{ env.DOCKERHUB_USER }}
71+
password: ${{ secrets.DOCKERHUB_TOKEN }}
72+
5973
- name: Apply tags to existing image
6074
run: |
61-
for tag in $DOCKER_METADATA_OUTPUT_TAGS; do
62-
docker tag "$IMAGE_ID" "$tag"
63-
docker push "$tag"
75+
set -x
76+
for registry in $REGISTRIES; do
77+
opts="$(echo "$DOCKER_METADATA_OUTPUT_TAGS" | sed "s@^@--tag $registry/@g" | xargs echo)"
78+
if [[ -n "$opts" ]]; then
79+
docker buildx imagetools create $opts "$IMAGE_ID"
80+
fi
6481
done

0 commit comments

Comments
 (0)