⚙️ Compact Variants Logic into build-all.sh

This commit is contained in:
Christian Mäder 2018-03-05 14:36:24 +01:00
parent e3120a715e
commit 36f79b3ffe
No known key found for this signature in database
GPG Key ID: 92FFD0A711F196BB
4 changed files with 61 additions and 16 deletions

View File

@ -19,12 +19,7 @@ after_script:
after_success: after_success:
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
- if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then - ./build-all.sh --push
./build-branches.sh --push;
./build-latest.sh --push;
PRERELEASE=true ./build-latest.sh --push;
SRC_ORG=lampwins TAG=webhooks-backend ./build.sh "feature/webhooks-backend" --push;
fi
notifications: notifications:
slack: slack:

60
build-all.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/bash
# Builds all Docker images this project provides
VARIANTS=("" "ldap")
if [ ! -z "${DEBUG}" ]; then
export DEBUG
fi
ERROR=0
# Don't build if not on `master` and don't build if on a pull request,
# but build when DEBUG is not empty
if [ ! -z "${DEBUG}" ] || \
( [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ] ); then
for VARIANT in "${VARIANTS[@]}"; do
export VARIANT
# Checking which VARIANT to build
if [ -z "$VARIANT" ]; then
DOCKERFILE="Dockerfile"
else
DOCKERFILE="Dockerfile.${VARIANT}"
# Fail fast
if [ ! -f "${DOCKERFILE}" ]; then
echo "🚨 The Dockerfile '${DOCKERFILE}' for variant '${VARIANT}' doesn't exist."
ERROR=1
if [ -z "$DEBUG" ]; then
continue
else
echo "⚠️ Would skip this, but DEBUG is enabled."
fi
fi
fi
echo "🛠 Building '$DOCKERFILE'"
# build the latest release
# shellcheck disable=SC2068
./build-latest.sh $@
# build the latest pre-release
# shellcheck disable=SC2068
PRERELEASE=true ./build-latest.sh $@
# build all branches
# shellcheck disable=SC2068
./build-branches.sh $@
# special build
# shellcheck disable=SC2068
SRC_ORG=lampwins TAG=webhooks-backend ./build.sh "feature/webhooks-backend" $@
done
else
echo "❎ Not building anything."
fi
exit $ERROR

View File

@ -9,12 +9,7 @@ CURL="curl -sS"
BRANCHES=$($CURL "${URL_RELEASES}" | jq -r 'map(.name) | .[] | scan("^[^v].+")') BRANCHES=$($CURL "${URL_RELEASES}" | jq -r 'map(.name) | .[] | scan("^[^v].+")')
VARIANTS=( "ldap" )
for BRANCH in $BRANCHES; do for BRANCH in $BRANCHES; do
# shellcheck disable=SC2068 # shellcheck disable=SC2068
./build.sh "${BRANCH}" $@ ./build.sh "${BRANCH}" $@
for var in "${VARIANTS[@]}" ; do
VARIANT=$var ./build.sh "${BRANCH}" $@
done
done done

View File

@ -46,14 +46,9 @@ URL_DOCKERHUB_TAG="https://registry.hub.docker.com/v2/${DOCKERHUB_REPO}/tags/lis
AUTHORIZATION_HEADER="Authorization: Bearer ${BEARER_TOKEN}" AUTHORIZATION_HEADER="Authorization: Bearer ${BEARER_TOKEN}"
ALREADY_BUILT="$($CURL -H "${AUTHORIZATION_HEADER}" "${URL_DOCKERHUB_TAG}" | jq -e ".tags | any(.==\"${VERSION}\")")" ALREADY_BUILT="$($CURL -H "${AUTHORIZATION_HEADER}" "${URL_DOCKERHUB_TAG}" | jq -e ".tags | any(.==\"${VERSION}\")")"
VARIANTS=( "ldap" )
if [ "$ALREADY_BUILT" == "false" ]; then if [ "$ALREADY_BUILT" == "false" ]; then
# shellcheck disable=SC2068 # shellcheck disable=SC2068
./build.sh "${VERSION}" $@ ./build.sh "${VERSION}" $@
for var in "${VARIANTS[@]}" ; do
VARIANT=$var ./build.sh "${VERSION}" $@
done
else else
echo "${VERSION} already exists on https://hub.docker.com/r/${DOCKERHUB_REPO}" echo "${VERSION} already exists on https://hub.docker.com/r/${DOCKERHUB_REPO}"
fi fi