diff --git a/.github/workflows/docker-constructive.yaml b/.github/workflows/docker-constructive.yaml index da50aac79..efd7cb436 100644 --- a/.github/workflows/docker-constructive.yaml +++ b/.github/workflows/docker-constructive.yaml @@ -123,6 +123,7 @@ jobs: env: REPO: ghcr.io/${{ github.repository_owner }} IMAGE_NAME: constructive + DOCKERHUB_IMAGE: constructiveio/constructive steps: - name: Set up Docker Buildx @@ -135,6 +136,12 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Download digests uses: actions/download-artifact@v4 with: @@ -142,7 +149,7 @@ jobs: path: ${{ runner.temp }}/digests merge-multiple: true - - name: Extract metadata + - name: Extract metadata (GHCR) id: meta uses: docker/metadata-action@v5 with: @@ -155,7 +162,20 @@ jobs: type=sha,format=short,prefix= type=raw,value=latest,enable={{is_default_branch}} - - name: Create and push multi-arch manifests + - name: Extract metadata (Docker Hub) + id: meta-dockerhub + uses: docker/metadata-action@v5 + with: + images: docker.io/${{ env.DOCKERHUB_IMAGE }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,format=short,prefix= + type=raw,value=latest,enable={{is_default_branch}} + + - name: Create and push multi-arch manifests (GHCR) run: | set -euo pipefail @@ -178,12 +198,27 @@ jobs: exit 1 fi - echo "Creating manifests for tags:" + echo "Creating GHCR manifests for tags:" echo "${{ steps.meta.outputs.tags }}" - # metadata-action outputs tags as a newline-separated list echo "${{ steps.meta.outputs.tags }}" | while read -r tag; do [ -z "$tag" ] && continue echo "Creating multi-arch manifest for $tag" docker buildx imagetools create -t "$tag" $digests done + + - name: Copy multi-arch manifests to Docker Hub + if: github.ref == 'refs/heads/main' + run: | + set -euo pipefail + + ghcr_image="${{ env.REPO }}/${{ env.IMAGE_NAME }}" + + echo "Copying manifests to Docker Hub:" + echo "${{ steps.meta-dockerhub.outputs.tags }}" + + echo "${{ steps.meta-dockerhub.outputs.tags }}" | while read -r tag; do + [ -z "$tag" ] && continue + echo "Copying to $tag" + docker buildx imagetools create -t "$tag" "${ghcr_image}:latest" + done