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

GitHub actions Docker Hub and combined publishing instructions don't work #36243

Open
1 task done
mmb opened this issue Feb 11, 2025 · 6 comments · May be fixed by #36263
Open
1 task done

GitHub actions Docker Hub and combined publishing instructions don't work #36243

mmb opened this issue Feb 11, 2025 · 6 comments · May be fixed by #36263
Labels
content This issue or pull request belongs to the Docs Content team more-information-needed More information is needed to complete review

Comments

@mmb
Copy link

mmb commented Feb 11, 2025

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images

What part(s) of the article would you like to see updated?

The "Publishing images to Docker Hub" YAML example fails at the attestation step because env.REGISTRY and env.IMAGE_NAME are not set.

The "Publishing images to Docker Hub and GitHub Packages" YAML has the same issue. I think this needs two attestation steps because it doesn't support multiple registries.

Additional information

No response

@mmb mmb added the content This issue or pull request belongs to the Docs Content team label Feb 11, 2025
Copy link

welcome bot commented Feb 11, 2025

Thanks for opening this issue. A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines.

@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Feb 11, 2025
@subatoi
Copy link
Contributor

subatoi commented Feb 11, 2025

Hi @mmb and thanks for raising an issue—

Can I ask: do you have access to GitHub Support with your plan? As this isn't a confirmed issue, that's the best place to start. Alternatively, you could raise a discussion.

Many thanks

@subatoi subatoi added more-information-needed More information is needed to complete review and removed triage Do not begin working on this issue until triaged by the team labels Feb 11, 2025
@mmb
Copy link
Author

mmb commented Feb 11, 2025

No I don't have access to GitHub Support. You mean the YAML example on the page works for you?

These are the two YAML examples I see on the page:

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Publish Docker image

on:
  release:
    types: [published]

jobs:
  push_to_registries:
    name: Push Docker image to multiple registries
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
      attestations: write
      id-token: write
    steps:
      - name: Check out the repo
        uses: actions/checkout@v4

      - name: Log in to Docker Hub
        uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Log in to the Container registry
        uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
        with:
          images: |
            my-docker-hub-namespace/my-docker-hub-repository
            ghcr.io/${{ github.repository }}

      - name: Build and push Docker images
        id: push
        uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

      - name: Generate artifact attestation
        uses: actions/attest-build-provenance@v2
        with:
          subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
          subject-digest: ${{ steps.push.outputs.digest }}
          push-to-registry: true

env.REGISTRY and env.IMAGE_NAME are not set anywhere so this example fails when it gets to the "Generate artifact attestation" step. I think these were copied from other documentation that set these environment variables.

The other one I mentioned is:

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Publish Docker image

on:
  release:
    types: [published]

jobs:
  push_to_registries:
    name: Push Docker image to multiple registries
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
      attestations: write
      id-token: write
    steps:
      - name: Check out the repo
        uses: actions/checkout@v4

      - name: Log in to Docker Hub
        uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Log in to the Container registry
        uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
        with:
          images: |
            my-docker-hub-namespace/my-docker-hub-repository
            ghcr.io/${{ github.repository }}

      - name: Build and push Docker images
        id: push
        uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

      - name: Generate artifact attestation
        uses: actions/attest-build-provenance@v2
        with:
          subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
          subject-digest: ${{ steps.push.outputs.digest }}
          push-to-registry: true

This has the same issue with the additional issue that the attest-build-provenance step can't create the build provenance for both Docker Hub and GitHub as far as I know.

verbeek45 added a commit to verbeek45/docs that referenced this issue Feb 11, 2025
@subatoi
Copy link
Contributor

subatoi commented Feb 11, 2025

Apologies—I understand where you're coming from now.

I'd suggest that we could make a small addition to the example, but we'd need to use placeholders:

env:
  REGISTRY: YOUR_REGISTRY
  IMAGE_NAME: YOUR_IMAGE_NAME

Does this sound sensible / would it make it clear enough? If so, I can open this up to either you or any contributor to submit a PR for.

verbeek45 added a commit to verbeek45/docs that referenced this issue Feb 11, 2025
@mmb
Copy link
Author

mmb commented Feb 11, 2025

Thanks Ben. I can open up a PR for it.

In addition to the env should I also add the additional build attestation step to push the build attestation for the second image?

mmb added a commit to mmb/docs that referenced this issue Feb 12, 2025
Instead of using env.REGISTRY and env.IMAGE_NAME, which are not set, use the
images in the metadata-action step.

Fixes github#36243
@subatoi
Copy link
Contributor

subatoi commented Feb 12, 2025

Many thanks for creating a PR—as I noted there, I'll get this double-checked for you internally

In addition to the env should I also add the additional build attestation step to push the build attestation for the second image?

I see you've done so, which is fine; the whole PR will be checked.

Many thanks again

@subatoi subatoi removed the more-information-needed More information is needed to complete review label Feb 12, 2025
@github github deleted a comment from qwer864cold Feb 13, 2025
@subatoi subatoi added the more-information-needed More information is needed to complete review label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content This issue or pull request belongs to the Docs Content team more-information-needed More information is needed to complete review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants