Last active
April 12, 2020 10:37
-
-
Save brunoborges/b9e9dd4e3e3ccaa3137b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build with: | |
# docker build -t entrypoint . | |
FROM alpine | |
COPY verify.sh ./ | |
RUN chmod +x verify.sh | |
ENTRYPOINT ["./verify.sh"] | |
CMD ["sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build with | |
# docker build -t overridden . | |
FROM entrypoint | |
COPY overridden.sh ./ | |
RUN chmod +x overridden.sh | |
ENTRYPOINT ["./overridden.sh"] | |
CMD ["sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "[overridden/overridden.sh] Overridden entrypoint. Should be OK to display this, but not without '-e VAR=ok'" | |
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
chmod +x *.sh | |
docker rmi -f entrypoint overridden | |
docker build -t entrypoint -f Dockerfile.entrypoint . | |
docker build -t overridden -f Dockerfile.overridden . | |
echo "" | |
echo "" | |
echo "Docker run 'entrypoint' without VAR=ok must fail:" | |
docker run --rm entrypoint | |
[ $? = 1 ] && echo "Test passed" || echo "Test failed." | |
echo "" | |
echo "" | |
echo "Docker run 'entrypoint' with VAR=ok must pass:" | |
docker run --rm -e VAR=ok entrypoint | |
[ $? = 0 ] && echo "Test passed" || echo "Test failed." | |
echo "" | |
echo "" | |
echo "Docker run 'overridden' without VAR=ok must fail:" | |
docker run --rm overridden | |
[ $? = 1 ] && echo "Test passed" || echo "Test failed." | |
echo "" | |
echo "" | |
echo "Docker run 'overridden' with VAR=ok must pass:" | |
docker run --rm -e VAR=ok overridden | |
[ $? = 0 ] && echo "Test passed" || echo "Test failed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "[entrypoint/verify.sh] Verifying variable VAR..." | |
if [ "$VAR" = "ok" ]; then | |
echo "[entrypoint/verify.sh] variable exists and it is 'ok'" | |
exec "$@" | |
else | |
echo '[entrypoint/verify.sh] Missing $VAR=ok' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment