Skip to content

Commit

Permalink
Merge pull request #33 from opensafely-core/interactive-exec
Browse files Browse the repository at this point in the history
Support a child image setting separate default interactive executable
  • Loading branch information
bloodearnest authored Oct 31, 2024
2 parents 0ec53cc + 445c894 commit 8794c57
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
set -euo pipefail

executable=${ACTION_EXEC:-bash}
script_executable=${ACTION_EXEC:-bash}
interactive_executable=${INTERACTIVE_EXEC:-$script_executable}

is_real_executable() {
local path shebang
Expand All @@ -23,6 +24,11 @@ is_real_executable() {
}

if test -n "${1:-}"; then
# we have arguments, so default to executing a file
executable=$script_executable

# However, check if the first argument is a valid executable, and use that instead.
# This allows a pattern of `docker run image exec` to run whatever excuteable you want.
if command -v -- "$1" >/dev/null 2>&1; then
# on windows, all files have executable mask, so check it is actually executable
if is_real_executable "$1"; then
Expand All @@ -32,6 +38,10 @@ if test -n "${1:-}"; then
shift
fi
fi

else
# no arguments - we want the interactive executable
executable=$interactive_executable
fi

exec "$executable" "$@"

0 comments on commit 8794c57

Please sign in to comment.