build.sh: Make build script more useful

build.sh replaces docker-compose as an image build tool.  Instead, all
OpenSlides services can be built using this script which offers various
important options such as tagging and configurable defaults.

The now-redundant build instructions have been removed from the YAML
templates.

The almost identical server and client build scripts have been made
fully identical.
This commit is contained in:
Gernot Schulz 2020-08-14 16:21:21 +02:00 committed by Finn Stutzenstein
parent 9c9f268fbf
commit 418480bff5
No known key found for this signature in database
GPG Key ID: 9042F605C6324654
7 changed files with 119 additions and 31 deletions

View File

@ -28,7 +28,7 @@ First, you have to clone this repository::
You need to build the Docker images for the client and server with this
script::
$ ./build.sh
$ ./build.sh all
You must define a Django secret key in ``secrets/django.env``, for example::
@ -46,8 +46,7 @@ Afterwards, generate the configuration file::
EXTERNAL_HTTP_PORT=8000 m4 docker-compose.yml.m4 > docker-compose.yml
Once the server and client have been built, you can use ``docker-compose`` as
usual (except for the ``build`` method)::
Finally, you can start the instance using ``docker-compose``::
$ docker-compose up
$ # or:

View File

@ -1,9 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
printf "Client built on %s:\n\nBranch: %s\n\n%s\n" \
"$(date)" \
"$(git rev-parse --abbrev-ref HEAD)" \
"$(git show -s --format=raw)" > client-version.txt
docker build -f docker/Dockerfile . $@

1
client/build.sh Symbolic link
View File

@ -0,0 +1 @@
../server/build.sh

View File

@ -16,7 +16,7 @@ COPY browserslist *.json ./
COPY src ./src
RUN npm run build
COPY client-version.txt static/
COPY docker/client-version.txt static/
FROM nginx
COPY --from=nodejs /build/app/static /usr/share/nginx/html

View File

@ -1,7 +1,103 @@
#!/bin/bash
../server/build.sh -t openslides/openslides-server:latest
../client/build.sh -t openslides/openslides-client:latest
[[ -f docker-compose.yml ]] || m4 < docker-compose.yml.m4 > docker-compose.yml
set -e
docker-compose build
declare -A TARGETS
TARGETS=(
[client]="$(dirname "${BASH_SOURCE[0]}")/../client/docker/"
[server]="$(dirname "${BASH_SOURCE[0]}")/../server/docker/"
[media-service]="https://github.com/OpenSlides/openslides-media-service.git"
[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=()
DEFAULT_TARGETS=(server client)
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)
--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:"
longopt="help,docker-repo:,tag:,no-cache"
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
;;
--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
. "$build_script"
else
docker build --tag "$img" --pull "${OPTIONS[@]}" "$loc"
fi
BUILT_IMAGES+=("$img")
done
for img in "${BUILT_IMAGES[@]}"; do
read -p "Push image '$img' to repository? [y/N] " REPL
case "$REPL" in
Y|y|Yes|yes|YES)
docker push "$img" ;;
esac
done

View File

@ -48,7 +48,6 @@ x-osserver-env: &default-osserver-env
REDIS_REPLICAS: ifenvelse(`REDIS_RO_SERVICE_REPLICAS', 1)
x-pgnode: &default-pgnode
image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-repmgr:latest
build: https://github.com/OpenSlides/openslides-docker-compose.git#:repmgr
networks:
- dbnet
labels:
@ -134,7 +133,6 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `'
environment:
- PG_NODE_LIST=pgnode1`'PGBOUNCER_NODELIST
image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-pgbouncer:latest
build: https://github.com/OpenSlides/openslides-docker-compose.git#:pgbouncer
restart: always
networks:
back:
@ -144,7 +142,6 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `'
dbnet:
postfix:
image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-postfix:latest
build: https://github.com/OpenSlides/openslides-docker-compose.git#:postfix
restart: always
environment:
MYHOSTNAME: "ifenvelse(`POSTFIX_MYHOSTNAME', localhost)"
@ -177,7 +174,6 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `'
back:
media:
image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-media-service:latest
build: https://github.com/OpenSlides/openslides-media-service.git
environment:
- CHECK_REQUEST_URL=server:8000/check-media/
restart: always

View File

@ -47,7 +47,6 @@ x-osserver-env: &default-osserver-env
REDIS_REPLICAS: ifenvelse(`REDIS_RO_SERVICE_REPLICAS', 3)
x-pgnode: &default-pgnode
image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-repmgr:latest
build: https://github.com/OpenSlides/openslides-docker-compose.git#:repmgr
networks:
- dbnet
labels:
@ -141,7 +140,6 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `'
environment:
- PG_NODE_LIST=pgnode1`'PGBOUNCER_NODELIST
image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-pgbouncer:latest
build: https://github.com/OpenSlides/openslides-docker-compose.git#:pgbouncer
networks:
back:
aliases:
@ -156,7 +154,6 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `'
constraints: ifenvelse(`PGBOUNCER_PLACEMENT_CONSTR', [node.role == manager])
postfix:
image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-postfix:latest
build: https://github.com/OpenSlides/openslides-docker-compose.git#:postfix
environment:
MYHOSTNAME: "ifenvelse(`POSTFIX_MYHOSTNAME', localhost)"
RELAYHOST: "ifenvelse(`POSTFIX_RELAYHOST', localhost)"
@ -203,7 +200,6 @@ ifelse(read_env(`PGNODE_3_ENABLED'), 1, `'
delay: 5s
media:
image: ifenvelse(`DEFAULT_DOCKER_REGISTRY', openslides)/openslides-media-service:latest
build: https://github.com/OpenSlides/openslides-media-service.git
environment:
- CHECK_REQUEST_URL=server:8000/check-media/
deploy:

View File

@ -1,10 +1,19 @@
#!/bin/bash
cd "$(dirname "$0")"
cd "$(dirname "${BASH_SOURCE[0]}")"
service_name="$(basename "$PWD")"
version_file="docker/${service_name}-version.txt"
printf "Server built on %s:\n\nBranch: %s\n\n%s\n" \
"$(date)" \
"$(git rev-parse --abbrev-ref HEAD)" \
"$(git show -s --format=raw)" > docker/server-version.txt
{
printf "${service_name^} built on %s:\n\n" "$(date)"
printf "Branch: %s\n" "$(git rev-parse --abbrev-ref HEAD)"
printf '\n'
git show -s --format=raw
} > "$version_file"
docker build -f docker/Dockerfile . $@
docker build --tag "${img:-openslides/openslides-${service_name}:latest}" \
--pull "${OPTIONS[@]}" -f docker/Dockerfile .
rm "$version_file" || true
unset version_file
unset service_name