Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Exit immediately if a command fails.
- set -e
- # Treat unset variables as errors.
- set -u
- # Name of the Docker Compose service for the development environment.
- readonly SERVICE="devenv"
- # Function to show a help message about this shell script.
- help(){
- # Print the help message line by line with a single command.
- printf "%s\n"\
- "Manage development environment containers."\
- ""\
- "Usage: ${0} [help | start | stop]"\
- ""\
- "Commands:"\
- " help Show this help message. Default command."\
- " start Start a container."\
- " stop Stop all containers."
- }
- # Function to start a development environment container.
- start(){
- # Run the Docker Compose command to start the service.
- docker compose run --quiet-pull --rm "${SERVICE}" 2>/dev/null
- }
- # Function to stop all development environment containers.
- stop(){
- # Run the Docker Compose command to stop the service.
- docker compose kill "${SERVICE}" 2>/dev/null
- }
- # Check that the number of arguments of the script is at most one.
- if [ $# -gt 1 ]; then
- >&2 echo "Too many arguments, expected at most one."
- return 1
- fi
- # Command to run taken from the optional argument. Defaults to "help".
- readonly COMMAND="${1:-"help"}"
- # Try to run the command.
- case "${COMMAND}" in
- # Run the command if it's either "help", "start", or "stop".
- "help"|"start"|"stop")
- "${COMMAND}"
- ;;
- # Show an error message otherwise explaining that the argument is invalid.
- *)
- >&2 echo "Invalid argument, expected \"help\", \"start\", or \"stop\"."
- return 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement