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
3 changes: 1 addition & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"!engine/artifacts",
"!engine/sdks",
"!engine/sdks/typescript/api-full",
"!engine/sdks/typescript/runner-protocol"
"!examples/snippets",
"!engine/sdks/typescript/runner-protocol",
"!frontend",
"!rivetkit-openapi/openapi.json",
"!scripts",
Expand Down
98 changes: 98 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions scripts/run/backup-postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail

CONTAINER_NAME="rivet-engine-postgres"

if [ $# -ne 1 ]; then
echo "Usage: $0 <backup-path>"
echo "Example: $0 /path/to/backup/postgres-backup.tar.gz"
exit 1
fi

BACKUP_PATH="$1"

# Check if container exists
if ! docker ps --all --format '{{.Names}}' | grep -qw "${CONTAINER_NAME}"; then
echo "error: container '${CONTAINER_NAME}' not found"
exit 1
fi

# Get the volume name
VOLUME_NAME=$(docker inspect "${CONTAINER_NAME}" --format '{{range .Mounts}}{{if eq .Destination "/var/lib/postgresql/data"}}{{.Name}}{{end}}{{end}}')

if [ -z "${VOLUME_NAME}" ]; then
echo "error: could not find postgres data volume for container '${CONTAINER_NAME}'"
exit 1
fi

echo "Backing up postgres data from volume '${VOLUME_NAME}'..."

# Create backup directory if it doesn't exist
BACKUP_DIR="$(dirname "${BACKUP_PATH}")"
mkdir -p "${BACKUP_DIR}"

# Backup the volume data
docker run --rm \
-v "${VOLUME_NAME}":/data \
-v "${BACKUP_DIR}":/backup \
alpine \
tar czf "/backup/$(basename "${BACKUP_PATH}")" -C /data .

echo "Backup completed: ${BACKUP_PATH}"
17 changes: 15 additions & 2 deletions scripts/run/engine-postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ fi

if ! nc -z localhost 5432 >/dev/null 2>&1; then
echo "Postgres is not reachable at localhost:5432."
echo "Hint: run scripts/dev/run-postgres.sh to start the local Postgres container."
exit 1
echo "Starting postgres container..."
"${SCRIPT_DIR}/postgres.sh"

echo "Waiting for postgres to be ready..."
for i in {1..30}; do
if nc -z localhost 5432 >/dev/null 2>&1; then
echo "Postgres is ready!"
break
fi
if [ $i -eq 30 ]; then
echo "error: postgres did not become ready in time"
exit 1
fi
sleep 1
done
fi

cd "${REPO_ROOT}"
Expand Down
33 changes: 33 additions & 0 deletions scripts/run/nuke-postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail

CONTAINER_NAME="rivet-engine-postgres"

echo "Nuking postgres container and data..."

# Get the volume name before removing the container
VOLUME_NAME=""
if docker ps --all --format '{{.Names}}' | grep -qw "${CONTAINER_NAME}"; then
VOLUME_NAME=$(docker inspect "${CONTAINER_NAME}" --format '{{range .Mounts}}{{if eq .Destination "/var/lib/postgresql/data"}}{{.Name}}{{end}}{{end}}' 2>/dev/null || true)
fi

# Stop and remove container
if docker ps --all --format '{{.Names}}' | grep -qw "${CONTAINER_NAME}"; then
echo "Stopping and removing container '${CONTAINER_NAME}'..."
if docker ps --format '{{.Names}}' | grep -qw "${CONTAINER_NAME}"; then
docker stop "${CONTAINER_NAME}" >/dev/null 2>&1 || true
fi
docker rm "${CONTAINER_NAME}" >/dev/null 2>&1 || true
echo "Container removed."
else
echo "Container '${CONTAINER_NAME}' not found."
fi

# Remove volume if it exists
if [ -n "${VOLUME_NAME}" ]; then
echo "Removing volume '${VOLUME_NAME}'..."
docker volume rm "${VOLUME_NAME}" >/dev/null 2>&1 || true
echo "Volume removed."
fi

echo "Postgres nuked successfully!"
56 changes: 56 additions & 0 deletions scripts/run/restore-postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -euo pipefail

CONTAINER_NAME="rivet-engine-postgres"
POSTGRES_IMAGE="postgres:17"

if [ $# -ne 1 ]; then
echo "Usage: $0 <backup-path>"
echo "Example: $0 /path/to/backup/postgres-backup.tar.gz"
exit 1
fi

BACKUP_PATH="$1"

if [ ! -f "${BACKUP_PATH}" ]; then
echo "error: backup file '${BACKUP_PATH}' not found"
exit 1
fi

# Stop and remove existing container if it exists
if docker ps --all --format '{{.Names}}' | grep -qw "${CONTAINER_NAME}"; then
echo "Stopping and removing existing container '${CONTAINER_NAME}'..."
if docker ps --format '{{.Names}}' | grep -qw "${CONTAINER_NAME}"; then
docker stop "${CONTAINER_NAME}" >/dev/null 2>&1 || true
fi
docker rm "${CONTAINER_NAME}" >/dev/null 2>&1 || true
fi

# Create a new volume
echo "Creating new volume..."
VOLUME_NAME=$(docker volume create)
echo "Created volume: ${VOLUME_NAME}"

# Restore the data to the new volume
echo "Restoring data from '${BACKUP_PATH}'..."
BACKUP_DIR="$(dirname "${BACKUP_PATH}")"
docker run --rm \
-v "${VOLUME_NAME}":/data \
-v "${BACKUP_DIR}":/backup \
alpine \
tar xzf "/backup/$(basename "${BACKUP_PATH}")" -C /data

# Create and start the container
echo "Starting container '${CONTAINER_NAME}'..."
docker run \
--detach \
--name "${CONTAINER_NAME}" \
--publish 5432:5432 \
--env POSTGRES_PASSWORD=postgres \
--env POSTGRES_USER=postgres \
--env POSTGRES_DB=postgres \
-v "${VOLUME_NAME}":/var/lib/postgresql/data \
"${POSTGRES_IMAGE}"

echo "Restore completed successfully!"
echo "Container ID: $(docker ps -q -f name=${CONTAINER_NAME})"
Loading