Skip to content

Minimal example to publish an image with NodeJS SDK #4089

Closed

Description

@sengmann

What is the issue?

I am trying to publish a docker image to a local registry to evaluate dagger. After a few tries I can manage to export the container, but I am not able to publish.

The SDK guide should include an example of how to publish an image, rather than just showing how to export the build to the host system.

Steps I have done so far:

  1. run local registry with docker run -d -p 5000:5000 --restart=unless-stopped --name registry registry:2
  2. add "insecure-registries": ["http://localhost:5000"] to /etc/docker/daemon.json
  3. use dagger to publish to localhost:5000

The error message contains "authorization failed", so I trieddocker login localhost:5000. I can push images using docker push localhost:5000 without problems.

What am I doing wrong?

// build.ts
import Client, { connect } from "@dagger.io/dagger";
await connect(
  async (client: Client) => {
    await client.container().from("hello-world").export('./hello-world.tgz');  
    await client.container().from("hello-world").publish('localhost:5000');  
  },
  { LogOutput: process.stdout }
);
(node:44067) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
#1 resolve image config for docker.io/library/hello-world:latest
#1 DONE 2.0s

#2 docker-image://docker.io/library/hello-world:latest
#2 resolve docker.io/library/hello-world:latest
#2 resolve docker.io/library/hello-world:latest 0.2s done
#2 CACHED

#3 exporting to oci image format
#3 exporting layers done
#3 exporting manifest sha256:527f201ea8b5e93034cbbdd33e94d3e112fb52523ada07f3c9641dbfdb3fc228 0.0s done
#3 exporting config sha256:f5adce0eef760a932ed6bd40c1b4c021bcceac28d92f19fb13b17f8fe504e9f2
#3 exporting config sha256:f5adce0eef760a932ed6bd40c1b4c021bcceac28d92f19fb13b17f8fe504e9f2 0.0s done
#3 sending tarball done
#3 DONE 0.1s

#1 resolve image config for docker.io/library/hello-world:latest
#1 DONE 2.3s

#2 docker-image://docker.io/library/hello-world:latest
#2 resolve docker.io/library/hello-world:latest 0.2s done
#2 DONE 0.5s

#2 docker-image://docker.io/library/hello-world:latest
#2 CACHED

#4 exporting to image
#4 exporting layers done
#4 exporting manifest sha256:b0ae4cb23f8af327bf924d56b231a94580289f50c32393a8c276735798002dba 0.0s done
#4 exporting config sha256:f5adce0eef760a932ed6bd40c1b4c021bcceac28d92f19fb13b17f8fe504e9f2 done
#4 pushing layers
#4 pushing layers 1.0s done
#4 ERROR: server message: insufficient_scope: authorization failed
------
 > exporting to image:
------
/home/sengmann/Projekte/private/dagger-test/node_modules/graphql-request/dist/index.js:63
            op = body.call(thisArg, _);
                      ^
ClientError: failed to solve: server message: insufficient_scope: authorization failed: {"response":{"data":null,"errors":[{"message":"failed to solve: server message: insufficient_scope: authorization failed","locations":[{"line":7,"column":9}],"path":["container","from","publish"]}],"status":200,"headers":{}},"request":{"query":"\n      {\n        container  {\n      \n        from (address: \"hello-world\") {\n      \n        publish (address: \"localhost:5000\") }}\n      }\n    "}}
    at /home/sengmann/Projekte/private/dagger-test/node_modules/graphql-request/src/index.ts:497:11
    at step (/home/sengmann/Projekte/private/dagger-test/node_modules/graphql-request/dist/index.js:63:23)
    at Object.next (/home/sengmann/Projekte/private/dagger-test/node_modules/graphql-request/dist/index.js:44:53)
    at fulfilled (/home/sengmann/Projekte/private/dagger-test/node_modules/graphql-request/dist/index.js:35:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  response: {
    data: null,
    errors: [ [Object] ],
    status: 200,
    headers: Headers { [Symbol(map)]: [Object: null prototype] }
  },
  request: {
    query: '\n' +
      '      {\n' +
      '        container  {\n' +
      '      \n' +
      '        from (address: "hello-world") {\n' +
      '      \n' +
      '        publish (address: "localhost:5000") }}\n' +
      '      }\n' +
      '    ',
    variables: undefined
  }
}

Activity

  1. dolanor commented on Dec 6, 2022

    @dolanor
    Contributor

    There are a few problems in this report for me to reproduce.

    • You point your registry to localhost:5000. I would think you need to point to your real IP address, otherwise, it would point to the dagger container's localhost address instead.
    • Also, you just point to the registry, but you need the full image reference, as: xx.yy.zz.ww:5000/my/hello-world:latest for example.

    But then, you will probably hit: https://discord.com/channels/707636530424053791/1046817210695417906/1046817210695417906 which might be some error in buildkit (tracked here)

    One way to fix it for now would be to actually generate correct TLS certificate until we figure that out.

    So the fix for now:

    • use the full image reference
    • setup TLS on your internal registry to actually test it

    I tried on the Docker Hub, it worked:

    -    await client.container().from("hello-world").publish('localhost:5000');  
    +    await client.container().from("hello-world").publish('docker.io/dolanor/hello-world-dagger:latest');

    https://hub.docker.com/repository/docker/dolanor/hello-world-dagger

    $ node --loader ts-node/esm ./build.ts
    (node:2679166) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    #1 resolve image config for docker.io/library/hello-world:latest
    #1 DONE 0.7s
    
    #2 docker-image://docker.io/library/hello-world:latest
    #2 resolve docker.io/library/hello-world:latest
    #2 resolve docker.io/library/hello-world:latest 0.1s done
    #2 CACHED
    
    #3 exporting to oci image format
    #3 exporting layers done
    #3 exporting manifest sha256:ef576f1dfa31e87a492ae8281dc197ec08f37248ff3ca6f0f4ed4816877990fc 0.0s done
    #3 exporting config sha256:2d2af508fea34cdca680ecae2627df59f39c03bdb24939626c57b1ab682f472b done
    #3 sending tarball done
    #3 DONE 0.0s
    
    #1 resolve image config for docker.io/library/hello-world:latest
    #1 DONE 0.9s
    
    #2 docker-image://docker.io/library/hello-world:latest
    #2 resolve docker.io/library/hello-world:latest 0.1s done
    #2 DONE 0.3s
    
    #2 docker-image://docker.io/library/hello-world:latest
    #2 CACHED
    
    #4 exporting to image
    #4 exporting layers done
    #4 exporting manifest sha256:0548109fda3db5498bffeb80a48d31841d92cd4cb2b996cf4defdbd27c3cbb99 0.0s done
    #4 exporting config sha256:2d2af508fea34cdca680ecae2627df59f39c03bdb24939626c57b1ab682f472b done
    #4 pushing layers
    #4 pushing layers 1.2s done
    #4 pushing manifest for docker.io/dolanor/hello-world-dagger:latest@sha256:0548109fda3db5498bffeb80a48d31841d92cd4cb2b996cf4defdbd27c3cbb99
    #4 pushing manifest for docker.io/dolanor/hello-world-dagger:latest@sha256:0548109fda3db5498bffeb80a48d31841d92cd4cb2b996cf4defdbd27c3cbb99 0.3s done
    #4 DONE 1.5s
    
  2. sengmann commented on Dec 7, 2022

    @sengmann
    Author

    @dolanor Thanks for your feedback. I will try your suggestion. The documentation of the Container.publish method should be more specific about the address parameter.

  3. dolanor commented on Dec 12, 2022

    @dolanor
    Contributor

    I totally agree with you, we're gonna fix it very soon.

  4. sengmann commented on Dec 13, 2022

    @sengmann
    Author

    @dolanor With the help of your example I was able to fix the problem. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions