Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM ${BASE_IMAGE}
# #!/usr/bin/env -S nix develop --accept-flake-config .#base -c bash
# Busybox env does not support -S and would fail with "unrecognized option".
RUN if command -v apk > /dev/null 2>&1; then \
apk add --no-cache bash coreutils; \
apk add --no-cache bash coreutils shadow; \
fi

# Install ca-certificates on Debian-based images.
Expand Down
24 changes: 21 additions & 3 deletions runner/source_dbsync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ stop_postgres() {
local psql_pid
psql_pid="$(<"$psql_pid_file")"
for _ in {1..5}; do
if ! kill "$psql_pid"; then
if ! kill "$psql_pid" 2>/dev/null; then
break
fi
sleep 1
Expand Down Expand Up @@ -153,8 +153,26 @@ export PGHOST=localhost
export PGUSER=postgres
export PGPORT=5432

# start and setup postgres
./scripts/postgres-start.sh "$WORKDIR/postgres" -k
# Start and setup postgres
if [ "$UID" -eq 0 ]; then
# If running as root, which is the case for containers, create a postgres user because postgres cannot run as root
if ! id -u postgres >/dev/null 2>&1; then
useradd -m -s /bin/sh postgres
fi

mkdir -p "$WORKDIR/postgres"
chown postgres:postgres "$WORKDIR/postgres"
# shellcheck disable=SC2016
REPODIR="$REPODIR" WORKDIR="$WORKDIR" SU="$(command -v su)" nix develop \
--accept-flake-config .#postgres -i -k PGHOST -k PGPORT -k PGUSER -k REPODIR -k WORKDIR -k SU --command bash -c '
"$SU" postgres -c "PATH=\"$PATH\" \"$REPODIR/scripts/postgres-start.sh\" \"$WORKDIR/postgres\" -k"
' || {
echo "Failed to start postgres as postgres user, line $LINENO in sourced db-sync setup" >&2 # assert
exit 1
}
else
./scripts/postgres-start-nix.sh "$WORKDIR/postgres" -k
fi

cd "$_origpwd" || exit 1
unset _origpwd
5 changes: 5 additions & 0 deletions scripts/postgres-start-nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /usr/bin/env -S nix develop --accept-flake-config .#postgres -i -k PGHOST -k PGPORT -k PGUSER -c bash
# shellcheck shell=bash

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
exec "$SCRIPT_DIR/postgres-start.sh" "$@"
3 changes: 1 addition & 2 deletions scripts/postgres-start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env -S nix develop --accept-flake-config .#postgres -i -k PGHOST -k PGPORT -k PGUSER -c bash
# shellcheck shell=bash
#!/usr/bin/env bash

set -Eeuo pipefail
trap 'echo "Error at line $LINENO"' ERR
Expand Down
4 changes: 2 additions & 2 deletions testnets_bootstrap_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ Running db-sync
* If you **do not** already have a database and snapshot for the given testnet, start Postgres with a clean database:

```sh
/path/to/cardano-node-tests-repo/scripts/postgres-start.sh ~/tmp/postgres-for-testnet/ -k
/path/to/cardano-node-tests-repo/scripts/postgres-start-nix.sh ~/tmp/postgres-for-testnet/ -k
./postgres-setup.sh
```

* If you **do** already have a database and snapshot, start Postgres using the existing data:

```sh
/path/to/cardano-node-tests-repo/scripts/postgres-start.sh ~/tmp/postgres-for-testnet/
/path/to/cardano-node-tests-repo/scripts/postgres-start-nix.sh ~/tmp/postgres-for-testnet/
```

* Start db-sync **only after the node is fully synced**:
Expand Down