Skip to content

Instantly share code, notes, and snippets.

@cyborch
Created April 6, 2018 11:08
Show Gist options
  • Save cyborch/e6793843021900d51187ce712e66e324 to your computer and use it in GitHub Desktop.
Save cyborch/e6793843021900d51187ce712e66e324 to your computer and use it in GitHub Desktop.
Docker helper functions
#!/bin/bash
# Activate a named docker machine
docker-machine-set-active() {
eval $(docker-machine env $1)
}
# Create digital ocean droplet
docker-create-droplet() {
if [[ "$1" == "" || "$2" == "" || "$3" == "" ]] ; then
echo "USAGE: docker-create-droplet TOKEN REGION NAME"
echo " TOKEN the Digital Ocean access token"
echo " REGION the region in which the droplet should be created"
echo " NAME the name of the droplet"
return
fi
docker-machine create --driver digitalocean --digitalocean-image ubuntu-16-04-x64 --digitalocean-access-token $1 --digitalocean-region $2 $3
}
# Restart digital ocean droplet
docker-restart-sails-droplet() {
if [[ "$1" == "" || "$2" == "" ]] ; then
echo "USAGE: docker-restart-droplet NAME ENVIRONMENT"
echo " NAME the name of the service"
echo " ENVIRONMENT the environment the service will run in"
return
fi
echo -n "Stopping $1..."
docker stop $1 >/dev/null 2>&1
echo -e " \033[32mdone\033[39m"
echo -n "Cleaning $1..."
docker rm $1 >/dev/null 2>&1
echo -e " \033[32mdone\033[39m"
echo -n "Starting $1..."
result=`docker run --name $1 -p 0.0.0.0:80:1337 -d --restart always $1:$2`
if [[ "$?" == "0" ]] ; then
echo -e " \033[32mdone\033[39m"
else
echo -e " \033[31m$result\033[39m"
fi
}
docker-restart-noservice-droplet() {
if [[ "$1" == "" || "$2" == "" ]] ; then
echo "USAGE: docker-restart-droplet NAME ENVIRONMENT"
echo " NAME the name of the service"
echo " ENVIRONMENT the environment the service will run in"
return
fi
echo -n "Stopping $1..."
docker stop $1 >/dev/null 2>&1
echo -e " \033[32mdone\033[39m"
echo -n "Cleaning $1..."
docker rm $1 >/dev/null 2>&1
echo -e " \033[32mdone\033[39m"
echo -n "Starting $1..."
result=`docker run --name $1 -d --restart always $1:$2`
if [[ "$?" == "0" ]] ; then
echo -e " \033[32mdone\033[39m"
else
echo -e " \033[31m$result\033[39m"
fi
}
healthcheck-staging-authservice() {
echo -n "Check staging authservice..."
if [[ `curl -I https://staging.api.justklikkit.com/v1/oauth/token 2>/dev/null | grep -e 401 -e Sails | wc -l | sed 's/ //g'` == "2" ]] ; then
echo -e " \033[32mok\033[39m"
else
echo -e " \033[1;31mdown\033[0m"
fi
}
healthcheck-staging-resourceservice() {
echo -n "Check staging resourceservice..."
if [[ `curl -I https://staging.api.justklikkit.com/v1/activities 2>/dev/null | grep -e 401 -e Sails | wc -l | sed 's/ //g'` == "2" ]] ; then
echo -e " \033[32mok\033[39m"
else
echo -e " \033[1;31mdown\033[0m"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment