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

Upload failed on ghcr.io, no details #177

Closed
bokub opened this issue Aug 30, 2023 · 5 comments · Fixed by home-assistant/addons-example#85
Closed

Upload failed on ghcr.io, no details #177

bokub opened this issue Aug 30, 2023 · 5 comments · Fixed by home-assistant/addons-example#85

Comments

@bokub
Copy link

bokub commented Aug 30, 2023

Hello,

I'm currently trying to use this repo as a GitHub Action, here is my workflow:

  publish:
    name: Build and publish Docker image
    runs-on: ubuntu-latest
    needs:
      - lint
      - test
    steps:
      - uses: actions/checkout@v3
      - uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: bokub
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: home-assistant/builder@master
        with:
          args: |
            --all \
            --target . \
            --docker-hub ghcr.io/bokub

Whenever the Action runs, the login step succeeds, then the build step fails with the following output:

[10:43:47] INFO: Finish build for ghcr.io/bokub/my-addon-i386:0.1.0
[10:43:47] INFO: Create image tag: latest
[10:43:47] INFO: Start upload of ghcr.io/bokub/my-addon-i386:0.1.0 (attempt #1/3)
[10:43:47] WARNING: Upload failed on attempt #1
[10:43:47] WARNING: Upload failed on attempt #1
[10:44:17] INFO: Start upload of ghcr.io/bokub/my-addon-amd64:0.1.0 (attempt #2/3)
[10:44:17] WARNING: Upload failed on attempt #2
[10:44:17] INFO: Start upload of ghcr.io/bokub/my-addon-i386:0.1.0 (attempt #2/3)
[10:44:18] WARNING: Upload failed on attempt #2
[10:44:47] INFO: Start upload of ghcr.io/bokub/my-addon-amd64:0.1.0 (attempt #3/3)
[10:44:48] FATAL: Upload failed on attempt #3
[10:44:48] INFO: Start upload of ghcr.io/bokub/my-addon-i386:0.1.0 (attempt #3/3)
[10:44:48] FATAL: Upload failed on attempt #3
...

Did I do something wrong?
Is there any way to display the upload error? ("Upload failed" is not enough to understand what went wrong)

Thanks!

@bokub
Copy link
Author

bokub commented Aug 30, 2023

Looks like the default GITHUB_TOKEN doesn't have enough rights.

I had to create a Personal Access Token and use it to publish Docker images...

Hope it will help someone someday!

@bokub bokub closed this as completed Aug 30, 2023
@klaernie
Copy link

The default GITHUB_TOKEN works, if you link the repository doing the build to the package and grant the actions running the repository write access. I'm doing exactly this in https://github.com/klaernie/hassio-addons/blob/main/.github/workflows/ci.yml
The only sad part is, that you cannot create a package in Github without pushing an image, and without granting access you cannot write from Github actions. I solved that catch-22 by manually pushing an image, sorting the permissions out and then running my Github actions.

@Erudition
Copy link

Erudition commented Mar 7, 2024

Uh oh! This needs to be re-opened. I built an addon with the starter template, and I'm running into the same issue. Not only does the error message still need to be clarified, but it would be nice to have some documentation on how to use @klaernie 's workaround or something.

Erudition added a commit to Erudition/home-assistant-addons that referenced this issue Mar 7, 2024
@Erudition
Copy link

Erudition commented Mar 7, 2024

According to this the linking is done automatically:

https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#pushing-container-images

However it "recommends" adding this to the Dockerfile for that:
LABEL org.opencontainers.image.source=https://github.com/you/repo-here

but... that didn't do the trick.

Then I noticed here that this needs to be added to the job:

    permissions:
      contents: read
      packages: write

BAM! now it works! Despite having never published a package, it uploaded just fine using only GITHUB_TOKEN. Hope that helps you @bokub as well.

@Erudition
Copy link

Created a PR for the fixes.
home-assistant/addons-example#85

Note that this issue still applies, the error message does not indicate what went wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants