Skip to content

Instantly share code, notes, and snippets.

@Odyno
Last active November 13, 2018 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Odyno/9a2181d9ecf1fe70eb1e515483930d36 to your computer and use it in GitHub Desktop.
Save Odyno/9a2181d9ecf1fe70eb1e515483930d36 to your computer and use it in GitHub Desktop.
#!/bin/bash
IMAGE_NAME=<IMAGE_NAME>
IMAGE_VER="$(head -1 version.txt)"
BASEPATH=$(pwd)
docker info > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "FATAL : Unable to talk to the docker daemon"
exit 3
fi
function check_images_presence {
if [[ "$(docker images -q ${IMAGE_NAME}:${IMAGE_VER} 2> /dev/null)" == "" ]]; then
echo "WARNING: Immage not found, I will build it"
build_image
fi
}
function run_image() {
check_images_presence
docker run -it --rm \
${IMAGE_NAME}:${IMAGE_VER} /bin/bash
}
function build_image() {
docker build -t ${IMAGE_NAME}:${IMAGE_VER} .
}
function help {
echo "USAGE: run.sh <THING>"
echo ""
echo "THING is one of this:"
echo " -sh, bash Bash"
echo " -bi, build_image Build Immage"
}
case "$1" in
-sh | bash)
echo "This task run a bash on build environments"
check_images_presence
run_image
;;
-bi | build_image)
echo "This task run build the image"
build_image
;;
*)
help
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment