upload/koji: make koji runner work with docker

The setup should be container engine agnostic. This changes allows this script
to be run on systems which prefer docker over podman (e.g. Github Actions).
This commit is contained in:
Ondřej Budai 2020-08-26 10:10:28 +02:00 committed by Tom Gundersen
parent 963e46f50d
commit a32ff633ba

View file

@ -2,36 +2,45 @@
set -eu
if [ $UID != 0 ]; then
echo must be run as root
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
clean_up () {
EXIT_CODE=$?
echo "Shutting down containers, please wait..."
podman stop org.osbuild.koji.koji || true
podman rm org.osbuild.koji.koji || true
${CONTAINER_RUNTIME} stop org.osbuild.koji.koji || true
${CONTAINER_RUNTIME} rm org.osbuild.koji.koji || true
podman stop org.osbuild.koji.postgres || true
podman rm org.osbuild.koji.postgres || true
${CONTAINER_RUNTIME} stop org.osbuild.koji.postgres || true
${CONTAINER_RUNTIME} rm org.osbuild.koji.postgres || true
podman network rm -f org.osbuild.koji || true
${CONTAINER_RUNTIME} network rm -f org.osbuild.koji || true
exit $EXIT_CODE
}
trap clean_up EXIT
podman network create org.osbuild.koji
podman run -d --name org.osbuild.koji.postgres --network org.osbuild.koji \
${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
podman run -d --name org.osbuild.koji.koji --network org.osbuild.koji \
${CONTAINER_RUNTIME} run -d --name org.osbuild.koji.koji --network org.osbuild.koji \
-p 8080:80 \
-e POSTGRES_USER=koji \
-e POSTGRES_PASSWORD=kojipass \