diff --git a/build-functions/docker-functions.sh b/build-functions/docker-functions.sh index 137ec54..3d947ab 100644 --- a/build-functions/docker-functions.sh +++ b/build-functions/docker-functions.sh @@ -5,4 +5,4 @@ push_image_to_registry() { echo "⏫ Pushing '${target_tag}'" $DRY docker push "${target_tag}" echo "✅ Finished pushing the Docker image '${target_tag}'." -} \ No newline at end of file +} diff --git a/build-functions/get-public-image-config.sh b/build-functions/get-public-image-config.sh index f718716..4f5b695 100644 --- a/build-functions/get-public-image-config.sh +++ b/build-functions/get-public-image-config.sh @@ -45,16 +45,16 @@ _get_image_configuration() { --silent \ --location \ --header "Authorization: Bearer $token" \ - "https://registry-1.docker.io/v2/$image/blobs/$digest" \ - | jq -r ".config.Labels.\"$label\"" + "https://registry-1.docker.io/v2/$image/blobs/$digest" | + jq -r ".config.Labels.\"$label\"" } _get_token() { local image=$1 curl \ --silent \ - "https://auth.docker.io/token?scope=repository:$image:pull&service=registry.docker.io" \ - | jq -r '.token' + "https://auth.docker.io/token?scope=repository:$image:pull&service=registry.docker.io" | + jq -r '.token' } _get_digest() { @@ -65,8 +65,8 @@ _get_digest() { --silent \ --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ --header "Authorization: Bearer $token" \ - "https://registry-1.docker.io/v2/$image/manifests/$tag" \ - | jq -r '.config.digest' + "https://registry-1.docker.io/v2/$image/manifests/$tag" | + jq -r '.config.digest' } _get_layers() { @@ -77,6 +77,6 @@ _get_layers() { --silent \ --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ --header "Authorization: Bearer $token" \ - "https://registry-1.docker.io/v2/$image/manifests/$tag" \ - | jq -r '.layers[].digest' + "https://registry-1.docker.io/v2/$image/manifests/$tag" | + jq -r '.layers[].digest' } diff --git a/build-latest.sh b/build-latest.sh index 468dffe..54ebe36 100755 --- a/build-latest.sh +++ b/build-latest.sh @@ -19,7 +19,7 @@ fi # Checking if PRERELEASE is either unset, 'true' or 'false' ### if [ -n "${PRERELEASE}" ] && - { [ "${PRERELEASE}" != "true" ] && [ "${PRERELEASE}" != "false" ]; }; then + { [ "${PRERELEASE}" != "true" ] && [ "${PRERELEASE}" != "false" ]; }; then if [ -z "${DEBUG}" ]; then echo "⚠️ PRERELEASE must be either unset, 'true' or 'false', but was '${PRERELEASE}'!" @@ -60,9 +60,10 @@ if [ "${PRERELEASE}" == "true" ]; then # shellcheck disable=SC2003 MINOR_UNSTABLE=$(expr match "${VERSION}" 'v[0-9]\+\.\([0-9]\+\)') - if { [ "${MAJOR_STABLE}" -eq "${MAJOR_UNSTABLE}" ] \ - && [ "${MINOR_STABLE}" -ge "${MINOR_UNSTABLE}" ]; - } || [ "${MAJOR_STABLE}" -gt "${MAJOR_UNSTABLE}" ]; then + if { + [ "${MAJOR_STABLE}" -eq "${MAJOR_UNSTABLE}" ] && + [ "${MINOR_STABLE}" -ge "${MINOR_UNSTABLE}" ] + } || [ "${MAJOR_STABLE}" -gt "${MAJOR_UNSTABLE}" ]; then echo "❎ Latest unstable version '${VERSION}' is not higher than the latest stable version '$STABLE_VERSION'." if [ -z "$DEBUG" ]; then diff --git a/build.sh b/build.sh index 47f4160..82084bf 100755 --- a/build.sh +++ b/build.sh @@ -117,7 +117,7 @@ NETBOX_PATH="${NETBOX_PATH-.netbox}" ### # Fetching the NetBox source ### -if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ] ; then +if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ]; then echo "🌐 Checking out '${NETBOX_BRANCH}' of NetBox from the url '${URL}' into '${NETBOX_PATH}'" if [ ! -d "${NETBOX_PATH}" ]; then $DRY git clone -q --depth 10 -b "${NETBOX_BRANCH}" "${URL}" "${NETBOX_PATH}" @@ -174,9 +174,18 @@ 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 ### @@ -186,19 +195,22 @@ DOCKER_REGISTRY="${DOCKER_REGISTRY-docker.io}" DOCKER_ORG="${DOCKER_ORG-netboxcommunity}" DOCKER_REPO="${DOCKER_REPO-netbox}" case "${NETBOX_BRANCH}" in - master) - TAG="${TAG-latest}";; - develop) - TAG="${TAG-snapshot}";; - *) - TAG="${TAG-$NETBOX_BRANCH}";; +master) + TAG="${TAG-latest}" + ;; +develop) + TAG="${TAG-snapshot}" + ;; +*) + TAG="${TAG-$NETBOX_BRANCH}" + ;; esac ### # Determine targets to build ### DEFAULT_DOCKER_TARGETS=("main" "ldap") -DOCKER_TARGETS=( "${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}") +DOCKER_TARGETS=("${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}") echo "🏭 Building the following targets:" "${DOCKER_TARGETS[@]}" ### @@ -216,7 +228,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do TARGET_DOCKER_TAG="${TARGET_DOCKER_TAG}-${DOCKER_TARGET}" fi if [ -n "${GH_ACTION}" ]; then - echo "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG}" >> "$GITHUB_ENV" + echo "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG}" >>"$GITHUB_ENV" echo "::set-output name=skipped::false" fi @@ -242,7 +254,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do ### # Proceeding to buils stage, except if `--push-only` is passed ### - if [ "${2}" != "--push-only" ] ; then + if [ "${2}" != "--push-only" ]; then ### # Checking if the build is necessary, # meaning build only if one of those values changed: @@ -259,7 +271,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do BUILD_REASON="${BUILD_REASON} interactive" elif [ "$DOCKER_REGISTRY" = "docker.io" ]; then source ./build-functions/get-public-image-config.sh - IFS=':' read -ra DOCKER_FROM_SPLIT <<< "${DOCKER_FROM}" + IFS=':' read -ra DOCKER_FROM_SPLIT <<<"${DOCKER_FROM}" if ! [[ ${DOCKER_FROM_SPLIT[0]} =~ .*/.* ]]; then # Need to use "library/..." for images the have no two part name DOCKER_FROM_SPLIT[0]="library/${DOCKER_FROM_SPLIT[0]}" @@ -295,8 +307,8 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do -t "${TARGET_DOCKER_TAG}" ) if [ -n "${TARGET_DOCKER_SHORT_TAG}" ]; then - DOCKER_BUILD_ARGS+=( -t "${TARGET_DOCKER_SHORT_TAG}" ) - DOCKER_BUILD_ARGS+=( -t "${TARGET_DOCKER_LATEST_TAG}" ) + DOCKER_BUILD_ARGS+=(-t "${TARGET_DOCKER_SHORT_TAG}") + DOCKER_BUILD_ARGS+=(-t "${TARGET_DOCKER_LATEST_TAG}") fi # --label @@ -323,22 +335,22 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do ) fi if [ -n "${BUILD_REASON}" ]; then - BUILD_REASON=$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$BUILD_REASON") - DOCKER_BUILD_ARGS+=( --label "BUILD_REASON=${BUILD_REASON}" ) + BUILD_REASON=$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<<"$BUILD_REASON") + DOCKER_BUILD_ARGS+=(--label "BUILD_REASON=${BUILD_REASON}") fi # --build-arg - DOCKER_BUILD_ARGS+=( --build-arg "NETBOX_PATH=${NETBOX_PATH}" ) + DOCKER_BUILD_ARGS+=(--build-arg "NETBOX_PATH=${NETBOX_PATH}") if [ -n "${DOCKER_FROM}" ]; then - DOCKER_BUILD_ARGS+=( --build-arg "FROM=${DOCKER_FROM}" ) + DOCKER_BUILD_ARGS+=(--build-arg "FROM=${DOCKER_FROM}") fi if [ -n "${HTTP_PROXY}" ]; then - DOCKER_BUILD_ARGS+=( --build-arg "http_proxy=${HTTP_PROXY}" ) - DOCKER_BUILD_ARGS+=( --build-arg "https_proxy=${HTTPS_PROXY}" ) + DOCKER_BUILD_ARGS+=(--build-arg "http_proxy=${HTTP_PROXY}") + DOCKER_BUILD_ARGS+=(--build-arg "https_proxy=${HTTPS_PROXY}") fi if [ -n "${NO_PROXY}" ]; then - DOCKER_BUILD_ARGS+=( --build-arg "no_proxy=${NO_PROXY}" ) + DOCKER_BUILD_ARGS+=(--build-arg "no_proxy=${NO_PROXY}") fi ### @@ -360,7 +372,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do ### # Pushing the docker images if either `--push` or `--push-only` are passed ### - if [ "${2}" == "--push" ] || [ "${2}" == "--push-only" ] ; then + if [ "${2}" == "--push" ] || [ "${2}" == "--push-only" ]; then source ./build-functions/docker-functions.sh push_image_to_registry "${TARGET_DOCKER_TAG}" diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 96ed002..c795d6a 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -18,7 +18,7 @@ CUR_DB_WAIT_TIME=0 while ! ./manage.py migrate 2>&1 && [ "${CUR_DB_WAIT_TIME}" -lt "${MAX_DB_WAIT_TIME}" ]; do echo "⏳ Waiting on DB... (${CUR_DB_WAIT_TIME}s / ${MAX_DB_WAIT_TIME}s)" sleep "${DB_WAIT_TIMEOUT}" - CUR_DB_WAIT_TIME=$(( CUR_DB_WAIT_TIME + DB_WAIT_TIMEOUT )) + CUR_DB_WAIT_TIME=$((CUR_DB_WAIT_TIME + DB_WAIT_TIMEOUT)) done if [ "${CUR_DB_WAIT_TIME}" -ge "${MAX_DB_WAIT_TIME}" ]; then echo "❌ Waited ${MAX_DB_WAIT_TIME}s or more for the DB to become ready." @@ -36,17 +36,17 @@ else SUPERUSER_EMAIL='admin@example.com' fi if [ -f "/run/secrets/superuser_password" ]; then - SUPERUSER_PASSWORD="$(< /run/secrets/superuser_password)" + SUPERUSER_PASSWORD="$( "../${INITIALIZERS_DIR}/${script}" + sed -E 's/^# //' "${script}" >"../${INITIALIZERS_DIR}/${script}" done ) }