From b218c1cc0915b503fc55f66a6c69219cab7677f3 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Sat, 3 Jun 2023 17:19:00 +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 docker-gen 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 && docker-gen renew` in a docker-gen image for example. E.g. `docker run docker-gen --help` works, as does `docker run docker-gen /bin/sh` or `docker run docker-gen ls`. [0]: https://github.com/docker-library/official-images#consistency Signed-off-by: Olliver Schinagl --- Dockerfile.alpine | 3 ++- Dockerfile.debian | 3 ++- app/container-entrypoint.sh | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100755 app/container-entrypoint.sh diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 3e92a58b..bb74051d 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -28,4 +28,5 @@ COPY --from=go-builder /build/docker-gen /usr/local/bin/docker-gen # Copy the license COPY LICENSE /usr/local/share/doc/docker-gen/ -ENTRYPOINT ["/usr/local/bin/docker-gen"] \ No newline at end of file +COPY "./container-entrypoint.sh" "/app/container-entrypoint.sh" +ENTRYPOINT [ "/app/container-entrypoint.sh" ] diff --git a/Dockerfile.debian b/Dockerfile.debian index 42cf6356..7cfb29e7 100644 --- a/Dockerfile.debian +++ b/Dockerfile.debian @@ -32,4 +32,5 @@ COPY --from=go-builder /build/docker-gen /usr/local/bin/docker-gen # Copy the license COPY LICENSE /usr/local/share/doc/docker-gen/ -ENTRYPOINT ["/usr/local/bin/docker-gen"] +COPY "./container-entrypoint.sh" "/app/container-entrypoint.sh" +ENTRYPOINT [ "/app/container-entrypoint.sh" ] diff --git a/app/container-entrypoint.sh b/app/container-entrypoint.sh new file mode 100755 index 00000000..e328f22f --- /dev/null +++ b/app/container-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -eu + +bin='docker-gen' + +# 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