Skip to content

Commit 36b946b

Browse files
committed
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 <[email protected]>
1 parent 4deba6c commit 36b946b

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Dockerfile.alpine

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ COPY --from=go-builder /build/docker-gen /usr/local/bin/docker-gen
2828
# Copy the license
2929
COPY LICENSE /usr/local/share/doc/docker-gen/
3030

31-
ENTRYPOINT ["/usr/local/bin/docker-gen"]
31+
COPY "./container-entrypoint.sh" "/app/container-entrypoint.sh"
32+
ENTRYPOINT [ "/app/container-entrypoint.sh" ]

Dockerfile.debian

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ COPY --from=go-builder /build/docker-gen /usr/local/bin/docker-gen
3232
# Copy the license
3333
COPY LICENSE /usr/local/share/doc/docker-gen/
3434

35-
ENTRYPOINT ["/usr/local/bin/docker-gen"]
35+
COPY "./container-entrypoint.sh" "/app/container-entrypoint.sh"
36+
ENTRYPOINT [ "/app/container-entrypoint.sh" ]

app/container-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: MIT
3+
#
4+
# Copyright (C) 2023 Olliver Schinagl <[email protected]>
5+
#
6+
# A beginning user should be able to docker run image bash (or sh) without
7+
# needing to learn about --entrypoint
8+
# https://github.com/docker-library/official-images#consistency
9+
10+
set -eu
11+
12+
bin='docker-gen'
13+
14+
# run command if it is not starting with a "-" and is an executable in PATH
15+
if [ "${#}" -le 0 ] || \
16+
[ "${1#-}" != "${1}" ] || \
17+
[ -d "${1}" ] || \
18+
! command -v "${1}" > '/dev/null' 2>&1; then
19+
entrypoint='true'
20+
fi
21+
22+
exec ${entrypoint:+${bin:?}} "${@}"
23+
24+
exit 0

0 commit comments

Comments
 (0)