From 6d3a65a5fcd4873257cc1337d59eca91b917a3b7 Mon Sep 17 00:00:00 2001 From: Brandon Sprague Date: Tue, 16 Jan 2024 12:30:46 -0800 Subject: [PATCH] Fix flags in local DB running script This makes the setup work for podman and un-breaks normal Docker setups, see comments in `run_db.sh` for details --- scripts/run_db.sh | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/scripts/run_db.sh b/scripts/run_db.sh index 7c91576..2647cfc 100755 --- a/scripts/run_db.sh +++ b/scripts/run_db.sh @@ -15,6 +15,12 @@ do shift done +IS_PODMAN=false +if docker --version | grep -q 'podman'; then + IS_PODMAN=true + echo "Running against podman" +fi + # Note: This is fixed by the container, changing it here will not work. For # more info, see https://hub.docker.com/_/postgres/ PG_USER="postgres" @@ -68,19 +74,28 @@ set_kv "SOCKET_DIR" "$SOCKET_DIR/sub" # Needed for rootless Podman setups mkdir -p "$SOCKET_DIR/sub" +declare -a RUN_ARGS=( + "--name" "local-postgres" + "--rm" + "--interactive" "--tty" + "--detach" + "--env" POSTGRES_PASSWORD="$PG_PASSWORD" + "--env" POSTGRES_DB="$PG_DB_NAME" + "--env" PG_DATA="$PG_DATA_PATH" + "--volume" "$SOCKET_DIR/sub:/var/run/postgresql" + "--volume" "$PG_LOCAL_DATA_PATH:$PG_DATA_PATH" +) + +# When running against podman, we use `--userns=keep-id` so that the +# `.postgres-data` directory is owned by the caller, as opposed to a mapped uid +# like 165xx. We could add an else here so that people with conventional docker +# setups don't have a root-owned .postgres/data, but we'll start with this. +if [ "$IS_PODMAN" = true ]; then + RUN_ARGS+=("--userns" "keep-id") +fi + # We turn off ports and listen solely on our Unix socket. -docker run \ - --name local-postgres \ - --userns keep-id \ - --rm \ - --interactive --tty \ - --detach \ - --env POSTGRES_PASSWORD="$PG_PASSWORD" \ - --env POSTGRES_DB="$PG_DB_NAME" \ - --env PG_DATA="$PG_DATA_PATH" \ - --volume "$SOCKET_DIR/sub:/var/run/postgresql" \ - --volume "$PG_LOCAL_DATA_PATH:$PG_DATA_PATH" \ - postgres:14.9 -c listen_addresses='' +docker run "${RUN_ARGS[@]}" postgres:14.9 -c listen_addresses='' CONTAINER_ID=$(docker ps -aqf "name=local-postgres") echo "Waiting for database to come up..."