Refactor to multistage builds
This commit introduces a huge change in the build process. What changed: - Dockerfile.ldap was integrated into Dockerfile as a seperate [build stage][multistage-build]. - All the build scripts were refactored according to this. - The `docker-compose.yml` file was adjusted likewise. - The main build script, `/build.sh`, now always builds all targets (formerly called variants). - The minimal requirements for Docker and docker-compose have increased. - The build on hub.docker.com must be adjusted. This change should also fix #156 permanently. [multistage-build]: https://docs.docker.com/develop/develop-images/multistage-build/
This commit is contained in:
parent
c148d3ceb9
commit
d0ebb34432
11 changed files with 259 additions and 246 deletions
46
hooks/common
46
hooks/common
|
@ -1,37 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
ensure_jq() {
|
||||
echo "🛠🛠🛠 Installing JQ via apt-get"
|
||||
[ -x "$(command -v jq)" ] || ( apt-get update && apt-get install -y jq )
|
||||
}
|
||||
|
||||
ensure_dockerfile_present() {
|
||||
if [ "${VARIANT}" == "main" ]; then
|
||||
DOCKERFILE="Dockerfile"
|
||||
else
|
||||
DOCKERFILE="Dockerfile.${VARIANT}"
|
||||
|
||||
# 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 skip this, but DEBUG is enabled."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${DOCKERFILE}" != "${DOCKERFILE_PATH}" ]; then
|
||||
echo "⚠️ The specified Dockerfile '${DOCKERFILE_PATH}' does not match the expected Dockerfile '${DOCKERFILE}'."
|
||||
echo " This script will use '${DOCKERFILE}' and ignore '${DOCKERFILE_PATH}'."
|
||||
if [ ! -x "$(command -v jq)" ]; then
|
||||
if [ ! -x "$(command -v apt-get)" ]; then
|
||||
echo "🛠🛠🛠 Installing 'jq' via 'apt-get'"
|
||||
apt-get update && apt-get install -y jq
|
||||
else
|
||||
echo "⚠️⚠️⚠️ apt-get not found, unable to automatically install 'jq'."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Passes args to the scripts
|
||||
run_build() {
|
||||
echo "🐳🐳🐳 Building '${BUILD}' images, the '${VARIANT:-main}' variant"
|
||||
echo "🐳🐳🐳 Building '${BUILD}' images"
|
||||
case $BUILD in
|
||||
release)
|
||||
# build the latest release
|
||||
|
@ -48,12 +30,6 @@ run_build() {
|
|||
# shellcheck disable=SC2068
|
||||
./build-branches.sh $@
|
||||
;;
|
||||
special)
|
||||
# special build
|
||||
# shellcheck disable=SC2068
|
||||
#SRC_ORG=lampwins TAG=webhooks-backend ./build.sh "feature/webhooks-backend" $@
|
||||
echo "✅ No special builds today."
|
||||
;;
|
||||
*)
|
||||
echo "🚨 Unrecognized build '$BUILD'."
|
||||
|
||||
|
@ -70,13 +46,9 @@ echo "🤖🤖🤖 Preparing build"
|
|||
export DOCKER_ORG="index.docker.io/netboxcommunity"
|
||||
export DOCKER_REPO=netbox
|
||||
export DOCKERHUB_REPO=netboxcommunity/netbox
|
||||
|
||||
# mis-using the "${DOCKER_TAG}" variable as "branch to build"
|
||||
export BUILD="${DOCKER_TAG%-*}"
|
||||
export VARIANT="${DOCKER_TAG#*-}"
|
||||
# shellcheck disable=SC2153
|
||||
export BUILD="$DOCKER_TAG"
|
||||
|
||||
unset DOCKER_TAG
|
||||
|
||||
ensure_dockerfile_present
|
||||
|
||||
ensure_jq
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
. hooks/common
|
||||
|
||||
if [ "${VARIANT}" == "main" ] && [ "${BUILD}" == "BRANCHES" ]; then
|
||||
if [ "${BUILD}" == "BRANCHES" ]; then
|
||||
echo "🐳🐳🐳 Testing"
|
||||
export DOCKER_TARGET="main"
|
||||
|
||||
docker-compose pull --parallel
|
||||
docker-compose build
|
||||
docker-compose run netbox ./manage.py test
|
||||
else
|
||||
echo "🐳🐳🐳 No tests are implemented for build '${BUILD}' with variant '${VARIANT}'."
|
||||
echo "🐳🐳🐳 No tests are implemented for build '${BUILD}'."
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue