#How to authenticate to remote repository when pushing docker image with Python SDK

1 messages · Page 1 of 1 (latest)

stiff forum
#

I was experimenting with converting my existing dagger.cue files to build.py using the new Python SDK and gotten everything working accept that I can't find a way to specify username/password when calling Container.publish()

Relevant cue:

push: {
  let _rev = strings.TrimSpace(client.commands.git_rev.stdout)
  let _push = docker.#Push & {
    image: actions.build.output
    auth: {
      username: client.env.GITHUB_USER
      secret:   client.env.GITHUB_TOKEN
    }
  }

  latest: _push & {dest: "\(params.image):latest"}
  rev:    _push & {dest: "\(params.image):\(_rev)"}
}

How to do the auth: thing when doing Container.publish() in python? Or I'm I just using the wrong command altogether? 😅 This is my entire build.py script:

import anyio
import dagger
import sys

IMAGE = "xxx/yyy"

config = dagger.Config(log_output=sys.stderr)

async def build():
    async with dagger.Connection(config) as conn:
        container = conn.host().directory(".").docker_build(platform="linux/amd64")
        await container.publish(f"ghcr.io/{IMAGE}:latest")

if __name__ == "__main__":
    anyio.run(build)

Running it gives a failed to solve: failed to fetch anonymous token: unexpected status: 403 Forbidden on the container.publish line.

vivid echo
stiff forum
#

ahhhh ok thanks @vivid echo i was looking in the python sdk section and didn't see there's a faq on the bottom

subtle jay
#

is it good for you now, @stiff forum ?