-
Notifications
You must be signed in to change notification settings - Fork 60.9k
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
Comments
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. |
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 |
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. |
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:
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. |
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? |
Instead of using env.REGISTRY and env.IMAGE_NAME, which are not set, use the images in the metadata-action step. Fixes github#36243
Many thanks for creating a PR—as I noted there, I'll get this double-checked for you internally
I see you've done so, which is fine; the whole PR will be checked. Many thanks again |
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
andenv.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
The text was updated successfully, but these errors were encountered: