#Don't stop when with_exec encounters an exit code > 0

1 messages · Page 1 of 1 (latest)

mint idol
#

Is it possible to run a command and not stop the execution?

The command I am running may return error code > 0, but that's considered a totally normal in my situation.

For example, I am running a tool called pixelmatch, which may return error code 66 in case input images don't match.

Right now, if I use with_exec with the following command:

pixelmatch /sample1.png /sample2.png /diff.png 0.1

I get this (log cut for breviry):

#3
#3 0.524 matched in: 95.832ms
#3 0.525 different pixels: 428622
#3 0.525 error: 19.72%
#3 ERROR: process "pixelmatch /sample3.png /sample4.png /diff-new.png 0.1 > /dev/null" did not complete successfully: exit code: 66

Perhaps there's an alternative to with_exec that would not stumbled upon a non-0 exit code?

P.S. I am trying out Elixir SDK.

#

FWIW the full code I have looks like this:

# https://docs.dagger.io/api/reference/

Mix.install([{:dagger, path: "/Users/eugene/oss/dagger/sdk/elixir"}])

gs_command = ~w(
  gs -sDEVICE=png16m
     -dGraphicsAlphaBits=4
     -dTextAlphaBits=4
     -r150
     -o /tmp/page-%03d.png
     /tmp/Arizona_Dream.pdf
)

download_file_command = ~w(
  curl --silent --output /tmp/Arizona_Dream.pdf https://en.wikipedia.org/api/rest_v1/page/pdf/Arizona_Dream
)

client = Dagger.connect!()

sample1 =
  client
  |> Dagger.Query.container([])
  |> Dagger.Container.from("debian:bullseye-20230522")
  |> Dagger.Container.with_exec(~w(apt update))
  |> Dagger.Container.with_exec(~w(apt install -y curl ghostscript))
  |> Dagger.Container.with_exec(download_file_command)
  |> Dagger.Container.with_exec(gs_command)
  |> Dagger.Container.file("/tmp/page-001.png")

sample2 =
  client
  |> Dagger.Query.container([])
  |> Dagger.Container.from("alpine:3.17")
  |> Dagger.Container.with_exec(~w(apk add --quiet --no-progress curl ghostscript))
  |> Dagger.Container.with_exec(download_file_command)
  |> Dagger.Container.with_exec(gs_command)
  |> Dagger.Container.file("/tmp/page-001.png")

result =
  client
  |> Dagger.Query.container([])
  |> Dagger.Container.from("alpine:3.18")
  |> Dagger.Container.with_file("/sample1.png", sample1)
  |> Dagger.Container.with_file("/sample2.png", sample2)
  |> Dagger.Container.with_exec(~w(apk add --quiet --no-progress npm))
  |> Dagger.Container.with_exec(~w(npm install -g pixelmatch))
  |> Dagger.Container.with_exec(~w(pixelmatch /sample1.png /sample2.png /diff.png 0.1 > /dev/null))
  |> Dagger.Container.file("/diff.png")

Dagger.File.export(result, "/tmp/diff.png")

For context, idea behind this code is to run different versions of gs tool on the same input file, and compare the results.

#

The code will not run beyond this line:

|> Dagger.Container.with_exec(~w(pixelmatch /sample1.png /sample2.png /diff.png 0.1 > /dev/null))
#

@spiral tide pinging you in case you have ideas 🙏 though I am not entirely sure this is related to Elixir SDK specifically

sturdy axle
#

you can always add ... || true to your exec's

spiral tide
#

@mint idol You may need to use shell such as to sh and use || like @sturdy axle suggests. For example:

# https://docs.dagger.io/api/reference/

Mix.install([{:dagger, github: "dagger/dagger", sparse: "sdk/elixir"}])

client = Dagger.connect!()

client
|> Dagger.Query.container()
|> Dagger.Container.from("alpine")
|> Dagger.Container.with_exec(["sh", "-c", "ls abc || true"]) # `ls abc` return exit status (`$?`) 1
|> Dagger.Container.with_exec(["echo" ,"this step should be show"])
|> Dagger.Container.stdout()
|> IO.puts
mint idol
#

sh and || did the trick, thanks! before this I was trying only || and it didn't work

amber nova
lilac imp
#

Welp, this basically kills Dagger for me.

I want to have a GitLab CI job run a basic linting task that produces a code climate report file. I can't suppress the exit code with something like || true because I want the job to fail in GitLab CI and would need to use the exit code.

I could determine whether or not to fail based on if there are any code quality findings, but that's already what the lint job is doing in the exec and basing its exit code on. I don't want to have to clobber that information with || true then redetermine what it is.

If the exec fails then so does the subsequent export of the code quality file. Why am I seemingly not allowed to export a file from a failed exec? The container should still exist, so I should be able to extract out that file.

amber nova
#

IIRC this limitation comes from buildkit and the ability that we don't have a way to export files if the exec OP fails. @long rain would probably know better. Having said that, there's a way to achieve what you need which is less hacky than the || true thing which is putting files into a volume and use them from there afterwards.