From db5ed29fa237f77e5b0fcaa2d4b3259994a189b1 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Sat, 3 Jun 2023 17:09:45 +0200 Subject: [PATCH] docker: Add proper entrypoint As per docker guidelines [0] a container should always really have a consistent entrypoint, without having to override it or do special tricks. The behavior should be _identical_ as before, but will no longer trigger errors because sslh doesn't understand certain parameters (/bin/sh for example being common). Further more, allows a proper entrypoint for a CI to work easily with the container as well. Allowing for scenario's such as `apk add git && sslh --foreground` in your sslh image for example. E.g. `docker run sslh --help` works though with the default `--foreground` a bit weirdly, as does `docker run sslh /bin/sh` or `docker run sslh ls`. [0]: https://github.com/docker-library/official-images#consistency Signed-off-by: Olliver Schinagl --- Dockerfile | 3 ++- container-entrypoint.sh | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 container-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 4609512..1cda8a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,5 @@ COPY --from=build "/sslh/sslh-select" "/usr/local/bin/sslh" RUN apk --no-cache add libconfig pcre2 -ENTRYPOINT [ "/usr/local/bin/sslh" ] +COPY "./container-entrypoint.sh" "/init" +ENTRYPOINT [ "/init" ] diff --git a/container-entrypoint.sh b/container-entrypoint.sh new file mode 100755 index 0000000..cabc783 --- /dev/null +++ b/container-entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL2-or-later +# +# Copyright (C) 2023 Olliver Schinagl +# +# A beginning user should be able to docker run image bash (or sh) without +# needing to learn about --entrypoint +# https://github.com/docker-library/official-images#consistency + +set -eu + +bin='sslh' + +# run command if it is not starting with a "-" and is an executable in PATH +if [ "${#}" -le 0 ] || \ + [ "${1#-}" != "${1}" ] || \ + [ -d "${1}" ] || \ + ! command -v "${1}" > '/dev/null' 2>&1; then + entrypoint='true' +fi + +exec ${entrypoint:+${bin}} "${@}" + +exit 0