From 4ac8d5063558df9346796975b2a334eb56d8ac3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=A4der?= Date: Sat, 21 Dec 2019 15:04:49 +0100 Subject: [PATCH] Scripts that mimicks the Docker Hub Build environment --- build.sh | 6 +++--- hooks/push | 2 +- test-hooks.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100755 test-hooks.sh diff --git a/build.sh b/build.sh index 01e841a..2bdb9db 100755 --- a/build.sh +++ b/build.sh @@ -163,9 +163,9 @@ PROJECT_VERSION="${PROJECT_VERSION-$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:] # Get the Git information from the netbox directory if [ -d "${NETBOX_PATH}/.git" ]; then - NETBOX_GIT_REF=$(cd ${NETBOX_PATH}; git rev-parse HEAD) - NETBOX_GIT_BRANCH=$(cd ${NETBOX_PATH}; git rev-parse --abbrev-ref HEAD) - NETBOX_GIT_URL=$(cd ${NETBOX_PATH}; git remote get-url origin) + NETBOX_GIT_REF=$(cd "${NETBOX_PATH}"; git rev-parse HEAD) + NETBOX_GIT_BRANCH=$(cd "${NETBOX_PATH}"; git rev-parse --abbrev-ref HEAD) + NETBOX_GIT_URL=$(cd "${NETBOX_PATH}"; git remote get-url origin) fi ### diff --git a/hooks/push b/hooks/push index 6513b24..ff2788f 100755 --- a/hooks/push +++ b/hooks/push @@ -9,6 +9,6 @@ if [ "${SOURCE_BRANCH}" == "release" ] || [ "${DEBUG}" == "true" ]; then run_build --push-only else - echo "⚠️⚠️⚠️ Only pushing on 'main' branch, but current branch is '${SOURCE_BRANCH}'" + echo "⚠️⚠️⚠️ Only pushing on 'release' branch, but current branch is '${SOURCE_BRANCH}'" exit 0 fi diff --git a/test-hooks.sh b/test-hooks.sh new file mode 100755 index 0000000..5a6af78 --- /dev/null +++ b/test-hooks.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# This helps testing and debugging the build hooks + +# exit when a command exits with an exit code != 0 +set -e + +prepare() { + echo "⏱ Preparing" +} + +cleanup() { + echo "💣 Cleaning Up" + +} + +run_test() { + branch="${1}" + tag="${2}" + echo "🏗 Testing Hook for SOURCE_BRANCH=\"${branch}\" and DOCKER_TAG=\"${tag}\"" + + export SOURCE_BRANCH="${branch}" + SOURCE_COMMIT="$(git rev-parse HEAD)" + export SOURCE_COMMIT + export COMMIT_MSG=test + export DOCKER_REPO=netboxcommunity/netbox + export DOCKERFILE_PATH=Dockerfile + export DOCKER_TAG="${tag}" + export IMAGE_NAME="${DOCKER_REPO}:${DOCKER_TAG}" + + echo "SOURCE_COMMIT=${SOURCE_COMMIT}" + + hooks/build + hooks/test + DRY_RUN=on hooks/push +} + +echo "🐳🐳🐳 Start testing" + +# Make sure the cleanup script is executed +trap cleanup EXIT ERR + +prepare +run_test release branches +run_test release prerelease +run_test release release + +echo "🐳🐳🐳 Done testing"