Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created July 16, 2018 08:36
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 cheeyeo/9ad2f0a28c440de3d6371836f036e0af to your computer and use it in GitHub Desktop.
Save cheeyeo/9ad2f0a28c440de3d6371836f036e0af to your computer and use it in GitHub Desktop.
Creating docker container script from phusion ? 2016...?
# example multistage process docker build script from https://blog.phusion.nl/2016/08/31/efficiently-and-conveniently-building-ruby-and-node-js-application-docker-containers-for-production-2
set -e
export IMAGE_NAME=tinco/express-example
export RUN_BUILD="docker run -it --rm -v $PWD:/usr/src/app -w /usr/src/app node:6"
export TEST_COMMAND="./node_modules/mocha/bin/mocha"
function run_image() {
docker run -it --entrypoint /bin/sh $IMAGE_NAME -c $1
}
function build_image() {
$RUN_BUILD npm install
docker build -t $IMAGE_NAME .
}
function test_image() {
run_image $TEST_COMMAND
}
function check_git() {
if [[ `git status --porcelain` ]]; then
echo "Current working directory is dirty, run 'git status' for details."
exit 1
fi
if [[ `git branch --no-color|grep "*"|awk '{ print $2 }'` != $TAG ]]; then
echo "Current branch is not $TAG, checkout and merge that branch before releasing."
exit 1
fi
}
function push() {
git push
docker tag $IMAGE_NAME $IMAGE_NAME:$TAG
docker push $IMAGE_NAME:$TAG
}
case "$1" in
build)
build_image
;;
test)
$RUN_BUILD $TEST_COMMAND
;;
test_image)
test_image
;;
release)
export TAG=$2
if [ -z "$TAG" ]; then
echo "Please supply the tag to be released (i.e. ./docker.sh release production)"
exit 1
fi
build_image
test_image
check_git
push
;;
install)
shift
$RUN_BUILD npm install --save "$@"
;;
*)
echo "Usage: ./docker.sh <command>"
echo ""
echo "For <command> choose any of: build, test, test_image, install, release"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment