Created
November 26, 2022 06:45
-
-
Save luisnquin/26a005577151f11eda13de74ab0fc6cb to your computer and use it in GitHub Desktop.
Bash script that runs swagger-editor in docker and waits for signal SIGINT to kill and remove containers
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
main() { | |
docker_command="docker run -d -p 80:8080 " | |
if [[ $1 != "" ]]; then | |
absolute_path=$(realpath "$1") | |
dir=$(dirname "$absolute_path") | |
docker_command+="-v $dir:/tmp -e SWAGGER_FILE=/tmp/$1 " | |
fi | |
docker_command+="swaggerapi/swagger-editor" | |
container_id=$(eval "$docker_command") | |
echo "Listening here: \033[1;34mhttp://localhost\033[0m 🍁" | |
( | |
trap exit SIGINT | |
read -r -d '' _ </dev/tty | |
) | |
docker kill "$container_id" >/dev/null | |
docker rm "$container_id" >/dev/null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment