[FAQ] GHCR push returns denied in GitHub Actions even with packages: write

Aperta Adatta ai principianti
#550 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
86/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, github-actions

Direzione di ricerca

Leggi la voce delle FAQ nel repository e confronta i passaggi per la risoluzione dei problemi e l’esempio di nuovo tentativo con il .github/workflows/cd.yml collegato. Verifica che la formulazione distingua il fallimento osservato al primo push dalle cause abituali legate alle autorizzazioni e ai nomi; il lavoro è completato quando la risposta è chiara e l’esempio rimanda al workflow funzionante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Course

ai-dev-tools-zoomcamp

Question

Final project CI/CD: my GitHub Actions workflow gets denied when pushing a new image to GHCR, even though it has packages: write and docker login succeeds. How do I fix it?

Answer

Re-run the job, and add a retry to the push. In my project the first push of each brand-new package failed, and the same push succeeded on the re-run, with no change to the workflow.

What the log looked like. The layers upload, then the push fails:

ae51df8ce05a: Pushed
error from registry: denied
denied

I had two images, and each one failed once. The first run failed on the API image. The re-run published it and then failed on the frontend image. The third run published both. Later pushes to the same packages had no problem.

Before assuming that's your issue, check the usual causes of denied:

  1. The workflow or job has permissions: packages: write. The default token may be read-only.
  2. The image name uses your own lowercase owner: ghcr.io/<owner>/<name>.
  3. docker/login-action uses password: ${{ secrets.GITHUB_TOKEN }}, and the log shows Login Succeeded!.

If all three are fine and the package doesn't exist yet, retry so a fresh setup doesn't need a manual re-run:

for attempt in 1 2 3; do
  docker push --all-tags "$repository" && break
  [ "$attempt" = 3 ] && exit 1
  sleep 15
done

I don't know the exact cause on GitHub's side. This is what I observed, on a public repository with a user-owned package.

Working example: https://github.com/devotuoma/chamaledger/blob/main/.github/workflows/cd.yml

Checklist
  • I have searched existing FAQs and this question is not already answered
  • The answer provides accurate, helpful information
  • I have included any relevant code examples or links
Lingua principale
Python
Stelle
8
Fork
20
Merge medio
3g 14h
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DataTalksClub/faq

Tutte le issue di DataTalksClub/faq

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.