From 36f79b3ffe0d2ff759eeee224996b9937f65c8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Mon, 5 Mar 2018 14:36:24 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Compact=20Variants=20Logic?= =?UTF-8?q?=20into=20build-all.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 7 +----- build-all.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++ build-branches.sh | 5 ---- build-latest.sh | 5 ---- 4 files changed, 61 insertions(+), 16 deletions(-) create mode 100755 build-all.sh diff --git a/.travis.yml b/.travis.yml index b7d537e..484a947 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,12 +19,7 @@ after_script: after_success: - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" - - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then - ./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 + - ./build-all.sh --push notifications: slack: diff --git a/build-all.sh b/build-all.sh new file mode 100755 index 0000000..54e2711 --- /dev/null +++ b/build-all.sh @@ -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 diff --git a/build-branches.sh b/build-branches.sh index 647b517..bbd07f2 100755 --- a/build-branches.sh +++ b/build-branches.sh @@ -9,12 +9,7 @@ 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}" $@ - done done diff --git a/build-latest.sh b/build-latest.sh index 3a82577..d5728b6 100755 --- a/build-latest.sh +++ b/build-latest.sh @@ -46,14 +46,9 @@ URL_DOCKERHUB_TAG="https://registry.hub.docker.com/v2/${DOCKERHUB_REPO}/tags/lis AUTHORIZATION_HEADER="Authorization: Bearer ${BEARER_TOKEN}" ALREADY_BUILT="$($CURL -H "${AUTHORIZATION_HEADER}" "${URL_DOCKERHUB_TAG}" | jq -e ".tags | any(.==\"${VERSION}\")")" -VARIANTS=( "ldap" ) - if [ "$ALREADY_BUILT" == "false" ]; then # shellcheck disable=SC2068 ./build.sh "${VERSION}" $@ - for var in "${VARIANTS[@]}" ; do - VARIANT=$var ./build.sh "${VERSION}" $@ - done else echo "✅ ${VERSION} already exists on https://hub.docker.com/r/${DOCKERHUB_REPO}" fi