Last active
February 3, 2023 13:59
-
-
Save Issykul/daae40738b6965d60cba64db4edf5de1 to your computer and use it in GitHub Desktop.
This is a script which helps you deploy, remove and re-deploy docker stacks/services.
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
#!/bin/bash | |
# Variables | |
STACK_NAME="app" | |
COMPOSE_FILE_NAME="docker-compose.yml" | |
SEC_REDEPLOY=20 | |
# Make sure the script is run with sudo permissions | |
if [[ "${UID}" -ne 0 ]] | |
then | |
echo "Please execute this script with sudo permissions." | |
exit 1 | |
fi | |
# Asking to deploy, remove or re-deploy | |
echo "What would you like to do?" | |
echo "[1] Deploy" | |
echo "[2] Remove" | |
echo "[3] Re-Deploy" | |
read INPUT | |
# Executing the Shell Commands | |
case $INPUT in | |
1) | |
echo "Stack" $STACK_NAME "is being deployed with the compose file" $COMPOSE_FILE_NAME"." | |
docker stack deploy -c $COMPOSE_FILE_NAME $STACK_NAME | |
;; | |
2) | |
echo "Stack" $STACK_NAME "is being removed." | |
docker stack rm $STACK_NAME | |
;; | |
3) | |
echo "Stack" $STACK_NAME "is being re-deployed with the compose file" $COMPOSE_FILE_NAME"." | |
docker stack rm $STACK_NAME && sleep $SEC_REDEPLOY && docker stack deploy -c $COMPOSE_FILE_NAME $STACK_NAME | |
;; | |
*) | |
echo "unknown input" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment