nodepool/tools/test-setup-docker.sh
Jeremy Stanley dfdf9d3684 Run docker-compose up test setup script with env
When not using a ROOTCMD when running the test-setup-docker.sh the
script will fail with the following error message:

    ++ id -u
    + USER_ID=1000 docker-compose up -d
    ./test-setup-docker.sh: line 50: USER_ID=1000: command not found

Due to Bash's simple command expansion[0] variable assignments will
be interpreted as the command when no ROOTCMD is given. To work
around this we use default ROOTCMD to the `env` command.

[0]: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Simple-Command-Expansion

Change-Id: I3e4dd844efae8971d9ba83060a7134f1f1f0e770
Co-Authored-By: Simon Westphahl <simon.westphahl@bmw.de>
2022-08-23 12:38:17 +00:00

53 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# This runs ZooKeeper in a docker container, which is required for
# tests.
# This setup needs to be run as a user that can run docker or podman, or by
# setting $ROOTCMD to a user substitution tool like "sudo" in the calling
# environment.
set -xeu
# Default ROOTCMD to the 'env' command, otherwise variable assignments will be
# interpreted as command when no ROOTCMD is given. The reason for that is
# Bash's simple command expansion.
ROOTCMD=${ROOTCMD:-env}
cd $(dirname $0)
SCRIPT_DIR="$(pwd)"
# Select docker or podman
if command -v docker > /dev/null; then
DOCKER=docker
if ! ${ROOTCMD} docker ps; then
${ROOTCMD} systemctl start docker
fi
elif command -v podman > /dev/null; then
DOCKER=podman
else
echo "Please install docker or podman."
exit 1
fi
# Select docker-compose or podman-compose
if command -v docker-compose > /dev/null; then
COMPOSE=docker-compose
elif command -v podman-compose > /dev/null; then
COMPOSE=podman-compose
else
echo "Please install docker-compose or podman-compose."
exit 1
fi
CA_DIR=$SCRIPT_DIR/ca
mkdir -p $CA_DIR
$SCRIPT_DIR/zk-ca.sh $CA_DIR nodepool-test-zookeeper
${ROOTCMD} ${COMPOSE} down
${ROOTCMD} ${COMPOSE} up -d
echo "Finished"