Last active
August 29, 2015 14:03
-
-
Save spuder/78bfb45418073075ee78 to your computer and use it in GitHub Desktop.
Docker build script
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
#!/usr/bin/env bash | |
# A simple script to build a docker container | |
# Pre and Post functions are where you place any optional commands (eg. git clone) | |
# Sets name for docker container docker build -t 'foo/bar:latest | |
readonly DOCKER_USER='foo' | |
readonly DOCKER_NAME='bar' | |
readonly DOCKER_TAG='latest' | |
# Mac and boot2docker don't use root for docker command | |
readonly DOCKER_NEED_ROOT=true | |
# Not used, usful for when script is passed in parameters | |
readonly PROGNAME=$(basename $0) | |
#readonly PROGDIR=$(readlink -m $(dirname $0)) | |
readonly ARGS="$@" | |
# Colors | |
readonly ESC_SEQ="\x1b[" | |
readonly COL_RESET=$ESC_SEQ"39;49;00m" | |
readonly COL_RED=$ESC_SEQ"31;01m" | |
readonly COL_GREEN=$ESC_SEQ"32;01m" | |
readonly COL_YELLOW=$ESC_SEQ"33;01m" | |
readonly COL_BLUE=$ESC_SEQ"34;01m" | |
readonly COL_MAGENTA=$ESC_SEQ"35;01m" | |
readonly COL_CYAN=$ESC_SEQ"36;01m" | |
pre() { | |
echo -e "$COL_GREEN Pre-build... $COL_RESET" | |
# Place commands you want to run before the build (eg. git clone) | |
} | |
build() { | |
echo -e "$COL_GREEN Building... $COL_RESET" | |
# docker build -t "${DOCKER_USER}/${DOCKER_NAME}:${DOCKER_TAG}" . | |
if [[ $DOCKER_NEED_ROOT = true ]] | |
then | |
echo -e "$COL_YELLOW Running docker with sudo $COL_RESET" | |
sudo docker build -t "${DOCKER_USER}/${DOCKER_NAME}:${DOCKER_TAG}" . | |
else | |
echo -e "$COL_YELLOW Running docker without sudo $COL_RESET" | |
docker build -t "${DOCKER_USER}/${DOCKER_NAME}:${DOCKER_TAG}" . | |
fi | |
} | |
post() { | |
echo -e "$COL_GREEN Post-build... $COL_RESET" | |
# Place the commands you want to run after the build (eg. rm foo) | |
} | |
main() { | |
pre | |
build | |
post | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment