debian-forge-composer/internal/upload/koji/run-koji-container.sh
Ondřej Budai c9d7892ec0 upload/koji: reorganize run-koji-container script
run-koji-container has now two actions: start and stop:
- ./run-koji-container.sh start
- ./run-koji-container.sh stop

The start action starts all containers. When it exits, all containers are
started and running in the background. To stop and removethem, use the stop
action.

This change is needed so we're able to easily use this script also in the CI
environment.
2020-08-27 17:29:57 +01:00

79 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
set -eu
koji_stop () {
echo "Shutting down containers, please wait..."
${CONTAINER_RUNTIME} stop org.osbuild.koji.koji || true
${CONTAINER_RUNTIME} rm org.osbuild.koji.koji || true
${CONTAINER_RUNTIME} stop org.osbuild.koji.postgres || true
${CONTAINER_RUNTIME} rm org.osbuild.koji.postgres || true
${CONTAINER_RUNTIME} network rm -f org.osbuild.koji || true
}
koji_clean_up_bad_start () {
EXIT_CODE=$?
echo "Start failed, removing containers."
koji_stop
exit $EXIT_CODE
}
koji_start() {
trap koji_clean_up_bad_start EXIT
${CONTAINER_RUNTIME} network create org.osbuild.koji
${CONTAINER_RUNTIME} run -d --name org.osbuild.koji.postgres --network org.osbuild.koji \
-e POSTGRES_USER=koji \
-e POSTGRES_PASSWORD=kojipass \
-e POSTGRES_DB=koji \
docker.io/library/postgres:12-alpine
${CONTAINER_RUNTIME} run -d --name org.osbuild.koji.koji --network org.osbuild.koji \
-p 8080:80 \
-e POSTGRES_USER=koji \
-e POSTGRES_PASSWORD=kojipass \
-e POSTGRES_DB=koji \
-e POSTGRES_HOST=org.osbuild.koji.postgres \
quay.io/osbuild/ghci-koji:v1
echo "Containers are running, to stop them use:"
echo "$0 stop"
trap - EXIT
}
if [[ $# -ne 1 || ( "$1" != "start" && "$1" != "stop" ) ]]; then
cat <<DOC
usage: $0 start|stop
start - starts the koji containers
stop - stops and removes the koji containers
DOC
exit 3
fi
if [ $UID != 0 ]; then
echo This script must be run as root.
exit 1
fi
if which podman 2>/dev/null >&2; then
CONTAINER_RUNTIME=podman
elif which docker 2>/dev/null >&2; then
CONTAINER_RUNTIME=docker
else
echo No container runtime found, install podman or docker.
exit 2
fi
if [ $1 == "start" ]; then
koji_start
fi
if [ $1 == "stop" ]; then
koji_stop
fi