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 <oliver@schinagl.nl>
This commit is contained in:
Olliver Schinagl 2023-06-03 17:09:45 +02:00
parent 295dba93b5
commit db5ed29fa2
No known key found for this signature in database
GPG Key ID: 96E1A3A6C9044763
2 changed files with 26 additions and 1 deletions

View File

@ -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" ]

24
container-entrypoint.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
# SPDX-License-Identifier: GPL2-or-later
#
# Copyright (C) 2023 Olliver Schinagl <oliver@schinagl.nl>
#
# 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