#Publishing isn't working

1 messages · Page 1 of 1 (latest)

haughty pulsar
#

This is my TypeScript function.

  @func()
  async publish(
    repository: string,
    tag: string = 'latest',
    src: Directory,
    username: string,
    password: string
  ): Promise<string> {
    // currently we only use docker.io 
    // TODO: need to make this dynamic at some point
    const registry: string = 'docker.io'
    // Build container image first
    const container: Container = await this.build(src) 
    
    if (!container) {
      throw new Error("No container built. See error messages and use build to fix any issues.");
    }

    const dagPassword = dag.setSecret("DOCKERHUB_PASSWORD", password)

    // Login to DockerHub
    container
      .withRegistryAuth(
        registry,
        username,
        dagPassword
      );

    // Publish the container
    return await container.publish(`${registry}/${repository}:${tag}`)
  }
#

And I'm getting this error:

Error: failed to export: failed to push docker.io/m8aio/test2:0.0.1: push access denied, repository does not exist or
may require authorization: server message: insufficient_scope: authorization failed: {"response":{"data":null,"errors"
:[{"message":"failed to export: failed to push docker.io/m8aio/test2:0.0.1: push access denied, repository does not ex
ist or may require authorization: server message: insufficient_scope: authorization failed","path":["blob","directory"
,"dockerBuild","publish"]}],"status":200,"headers":{}},"request":{"query":"\n      { loadContainerFromID (id: \"ChV4eG
gzOmM4ODI5MDJhNWVmM2Q1NTYSgAEKFXh4aDM6MzdiYzk4ZWNlM2NjZTA3ZRJnChV4eGgzOmU1MWVkM2ViYjQ3OGE5MDMSDQoJRGlyZWN0b3J5GAEaCWRp
cmVjdG9yeSIdCgRwYXRoEhU6Ey8ubThhL2NpLWNvZGluZy1lbnZKFXh4aDM6MzdiYzk4ZWNlM2NjZTA3ZRJjChV4eGgzOmM4ODI5MDJhNWVmM2Q1NTYSSg
oVeHhoMzozN2JjOThlY2UzY2NlMDdlEg0KCUNvbnRhaW5lchgBGgtkb2NrZXJCdWlsZEoVeHhoMzpjODgyOTAyYTVlZjNkNTU2EpsBChV4eGgzOmU1MWVk
M2ViYjQ3OGE5MDMSgQESDQoJRGlyZWN0b3J5GAEaBGJsb2IiUwoGZGlnZXN0Ekk6R3NoYTI1NjpmNjQ2NmQ3MjQwZDk1MmFjOGJmZjgzMjZlMDMxYWYzYW
ExODljYzY1ODc1MmQyNTFlZWY5NjY1MDQ0N2ExYmZkShV4eGgzOmU1MWVkM2ViYjQ3OGE5MDM=\") { publish (address: \"docker.io/m8aio/te
st2:0.0.1\") } }\n    "}}
Error: failed to export: failed to push docker.io/m8aio/test2:0.0.1: push access denied, repository does not exist or
may require authorization: server message: insufficient_scope: authorization failed
! process "tsx --no-deprecation --tsconfig /src/dagger/tsconfig.json /src/dagger/src/__dagger.entrypoint.ts" did not complete successfully: exit code: 1
#

I could successfully push the image locally with Docker and the same credentials, so it's not any of the issues noted above as a possible problem.

What else might I be doing wrong?

buoyant grove
#

@haughty pulsar are you running this in your local machine? If that's the case can you try removing the withRegistryAuth? Dagger should use your local config.json and get the credentials from there

haughty pulsar
#

I say runner. It's a pod I'm doing remote development in.

buoyant grove
haughty pulsar
#

I didn't try it locally. I don't have Dagger installed. 🙂

buoyant grove
#

Oh!! I see the error now

#

@haughty pulsar chainable functions don't mutate the underlying object. They return the modified object with the new properties

#

So when you're doing withRegistryAuth, you're not re-assigning the return of that call to the original container variable

#

Which you'll have to change from const to variable