diff --git a/.github/workflows/publish-ghcr-image.yml b/.github/workflows/publish-ghcr-image.yml index 804740af..da8de388 100644 --- a/.github/workflows/publish-ghcr-image.yml +++ b/.github/workflows/publish-ghcr-image.yml @@ -1,4 +1,4 @@ -name: Build & Publish GHCR Image +name: Build & Publish Release Image on: push: @@ -17,7 +17,10 @@ concurrency: env: versionTag: ${{ inputs.version || github.ref_name }} - registry: ghcr.io + ghcrRegistry: ghcr.io + dockerHubRegistry: docker.io + imageName: ${{ github.repository }} + dockerHubImage: vechain/block-explorer jobs: build: @@ -50,7 +53,7 @@ jobs: - name: Login to GHCR uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 with: - registry: ${{ env.registry }} + registry: ${{ env.ghcrRegistry }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} @@ -67,7 +70,7 @@ jobs: sbom: false cache-from: type=gha,scope=buildkit-${{ matrix.arch }} cache-to: type=gha,mode=max,scope=buildkit-${{ matrix.arch }} - outputs: type=image,name=${{ env.registry }}/${{ github.repository }},push-by-digest=true,name-canonical=true,push=true + outputs: type=image,name=${{ env.ghcrRegistry }}/${{ env.imageName }},push-by-digest=true,name-canonical=true,push=true - name: Export digest run: | @@ -104,10 +107,17 @@ jobs: - name: Login to GHCR uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 with: - registry: ${{ env.registry }} + registry: ${{ env.ghcrRegistry }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Login to Docker Hub + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 + with: + registry: ${{ env.dockerHubRegistry }} + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract version tags id: version run: | @@ -124,24 +134,50 @@ jobs: echo "stable=false" >> "$GITHUB_OUTPUT" fi - - name: Create manifest list and push + - name: Create GHCR manifest list working-directory: /tmp/digests env: - IMAGE: ${{ env.registry }}/${{ github.repository }} + GHCR_IMAGE: ${{ env.ghcrRegistry }}/${{ env.imageName }} + FULL_VERSION: ${{ steps.version.outputs.full }} + STABLE: ${{ steps.version.outputs.stable }} + MAJOR: ${{ steps.version.outputs.major }} + MINOR: ${{ steps.version.outputs.minor }} run: | - TAGS="-t ${{ env.IMAGE }}:${{ steps.version.outputs.full }}" + set -euo pipefail - if [ "${{ steps.version.outputs.stable }}" = "true" ]; then - TAGS="$TAGS -t ${{ env.IMAGE }}:${{ steps.version.outputs.minor }}" - TAGS="$TAGS -t ${{ env.IMAGE }}:${{ steps.version.outputs.major }}" - TAGS="$TAGS -t ${{ env.IMAGE }}:latest" + tags=("-t" "${GHCR_IMAGE}:${FULL_VERSION}") + if [ "${STABLE}" = "true" ]; then + tags+=("-t" "${GHCR_IMAGE}:${MINOR}") + tags+=("-t" "${GHCR_IMAGE}:${MAJOR}") + tags+=("-t" "${GHCR_IMAGE}:latest") fi - IMAGE_REFS=() + refs=() for digest in *; do - IMAGE_REFS+=("${IMAGE}@sha256:${digest}") + refs+=("${GHCR_IMAGE}@sha256:${digest}") done - docker buildx imagetools create \ - $TAGS \ - "${IMAGE_REFS[@]}" + docker buildx imagetools create "${tags[@]}" "${refs[@]}" + + - name: Mirror manifest from GHCR to Docker Hub + env: + GHCR_IMAGE: ${{ env.ghcrRegistry }}/${{ env.imageName }} + DOCKERHUB_IMAGE: ${{ env.dockerHubRegistry }}/${{ env.dockerHubImage }} + FULL_VERSION: ${{ steps.version.outputs.full }} + STABLE: ${{ steps.version.outputs.stable }} + MAJOR: ${{ steps.version.outputs.major }} + MINOR: ${{ steps.version.outputs.minor }} + run: | + set -euo pipefail + + copy_tag() { + local tag="$1" + docker buildx imagetools create -t "${DOCKERHUB_IMAGE}:${tag}" "${GHCR_IMAGE}:${tag}" + } + + copy_tag "${FULL_VERSION}" + if [ "${STABLE}" = "true" ]; then + copy_tag "${MINOR}" + copy_tag "${MAJOR}" + copy_tag "latest" + fi