Skip to content

when bash is present in the image - job containers ignore user's choice for a sh entrypoint

Consider a pipeline that uses:

  1. base image for jobs who is built on busybox (no bash, e.g. kaniko)
  2. a custom base image for jobs who is built of alpine, added with the package bash for historical reasons. The ENTRYPOINT of the image is /bin/sh - the Dockerfile does not change the entrypoint - just installs the bash package to be able to call some 3rd party scripts with a #!/bin/bash shebang.
  3. scripts from the repo that should be called from all jobs, some may run in a container with bash, but not all - so we decided to write them and test them in the lowest common denominator - busybox's /bin/sh (which is some amalgamation of dash, whatever).

The first command in all job's script is pstree.

which when run in a busybox image without bash gives:

sh-+-sh---sh---pstree
   `-tee

Great.

However.

When run from a container of the image that has bash (the alpine entrypoint is still /bin/sh) - the runtime I get in the container is ...bash... ???

pstree yields:

bash-+-bash---bash---pstree
   `-tee

which results with runtime errors on scripts that are meant for sh...

Tried:

  image:
    entrypoint: [""]
  image:
    entrypoint: ["/bin/sh"]
  image:
    entrypoint: ["/bin/sh", "-c"]

same results... 😮

...

Adding shebang to the scripts is useless, because they are designed to be sourceed and mount on the context functions that can then be called from later steps of the script: stage.

e.g:

   script:
     - pstree
     - . $CICD_ROOT/source-init.sh;   #<------ defines local vars and functions, e.g. log
     - log "[${INFO}] loaded";

Self-hosted from linux package v15.x, kubernetes runner v15.x, recommended arch, Ultimate plan.

Edited by Osher El-Netanany