❇️ Adds new options to the build script

This commit is contained in:
Christian Mäder 2018-02-02 12:48:38 +01:00
parent d2ec32fefe
commit fe05ca5c7c
No known key found for this signature in database
GPG Key ID: 92FFD0A711F196BB
2 changed files with 55 additions and 22 deletions

View File

@ -40,3 +40,5 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ]
VOLUME ["/etc/netbox-nginx/"] VOLUME ["/etc/netbox-nginx/"]
CMD ["gunicorn", "--log-level debug", "-c /opt/netbox/gunicorn_config.py", "netbox.wsgi"] CMD ["gunicorn", "--log-level debug", "-c /opt/netbox/gunicorn_config.py", "netbox.wsgi"]
LABEL SRC_URL="$URL"

View File

@ -8,16 +8,33 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
echo " --push Pushes built Docker image to docker hub." echo " --push Pushes built Docker image to docker hub."
echo "" echo ""
echo "You can use the following ENV variables to customize the build:" echo "You can use the following ENV variables to customize the build:"
echo " DOCKER_OPTS Add parameters to Docker."
echo " Default:"
echo " When <TAG> starts with 'v': \"\""
echo " Else: \"--no-cache\""
echo " BRANCH The branch to build." echo " BRANCH The branch to build."
echo " Also used for tagging the image." echo " Also used for tagging the image."
echo " DOCKER_REPO The Docker registry (i.e. hub.docker.com/r/DOCKER_REPO/netbox) " echo " TAG The version part of the docker tag."
echo " Default:"
echo " When <BRANCH>=master: latest"
echo " When <BRANCH>=develop: snapshot"
echo " Else: same as <BRANCH>"
echo " DOCKER_ORG The Docker registry (i.e. hub.docker.com/r/<DOCKER_ORG>/<DOCKER_REPO>) "
echo " Also used for tagging the image." echo " Also used for tagging the image."
echo " Default: ninech" echo " Default: ninech"
echo " SRC_REPO Which fork of netbox to use (i.e. github.com/<SRC_REPO>/netbox)." echo " DOCKER_REPO The Docker registry (i.e. hub.docker.com/r/<DOCKER_ORG>/<DOCKER_REPO>) "
echo " Also used for tagging the image."
echo " Default: netbox"
echo " DOCKER_TAG The name of the tag which is applied to the image."
echo " Useful for pushing into another registry than hub.docker.com."
echo " Default: <DOCKER_ORG>/<DOCKER_REPO>:<BRANCH>"
echo " SRC_ORG Which fork of netbox to use (i.e. github.com/<SRC_ORG>/<SRC_REPO>)."
echo " Default: digitalocean" echo " Default: digitalocean"
echo " SRC_REPO The name of the netbox for to use (i.e. github.com/<SRC_ORG>/<SRC_REPO>)."
echo " Default: netbox"
echo " URL Where to fetch the package from." echo " URL Where to fetch the package from."
echo " Must be a tar.gz file of the source code." echo " Must be a tar.gz file of the source code."
echo " Default: https://github.com/\${SRC_REPO}/netbox/archive/\$BRANCH.tar.gz" echo " Default: https://github.com/<SRC_ORG>/<SRC_REPO>/archive/\$BRANCH.tar.gz"
if [ "${1}x" == "x" ]; then if [ "${1}x" == "x" ]; then
exit 1 exit 1
@ -26,28 +43,42 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
fi fi
fi fi
SRC_REPO="${SRC_REPO-digitalocean}" # variables for fetching the source
DOCKER_REPO="${DOCKER_REPO-ninech}" SRC_ORG="${SRC_ORG-digitalocean}"
SRC_REPO="${SRC_REPO-netbox}"
BRANCH="${1}" BRANCH="${1}"
URL="${URL-https://github.com/${SRC_REPO}/netbox/archive/$BRANCH.tar.gz}" URL="${URL-https://github.com/${SRC_ORG}/${SRC_REPO}/archive/$BRANCH.tar.gz}"
if [ "${BRANCH}" == "master" ]; then # variables for tagging the docker image
TAG="${TAG-latest}" DOCKER_ORG="${DOCKER_ORG-ninech}"
CACHE="--no-cache" DOCKER_REPO="${DOCKER_REPO-netbox}"
elif [ "${BRANCH}" == "develop" ]; then case "${BRANCH}" in
TAG="${TAG-snapshot}" master)
CACHE="--no-cache" TAG="${TAG-latest}";;
else develop)
TAG="${TAG-$BRANCH}" TAG="${TAG-snapshot}";;
CACHE="" *)
fi TAG="${TAG-$BRANCH}";;
esac
DOCKER_TAG="${DOCKER_TAG-${DOCKER_ORG}/${DOCKER_REPO}:${TAG}}"
echo "🐳 Building the Docker image '${DOCKER_REPO}/netbox:${TAG}' from the branch '${BRANCH}'." # caching is only ok for version tags
docker build -t "${DOCKER_REPO}/netbox:${TAG}" --build-arg "BRANCH=${BRANCH}" --build-arg "URL=${URL}" --pull ${CACHE} . case "${TAG}" in
echo "✅ Finished building the Docker images '${DOCKER_REPO}/netbox:${TAG}'" v*)
CACHE="${CACHE-}";;
*)
CACHE="${CACHE---no-cache}";;
esac
# Docker options
DOCKER_OPTS="${DOCKER_OPTS-$CACHE}"
echo "🐳 Building the Docker image '${DOCKER_TAG}' from the url '${URL}'."
docker build -t "${DOCKER_TAG}" --build-arg "BRANCH=${BRANCH}" --build-arg "URL=${URL}" --pull ${DOCKER_OPTS} .
echo "✅ Finished building the Docker images '${DOCKER_TAG}'"
if [ "${2}" == "--push" ] ; then if [ "${2}" == "--push" ] ; then
echo "⏫ Pushing '${DOCKER_REPO}/netbox:${BRANCH}" echo "⏫ Pushing '${DOCKER_TAG}"
docker push "${DOCKER_REPO}/netbox:${TAG}" docker push "${DOCKER_TAG}"
echo "✅ Finished pushing the Docker image '${DOCKER_REPO}/netbox:${TAG}'." echo "✅ Finished pushing the Docker image '${DOCKER_TAG}'."
fi fi