Skip to content

Commit

Permalink
docker: Add proper entrypoint
Browse files Browse the repository at this point in the history
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 <oliver@schinagl.nl>
  • Loading branch information
oliv3r committed Jun 9, 2023
1 parent 4deba6c commit b218c1c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
COPY "./container-entrypoint.sh" "/app/container-entrypoint.sh"
ENTRYPOINT [ "/app/container-entrypoint.sh" ]
3 changes: 2 additions & 1 deletion Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
17 changes: 17 additions & 0 deletions app/container-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b218c1c

Please sign in to comment.