💄 Cleanup and hide warnings

This commit is contained in:
Christian Mäder 2018-03-05 14:29:24 +01:00
parent 6a01a3379d
commit 8f001adef4
No known key found for this signature in database
GPG Key ID: 92FFD0A711F196BB
3 changed files with 41 additions and 17 deletions

View File

@ -1,17 +1,18 @@
#!/bin/bash
# Builds all published branches
ORIGINAL_GITHUB_REPO="digitalocean/netbox"
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/branches"
CURL_OPTS="-s"
CURL="curl ${CURL_OPTS}"
CURL="curl -sS"
BRANCHES=$($CURL "${URL_RELEASES}" | jq -r 'map(.name) | .[] | scan("^[^v].+")')
VARIANTS=( "ldap" )
for BRANCH in $BRANCHES; do
# shellcheck disable=SC2068
./build.sh "${BRANCH}" $@
for var in "${VARIANTS[@]}" ; do
VARIANT=$var ./build.sh "${BRANCH}" $@

View File

@ -1,4 +1,5 @@
#!/bin/bash
# Builds the latest released version
ORIGINAL_GITHUB_REPO="digitalocean/netbox"
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
@ -6,25 +7,28 @@ URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases"
JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name"
CURL_OPTS="-s"
CURL="curl ${CURL_OPTS}"
CURL="curl -sS"
VERSION=$($CURL "${URL_RELEASES}" | jq -r "${JQ_LATEST}")
# Check if the prerelease version is actually higher than stable version
if [ "${PRERELEASE}" == "true" ]; then
JQ_STABLE="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==false) | .tag_name"
STABLE_VERSION=$(curl $CURL_OPTS "${URL_RELEASES}" | jq -r "${JQ_STABLE}")
STABLE_VERSION=$($CURL "${URL_RELEASES}" | jq -r "${JQ_STABLE}")
# shellcheck disable=SC2003
MAJOR_STABLE=$(expr match "${STABLE_VERSION}" 'v\([0-9]\+\)')
# shellcheck disable=SC2003
MINOR_STABLE=$(expr match "${STABLE_VERSION}" 'v[0-9]\+\.\([0-9]\+\)')
# shellcheck disable=SC2003
MAJOR_UNSTABLE=$(expr match "${VERSION}" 'v\([0-9]\+\)')
# 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
echo "Latest unstable version ('$VERSION') is not higher than the latest stable version ('$STABLE_VERSION')."
exit 0
echo "❎ Latest unstable version ('$VERSION') is not higher than the latest stable version ('$STABLE_VERSION')."
fi
fi
@ -41,6 +45,7 @@ ALREADY_BUILT="$($CURL -H "${AUTHORIZATION_HEADER}" "${URL_DOCKERHUB_TAG}" | jq
VARIANTS=( "ldap" )
if [ "$ALREADY_BUILT" == "false" ]; then
# shellcheck disable=SC2068
./build.sh "${VERSION}" $@
for var in "${VARIANTS[@]}" ; do
VARIANT=$var ./build.sh "${VERSION}" $@

View File

@ -1,4 +1,5 @@
#!/bin/bash
# Builds the Dockerfile[.variant] and injects tgz'ed Netbox code from Github
set -e
@ -71,6 +72,14 @@ case "${BRANCH}" in
esac
DOCKER_TAG="${DOCKER_TAG-${DOCKER_ORG}/${DOCKER_REPO}:${TAG}}"
# caching is only ok for version tags
case "${TAG}" in
v*)
CACHE="${CACHE-}";;
*)
CACHE="${CACHE---no-cache}";;
esac
# Checking which VARIANT to build
if [ -z "$VARIANT" ]; then
DOCKERFILE="Dockerfile"
@ -83,23 +92,32 @@ else
fi
fi
# caching is only ok for version tags
case "${TAG}" in
v*)
CACHE="${CACHE-}";;
*)
CACHE="${CACHE---no-cache}";;
esac
# Docker options
DOCKER_OPTS="${DOCKER_OPTS-$CACHE}"
DOCKER_OPTS=(
"$CACHE"
--pull
)
# Build args
DOCKER_BUILD_ARGS=(
--build-arg "FROM_TAG=${TAG}"
--build-arg "BRANCH=${BRANCH}"
--build-arg "URL=${URL}"
)
if [ -z "$DRY_RUN" ]; then
DOCKER_CMD="docker"
else
echo "⚠️ DRY_RUN MODE ON ⚠️"
DOCKER_CMD="echo docker"
fi
echo "🐳 Building the Docker image '${DOCKER_TAG}' from the url '${URL}'."
docker build -t "${DOCKER_TAG}" --build-arg "FROM_TAG=${TAG}" --build-arg "BRANCH=${BRANCH}" --build-arg "URL=${URL}" --pull ${DOCKER_OPTS} -f ${DOCKERFILE} .
$DOCKER_CMD build -t "${DOCKER_TAG}" "${DOCKER_BUILD_ARGS[@]}" "${DOCKER_OPTS[@]}" -f "${DOCKERFILE}" .
echo "✅ Finished building the Docker images '${DOCKER_TAG}'"
if [ "${2}" == "--push" ] ; then
echo "⏫ Pushing '${DOCKER_TAG}"
docker push "${DOCKER_TAG}"
$DOCKER_CMD push "${DOCKER_TAG}"
echo "✅ Finished pushing the Docker image '${DOCKER_TAG}'."
fi