From 220370ed76e83e2e7d807dfed3b4995486519082 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 20 Mar 2019 14:03:18 +0100 Subject: [PATCH 1/2] Add short version tag Adds a short version tag in the form of v$MAJOR.$MINOR. This tags creates the possibillity to follow patch releases automatically with the scheduled import option in Openshift and Kubernetes. --- build.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/build.sh b/build.sh index 5c62b08..dc0e3a3 100755 --- a/build.sh +++ b/build.sh @@ -34,6 +34,9 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then 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: /:" + echo " DOCKER_SHORT_TAG The name of the short tag which is applied to the image." + echo " This is used to tag all patch releases to their containing version e.g. v2.5.1 -> v2.5" + echo " Default: /:\$MAJOR.\$MINOR" echo " SRC_ORG Which fork of netbox to use (i.e. github.com//)." echo " Default: digitalocean" echo " SRC_REPO The name of the netbox for to use (i.e. github.com//)." @@ -165,4 +168,18 @@ if [ "${2}" == "--push" ] || [ "${2}" == "--push-only" ] ; then echo "⏫ Pushing '${DOCKER_TAG}" $DOCKER_CMD push "${DOCKER_TAG}" echo "✅ Finished pushing the Docker image '${DOCKER_TAG}'." + if [[ "${TAG}" =~ ^v([0-9]+)\.([0-9]+)\.[0-9]+$ ]]; then + MAJOR=${BASH_REMATCH[1]} + MINOR=${BASH_REMATCH[2]} + DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG-${DOCKER_ORG}/${DOCKER_REPO}:v${MAJOR}.${MINOR}}" + if [ "$VARIANT" != "main" ]; then + DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG}-${VARIANT}" + fi + echo "⏫ Pushing '${DOCKER_SHORT_TAG}'" + $DOCKER_CMD tag "${DOCKER_TAG}" "${DOCKER_SHORT_TAG}" + $DOCKER_CMD push "${DOCKER_SHORT_TAG}" + echo "✅ Finished pushing the Docker image '${DOCKER_SHORT_TAG}'." + else + echo "☇ No version tag detected; skipping short tag" + fi fi From 286bfa0248da14acecd54ab24505c0ccd66c82f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Wed, 27 Mar 2019 12:00:32 +0100 Subject: [PATCH 2/2] reorganized tagging --- build.sh | 62 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/build.sh b/build.sh index dc0e3a3..d3dc978 100755 --- a/build.sh +++ b/build.sh @@ -86,6 +86,25 @@ SRC_REPO="${SRC_REPO-netbox}" BRANCH="${1}" URL="${URL-https://github.com/${SRC_ORG}/${SRC_REPO}/archive/$BRANCH.tar.gz}" +# Checking which VARIANT to build +VARIANT="${VARIANT-main}" +if [ "$VARIANT" == "main" ]; then + DOCKERFILE="Dockerfile" +else + DOCKERFILE="Dockerfile.${VARIANT}" +fi + +# Fail fast +if [ ! -f "${DOCKERFILE}" ]; then + echo "🚨 The Dockerfile ${DOCKERFILE} for variant '${VARIANT}' doesn't exist." + + if [ -z "$DEBUG" ]; then + exit 1 + else + echo "⚠️ Would exit here with code '1', but DEBUG is enabled." + fi +fi + # variables for tagging the docker image DOCKER_ORG="${DOCKER_ORG-netboxcommunity}" DOCKER_REPO="${DOCKER_REPO-netbox}" @@ -97,25 +116,20 @@ case "${BRANCH}" in *) TAG="${TAG-$BRANCH}";; esac + DOCKER_TAG="${DOCKER_TAG-${DOCKER_ORG}/${DOCKER_REPO}:${TAG}}" - -# Checking which VARIANT to build -VARIANT="${VARIANT-main}" -if [ "$VARIANT" == "main" ]; then - DOCKERFILE="Dockerfile" -else - DOCKERFILE="Dockerfile.${VARIANT}" +if [ "$VARIANT" != "main" ]; then DOCKER_TAG="${DOCKER_TAG}-${VARIANT}" +fi - # Fail fast - if [ ! -f "${DOCKERFILE}" ]; then - echo "🚨 The Dockerfile ${DOCKERFILE} for variant '${VARIANT}' doesn't exist." +if [[ "${TAG}" =~ ^v([0-9]+)\.([0-9]+)\.[0-9]+$ ]]; then + MAJOR=${BASH_REMATCH[1]} + MINOR=${BASH_REMATCH[2]} - if [ -z "$DEBUG" ]; then - exit 1 - else - echo "⚠️ Would exit here with code '1', but DEBUG is enabled." - fi + DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG-${DOCKER_ORG}/${DOCKER_REPO}:v${MAJOR}.${MINOR}}" + + if [ "$VARIANT" != "main" ]; then + DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG}-${VARIANT}" fi fi @@ -162,24 +176,22 @@ if [ "${2}" != "--push-only" ] ; then echo "🐳 Building the Docker image '${DOCKER_TAG}' from the url '${URL}'." $DOCKER_CMD build -t "${DOCKER_TAG}" "${DOCKER_BUILD_ARGS[@]}" "${DOCKER_OPTS[@]}" -f "${DOCKERFILE}" . echo "✅ Finished building the Docker images '${DOCKER_TAG}'" + + if [ -n "$DOCKER_SHORT_TAG" ]; then + echo "🐳 Tagging image '${DOCKER_SHORT_TAG}'." + $DOCKER_CMD tag "${DOCKER_TAG}" "${DOCKER_SHORT_TAG}" + echo "✅ Tagged image '${DOCKER_SHORT_TAG}'" + fi fi if [ "${2}" == "--push" ] || [ "${2}" == "--push-only" ] ; then echo "⏫ Pushing '${DOCKER_TAG}" $DOCKER_CMD push "${DOCKER_TAG}" echo "✅ Finished pushing the Docker image '${DOCKER_TAG}'." - if [[ "${TAG}" =~ ^v([0-9]+)\.([0-9]+)\.[0-9]+$ ]]; then - MAJOR=${BASH_REMATCH[1]} - MINOR=${BASH_REMATCH[2]} - DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG-${DOCKER_ORG}/${DOCKER_REPO}:v${MAJOR}.${MINOR}}" - if [ "$VARIANT" != "main" ]; then - DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG}-${VARIANT}" - fi + + if [ -n "$DOCKER_SHORT_TAG" ]; then echo "⏫ Pushing '${DOCKER_SHORT_TAG}'" - $DOCKER_CMD tag "${DOCKER_TAG}" "${DOCKER_SHORT_TAG}" $DOCKER_CMD push "${DOCKER_SHORT_TAG}" echo "✅ Finished pushing the Docker image '${DOCKER_SHORT_TAG}'." - else - echo "☇ No version tag detected; skipping short tag" fi fi