Last active
September 6, 2021 00:53
-
-
Save bil0u/93c1c7da08430d76fd7442822ba46c2a to your computer and use it in GitHub Desktop.
[Docker Entrypoint] Docker entrypoint template which handles multiple commands #docker #script
This file contains hidden or 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
#!/usr/bin/env sh | |
# --------------- | |
# App Entrypoints | |
# --------------- | |
run_dev() { | |
echo "Starting development server" | |
} | |
run_prod() { | |
echo "Starting production server" | |
} | |
# ------------ | |
# App Lifecyle | |
# ------------ | |
foo() { | |
echo "Foo" | |
} | |
bar() { | |
echo "Bar" + $@ | |
} | |
# ------------------------------------------------------ | |
# The script starts here. | |
echo "[NAME] Container is starting up ..." | |
if [ "$1" = "/bin/sh" ]; then shift; fi | |
if [ "$1" = "-c" ]; then shift; fi | |
command=$1 | |
shift | |
case $command in | |
'run_dev') run_dev ;; | |
'run_prod') foo && bar && run_prod ;; | |
'foo') foo ;; | |
'bar') bar "$@" ;; | |
*) | |
echo "Unknown command : $command" | |
cat <<-END | |
Usage: <command> [args] | |
Where <command> is one of the below, with optional args availables for * bulleted commands. | |
[+] Entrypoints : | |
- run_dev Runs the app in development mode. | |
- run_prod Runs the app in production mode. | |
[+] Lifecycle : | |
- foo Foo command description. | |
* bar Bar command description. | |
> Args : anything | |
END | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment