Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11634. Publish images to Docker Hub from GitHub workflow #33

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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