hpc / charliecloud

Lightweight user-defined software stacks for high-performance computing.
https://hpc.github.io/charliecloud
Apache License 2.0
312 stars 61 forks source link

`ch-image modify`: improve non-existent shell error message #1913

Open lucaudill opened 2 months ago

lucaudill commented 2 months ago

When modifying a container image with via ch-image modify using a script, we currently don't have a very user-friendly error message when trying to use a shell that doesn't exist via -S, e.g.

$ ch-image modify -S doesnotexist alpine:3.17 foo <<'EOF'
echo hello
EOF
 -1* FROM alpine:3.17
 -1. COPY ['/tmp/tmpw5_ww4op'] -> '/ch/script.sh'
updating existing image ...
 -1. RUN.S doesnotexist /ch/script.sh
/bin/sh: doesnotexist: not found
something went wrong, rolling back ...
HEAD is now at 36233bb COPY ['/tmp/tmpw5_ww4op'] -> '/ch/script.sh'
error: build failed: RUN command exited with 127

Note that we do have a user-friendly error message for this same problem in interactive mode

$ ch-image modify -S doesnotexist alpine:3.17 foo
copying image from cache ...
ch-run[169241]: error: can't execve(2): doesnotexist: No such file or directory (ch_core.c:570 2)
error: can't run shell: doesnotexist

This is because in interactive mode we rely on the return value of a ch-run subprocess to determine whether the shell is there or not, but we don't perform such a check when traversing the Dockerfile parse tree in the script case.

reidpr commented 2 weeks ago

The shell does tell us it’s not found, but very tersely:

/bin/sh: doesnotexist: not found

Shouldn’t the first example have a SHELL instruction though?