2017-06-09 03:14:43 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
|
|
|
|
echo "Usage: ${0} <branch> [--push]"
|
2017-09-11 08:30:52 -05:00
|
|
|
echo " branch The branch or tag to build. Required."
|
|
|
|
echo " --push Pushes built Docker image to docker hub."
|
2017-06-09 03:14:43 -05:00
|
|
|
echo ""
|
|
|
|
echo "You can use the following ENV variables to customize the build:"
|
|
|
|
echo " BRANCH The branch to build."
|
|
|
|
echo " Also used for tagging the image."
|
2017-09-11 08:30:52 -05:00
|
|
|
echo " DOCKER_REPO The Docker registry (i.e. hub.docker.com/r/DOCKER_REPO/netbox) "
|
|
|
|
echo " Also used for tagging the image."
|
|
|
|
echo " Default: ninech"
|
|
|
|
echo " SRC_REPO Which fork of netbox to use (i.e. github.com/<SRC_REPO>/netbox)."
|
|
|
|
echo " Default: digitalocean"
|
2017-06-09 03:14:43 -05:00
|
|
|
echo " URL Where to fetch the package from."
|
|
|
|
echo " Must be a tar.gz file of the source code."
|
2017-09-11 08:30:52 -05:00
|
|
|
echo " Default: https://github.com/\${SRC_REPO}/netbox/archive/\$BRANCH.tar.gz"
|
2017-06-09 03:14:43 -05:00
|
|
|
|
|
|
|
if [ "${1}x" == "x" ]; then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
SRC_REPO="${SRC_REPO-digitalocean}"
|
|
|
|
DOCKER_REPO="${DOCKER_REPO-ninech}"
|
|
|
|
BRANCH="${1}"
|
|
|
|
URL="${URL-https://github.com/${SRC_REPO}/netbox/archive/$BRANCH.tar.gz}"
|
|
|
|
|
2017-06-09 05:41:14 -05:00
|
|
|
if [ "${BRANCH}" == "master" ]; then
|
|
|
|
TAG="${TAG-latest}"
|
2017-08-11 10:08:43 -05:00
|
|
|
CACHE="--no-cache"
|
2017-06-09 05:41:14 -05:00
|
|
|
elif [ "${BRANCH}" == "develop" ]; then
|
|
|
|
TAG="${TAG-snapshot}"
|
2017-08-11 10:08:43 -05:00
|
|
|
CACHE="--no-cache"
|
2017-06-09 05:41:14 -05:00
|
|
|
else
|
|
|
|
TAG="${TAG-$BRANCH}"
|
2017-08-11 10:08:43 -05:00
|
|
|
CACHE=""
|
2017-06-09 05:41:14 -05:00
|
|
|
fi
|
2017-06-09 03:14:43 -05:00
|
|
|
|
2017-06-09 05:41:14 -05:00
|
|
|
echo "🐳 Building the Docker image '${DOCKER_REPO}/netbox:${TAG}' from the branch '${BRANCH}'."
|
2018-01-30 09:00:05 -06:00
|
|
|
docker build -t "${DOCKER_REPO}/netbox:${TAG}" --build-arg "BRANCH=${BRANCH}" --build-arg "URL=${URL}" --pull ${CACHE} .
|
2017-06-09 05:41:14 -05:00
|
|
|
echo "✅ Finished building the Docker images '${DOCKER_REPO}/netbox:${TAG}'"
|
2017-06-09 03:14:43 -05:00
|
|
|
|
|
|
|
if [ "${2}" == "--push" ] ; then
|
2017-06-09 06:05:02 -05:00
|
|
|
echo "⏫ Pushing '${DOCKER_REPO}/netbox:${BRANCH}"
|
2017-06-09 05:41:14 -05:00
|
|
|
docker push "${DOCKER_REPO}/netbox:${TAG}"
|
2017-06-09 06:05:02 -05:00
|
|
|
echo "✅ Finished pushing the Docker image '${DOCKER_REPO}/netbox:${TAG}'."
|
2017-06-09 03:14:43 -05:00
|
|
|
fi
|