#Help! Dagger CMD Not Working as Expected

1 messages · Page 1 of 1 (latest)

still mirage
#

I have a working Dockerfile (as given below). I'm attempting to create a Dagger function with the same functionality (as given below). While the Dockerfile runs my Deno script correctly, the Dagger function fails to execute it. I believe the issue is with how I'm handling the CMD instruction in Dagger. Could you help me correct my Dagger function?

dockerfile

# Use the linuxserver/chromium image as the base image
FROM linuxserver/chromium:latest

# Set the working directory
WORKDIR /test

# Copy the local directory into the container
COPY ./test /test

# Update the package list
RUN apt-get update

# Install curl and unzip
RUN apt-get install -y curl unzip

# Install Deno
RUN sh -c "curl -fsSL https://deno.land/x/install/install.sh | sh"

# Set environment variables
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV DENO_INSTALL=/config/.deno
# Run the Deno script
CMD [ "sh", "-c", "/config/.deno/bin/deno run --allow-read --allow-env --allow-write --allow-run --allow-net --allow-sys /test/index.ts" ]

dag function

dag
      .container()
      .from("linuxserver/chromium:latest")
      .withDirectory("/test", source)
      .withWorkdir("/test")
      .withExec([
        "apt-get",
        "update",
      ])
      .withExec([
        "apt-get",
        "install",
        "curl",
        "unzip",
        "-y",
      ])
      .withExec([
        "sh",
        "-c",
        "curl -fsSL https://deno.land/x/install/install.sh | sh",
      ]).withEnvVariable("PUPPETEER_SKIP_CHROMIUM_DOWNLOAD", "true")
      .withEnvVariable("DENO_INSTALL", "/config/.deno")
      .withDefaultArgs([
        "/config/.deno/bin/deno",
        "run",
        "--allow-read",
        "--allow-env",
        "--allow-write",
        "--allow-run",
        "--allow-net",
        "--allow-sys",
        "/test/index.ts"
      ])
clever sonnet
still mirage
clever sonnet
#

I see your Dockerifle has a sh -c which your withDefaultArgs doesn't have

#

so seems like you forgotten to add that to your withDefaultArgs

still mirage
still mirage
clever sonnet
still mirage
#

ok will share dagger cloud trace...soon...

still mirage
zealous yarrow
#

you can share the cloud trace URL which is printed at the end of dagger call execution

still mirage
#

Nothing is coming inside this command. Script which we are runing using deno run should generate one screenshot. So we tried to attach terminal and check if screenshot is generated or not but it not generated.

still mirage
clever sonnet
#

the Dagger team can access the trace.

clever sonnet
#

Are you familiarized how the CMD Dockerfle instruction works?

#

If you actually need to run the command, you need to use withExec as usual

still mirage
zealous yarrow
#
func (m *Foo) ContainerEcho(ctx context.Context) (string, error) {
    return dag.Container().
        From("alpine:latest").
        WithDefaultArgs([]string{"echo", "hello world !"}).
        WithExec([]string{}).
        Stdout(ctx)
}

^^^ above works. But my 2 cents would be that we should allow Stdout without exec if default args are set.

clever sonnet
still mirage
clever sonnet
zealous yarrow
#

hey @still mirage, I am happy to jump on a call to discuss and debug this with you. (I believe we are in the same timezone). Best case we may find the solution, worst case we may be able to collect info required to help Marcos debug this better.

still mirage
zealous yarrow
#

anytime after 9am works for me. (I may have to go out for some festival shopping around noon OR around 3PM, but beside that I should be available). A 30mins heads up would be great.

still mirage
zealous yarrow
#

Hi @still mirage , let me know when you are available, i am available for next 1 hr or so before I head out.

still mirage
#

Okay give me 15 min

zealous yarrow
#

I had a call regarding this, and following are the few observations:

tl;dr;

  • it still does not work on their laptop, but I am suspecting this might be due to the resource constraints. We saw CPU jumping to 200% for dagger and memory going upto 1.4GB during the dagger call.
  • I am going to try and constraint my docker instance and see if I can reproduce this consistently. Also would be useful to check the puppeteer/chromium logs, which may tell us exactly why the browser is failing to launch.

Detailed notes:

  • They are running it on a Macbook air with initial resources 4CPU, 4GB RAM. I had them increase it to 8 CPU/8GB ram. it didn't helped either.
  • it failed on my laptop a couple of times, but worked most of the times. I am running this on M2 Pro with 8GB RAM and no limit on CPU for docker (I am also using OrbStack instead of docker desktop).
  • There were some cache misses, but we reconfigured the code a little bit to maximize cache utilization. (copy the code after all software installations is done).
  • We also added some timeout to the code. that started to tell us where exactly the code is getting timeout, but not much help otherwise.
clever sonnet
#

I'd like to rule out the fact that it might not be a dagger only problem

zealous yarrow
#

I tried with Dockerfile, and it works (but again it worked for me using dagger as well).

#

I reduced my resources to 4GB ram, and now it failed 3 times in a row. (using dagger pipeline)

#

trying now with reduced resources + Dockerfile

zealous yarrow
#

after adding resource contraints to my docker desktop, I am consistently able to reproduce the issue with dagger but it works if I exec into a docker container (without dagger) and run the command manually.

clever sonnet
still mirage
#

how to pass source directory to dockerfile? i tried to run below function with dockerfile but getting error for path not found

@func()
  async runDockerFile(@argument({ defaultPath: "/test" }) src: Directory): Promise<string> {
    const ref = await dag
      .container()
      .withDirectory("/test", src)
      .withWorkdir("/test")
      .directory("/test")
      .dockerBuild() // build from Dockerfile
      .withExec([])
      .stdout();
    return ref;
  }

Traces: https://dagger.cloud/StaytunedLLP/traces/696a5863045dbeb4a529b5f1e7a562db

zealous yarrow
#

I tried with Dockerfile and it still gets stuck.

#

@still mirage - can you try adding this withExec([], {noInit: true, useEntrypoint: true}). it seems to have worked for me

#

yep, seems to be consistently working for me with constrained resources as well.

zealous yarrow
zealous yarrow
#

That is great to hear. Maybe we can document this somewhere. I will check with Marcos/team regarding that.