I have failed to get my apko Dagger module to successfully publish to ghcr.io. I have created a PAT token for experimenting, and I can successfully log into ghcr.io and publish using apko directly.
However, I always get an authentication failure when I run this within my Dagger module.
Code snippet:
ctr := dag.Container().From("cgr.dev/chainguard/apko")
if registry != "" && username != "" && password != nil {
ctr = ctr.WithSecretVariable("REGISTRY_TOKEN", password).
WithExec([]string{"login", registry, "-u", username, "-p", "$REGISTRY_TOKEN"})
}
return ctr.
WithWorkdir("apko").
WithFile("apko.yaml", a.Cfg).
WithExec(cmd).
Stdout(ctx)
ℹ️ | publishing index tag ghcr.io/purpleclay/dagger-cli:0.10.3
Error: publishing image index: failed to publish: PUT https://ghcr.io/v2/purpleclay/dagger-cli/manifests/0.10.3: UNAUTHORIZED: unauthenticated: User cannot be authenticated with the token provided.
I currently pass in the registry details as parameters, with the password being a secret:
dagger call -m github.com/purpleclay/daggerverse/apko@v0.3.0 load --cfg apko.yaml publish --ref "ghcr.io/purpleclay/dagger-cli:0.10.3" --registry ghcr.io --username purpleclay --password env:GHCR_TOKEN
The issue appears with the WithExec command not picking up the environment variable. It feels like it is using the string $REGISTRY_TOKEN as a Raw value. Should I be wrapping this up as a script?