2020-06-18 15:22:38 +02:00
|
|
|
#!/bin/bash
|
2020-08-14 14:39:01 +02:00
|
|
|
|
2020-08-14 16:21:21 +02:00
|
|
|
set -e
|
2020-08-14 14:39:01 +02:00
|
|
|
|
2020-08-14 16:21:21 +02:00
|
|
|
declare -A TARGETS
|
|
|
|
TARGETS=(
|
|
|
|
[client]="$(dirname "${BASH_SOURCE[0]}")/../client/docker/"
|
|
|
|
[server]="$(dirname "${BASH_SOURCE[0]}")/../server/docker/"
|
2020-05-28 11:40:41 +02:00
|
|
|
[haproxy]="$(dirname "${BASH_SOURCE[0]}")/../haproxy/"
|
|
|
|
[autoupdate]="$(dirname "${BASH_SOURCE[0]}")/../autoupdate/"
|
|
|
|
[media]="https://github.com/OpenSlides/openslides-media-service.git"
|
2020-08-14 16:21:21 +02:00
|
|
|
[pgbouncer]="https://github.com/OpenSlides/openslides-docker-compose.git#:pgbouncer"
|
|
|
|
[postfix]="https://github.com/OpenSlides/openslides-docker-compose.git#:postfix"
|
|
|
|
[repmgr]="https://github.com/OpenSlides/openslides-docker-compose.git#:repmgr"
|
|
|
|
)
|
|
|
|
|
|
|
|
DOCKER_REPOSITORY="openslides"
|
|
|
|
DOCKER_TAG="latest"
|
|
|
|
CONFIG="/etc/osinstancectl"
|
|
|
|
OPTIONS=()
|
|
|
|
BUILT_IMAGES=()
|
2020-05-28 11:40:41 +02:00
|
|
|
DEFAULT_TARGETS=(server client haproxy autoupdate)
|
2020-08-14 16:21:21 +02:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat << EOF
|
|
|
|
Usage: $(basename ${BASH_SOURCE[0]}) [<options>] <service>...
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-D, --docker-repo Specify a Docker repository
|
|
|
|
(default: unspecified, i.e., system default)
|
|
|
|
-t, --tag Tag the Docker image (default: $DOCKER_TAG)
|
2020-08-19 16:45:12 +02:00
|
|
|
--ask-push Offer to push newly built images to registry
|
2020-08-14 16:21:21 +02:00
|
|
|
--no-cache Pass --no-cache to docker-build
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
# Config file
|
|
|
|
if [[ -f "$CONFIG" ]]; then
|
|
|
|
echo "Found ${CONFIG} file."
|
|
|
|
source "$CONFIG"
|
|
|
|
fi
|
|
|
|
|
|
|
|
shortopt="hr:D:t:"
|
2020-08-19 16:45:12 +02:00
|
|
|
longopt="help,docker-repo:,tag:,ask-push,no-cache"
|
2020-08-14 16:21:21 +02:00
|
|
|
ARGS=$(getopt -o "$shortopt" -l "$longopt" -n "$ME" -- "$@")
|
|
|
|
if [ $? -ne 0 ]; then usage; exit 1; fi
|
|
|
|
eval set -- "$ARGS";
|
|
|
|
unset ARGS
|
|
|
|
|
|
|
|
# Parse options
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-D|--docker-repo)
|
|
|
|
DOCKER_REPOSITORY="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-t|--tag)
|
|
|
|
DOCKER_TAG="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2020-08-19 16:45:12 +02:00
|
|
|
--ask-push)
|
|
|
|
ASK_PUSH=1
|
|
|
|
shift 1
|
|
|
|
;;
|
2020-08-14 16:21:21 +02:00
|
|
|
--no-cache)
|
|
|
|
OPTIONS+="--no-cache"
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-h|--help) usage; exit 0 ;;
|
|
|
|
--) shift ; break ;;
|
|
|
|
*) usage; exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
SELECTED_TARGETS=($@)
|
|
|
|
[[ "${#SELECTED_TARGETS[@]}" -ge 1 ]] || SELECTED_TARGETS=("${DEFAULT_TARGETS[@]}")
|
|
|
|
[[ "${SELECTED_TARGETS[@]}" != "all" ]] || SELECTED_TARGETS=("${!TARGETS[@]}")
|
|
|
|
|
|
|
|
for i in "${SELECTED_TARGETS[@]}"; do
|
|
|
|
|
|
|
|
loc="${TARGETS[$i]}"
|
|
|
|
[[ -n "$loc" ]] || {
|
|
|
|
echo "ERROR: Cannot build ${i}: not configured."
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
img_name="openslides-${i}"
|
|
|
|
img="${img_name}:${DOCKER_TAG}"
|
|
|
|
if [[ -n "$DOCKER_REPOSITORY" ]]; then
|
|
|
|
img="${DOCKER_REPOSITORY}/${img}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Building $img..."
|
|
|
|
# Special instructions for local services
|
|
|
|
build_script="$(dirname "${BASH_SOURCE[0]}")/../${i}/build.sh"
|
|
|
|
if [[ -f "$build_script" ]]; then
|
2020-09-07 10:29:18 +02:00
|
|
|
( . "$build_script" )
|
2020-08-14 16:21:21 +02:00
|
|
|
else
|
|
|
|
docker build --tag "$img" --pull "${OPTIONS[@]}" "$loc"
|
|
|
|
fi
|
2020-08-19 16:45:12 +02:00
|
|
|
BUILT_IMAGES+=("$img ON")
|
2020-08-14 16:21:21 +02:00
|
|
|
done
|
|
|
|
|
2020-08-19 16:45:12 +02:00
|
|
|
if [[ "${#BUILT_IMAGES[@]}" -ge 1 ]]; then
|
|
|
|
printf "\nSuccessfully built images:\n\n"
|
|
|
|
for i in "${BUILT_IMAGES[@]}"; do
|
|
|
|
read -r img x <<< "$i"
|
|
|
|
printf " - $img\n"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "No images were built."
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
|
|
|
[[ "$ASK_PUSH" ]] || exit 0
|
|
|
|
|
2020-08-14 18:22:19 +02:00
|
|
|
if hash whiptail > /dev/null 2>&1; then
|
|
|
|
while read img; do
|
|
|
|
echo "Pushing ${img}."
|
|
|
|
docker push "$img"
|
|
|
|
done < <( whiptail --title "OpenSlides build script" \
|
|
|
|
--checklist "Select images to push to their registry." \
|
|
|
|
25 78 16 --separate-output --noitem --clear \
|
|
|
|
${BUILT_IMAGES[@]} \
|
|
|
|
3>&2 2>&1 1>&3 )
|
|
|
|
else
|
2020-08-19 16:45:12 +02:00
|
|
|
echo
|
2020-08-14 18:22:19 +02:00
|
|
|
for i in "${BUILT_IMAGES[@]}"; do
|
|
|
|
read -r img x <<< "$i"
|
2020-08-19 16:45:12 +02:00
|
|
|
read -p "Push image '$img' to repository? [Y/n] " REPL
|
|
|
|
case "$REPL" in
|
|
|
|
N|n|No|no|NO) exit 0;;
|
|
|
|
*) docker push "$img" ;;
|
|
|
|
esac
|
2020-08-14 18:22:19 +02:00
|
|
|
done
|
|
|
|
fi
|