Skip to content

Commit

Permalink
HDDS-11634. Publish images to Docker Hub from GitHub workflow (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai authored Nov 8, 2024
1 parent 445b14f commit c36597a
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions .github/workflows/build-and-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@ jobs:
if: ${{ github.ref_type == 'tag' }}
runs-on: ubuntu-latest
env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
IMAGE_ID: ${{ needs.build.outputs.image-id }}
REGISTRIES: ghcr.io # docker.io is appended dynamically
steps:
- name: Generate tags
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |
ghcr.io/${{ github.repository_owner }}/ozone-runner
${{ github.repository_owner }}/ozone-runner
tags: |
type=ref,event=tag
flavor: |
latest=false
- name: Add Docker Hub to targets
if: ${{ env.DOCKERHUB_USER }}
run: |
echo "REGISTRIES=${{ env.REGISTRIES }} docker.io" >> $GITHUB_ENV
- name: Pull image
run: |
docker pull "$IMAGE_ID"
Expand All @@ -56,9 +63,19 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
if: ${{ env.DOCKERHUB_USER }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
username: ${{ env.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Apply tags to existing image
run: |
for tag in $DOCKER_METADATA_OUTPUT_TAGS; do
docker tag "$IMAGE_ID" "$tag"
docker push "$tag"
set -x
for registry in $REGISTRIES; do
opts="$(echo "$DOCKER_METADATA_OUTPUT_TAGS" | sed "s@^@--tag $registry/@g" | xargs echo)"
if [[ -n "$opts" ]]; then
docker buildx imagetools create $opts "$IMAGE_ID"
fi
done

0 comments on commit c36597a

Please sign in to comment.