Merge pull request #43 from ninech/add_options_to_build_script
❇️ Adds new options to the build script
This commit is contained in:
commit
95e7fe6e02
@ -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"
|
||||||
|
75
build.sh
75
build.sh
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user