Skip to content

Commit 8710be1

Browse files
authored
Add podman compose fallback. (#430)
1 parent 358d19a commit 8710be1

8 files changed

Lines changed: 106 additions & 17 deletions

File tree

docs-site/src/content/docs/development/contributing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ For the full-featured desktop application:
123123
3. **Start dev servers:** `npm run dev` or use `./quickstart-web.sh`
124124
4. **Connect:** Open http://localhost:5173 and manually add connection to `localhost:7001`
125125

126+
> These scripts use Docker when its daemon is running and fall back to Podman otherwise. Force a choice with `CONTAINER_ENGINE=docker` or `CONTAINER_ENGINE=podman`. See `tools/README.md` for Podman requirements.
127+
126128
### Windows/WSL Users
127129

128130
Fix line endings before running scripts:
@@ -139,6 +141,8 @@ cd tools/valkey-cluster
139141
docker compose down -v
140142
```
141143

144+
(or `podman compose down -v` if the scripts selected Podman)
145+
142146
## IDE Setup
143147

144148
### VSCode

quickstart-web.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ echo "📝 The application will open at http://localhost:5173"
3333
echo "🔌 Auto-connection to local cluster is configured"
3434
echo ""
3535
echo "💡 Cluster is running in the background"
36-
echo " - Use 'docker logs valkey-cluster-valkey-7001-1' to see cluster logs"
37-
echo " - Use 'docker compose -f tools/valkey-cluster/docker-compose.yml down -v' to stop cluster"
36+
echo " - Use '$COMPOSE_CMD -f tools/valkey-cluster/docker-compose.yml logs valkey-7001' to see cluster logs"
37+
echo " - Use '$COMPOSE_CMD -f tools/valkey-cluster/docker-compose.yml down -v' to stop cluster"
3838
echo " - Press Ctrl+C to stop development servers"
3939
echo ""
4040

quickstart.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ echo " - Name: Local Valkey Cluster"
4949
echo ""
5050
echo "💡 Cluster management:"
5151
echo " - Cluster is running in the background"
52-
echo " - Use 'docker logs valkey-cluster-valkey-7001-1' to see cluster logs"
53-
echo " - Use 'docker compose -f tools/valkey-cluster/docker-compose.yml down -v' to stop cluster"
52+
echo " - Use '$COMPOSE_CMD -f tools/valkey-cluster/docker-compose.yml logs valkey-7001' to see cluster logs"
53+
echo " - Use '$COMPOSE_CMD -f tools/valkey-cluster/docker-compose.yml down -v' to stop cluster"
5454
echo ""
5555
echo "🚀 Enjoy the full Valkey Admin experience with all features!"

scripts/common-setup.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
# Common setup functions for quickstart scripts
33

4+
# Select Docker or fall back to Podman; defines compose() and CONTAINER_ENGINE.
5+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/tools/common/container-engine.sh"
6+
47
# Function to detect platform
58
detect_platform() {
69
PLATFORM="unknown"
@@ -11,7 +14,7 @@ detect_platform() {
1114
if grep -qi microsoft /proc/version 2>/dev/null; then
1215
PLATFORM="wsl"
1316
echo "🐧 WSL (Windows Subsystem for Linux) detected"
14-
echo "Make sure Docker Desktop is running with WSL integration enabled"
17+
echo "Make sure Docker Desktop (with WSL integration) or Podman is running"
1518
else
1619
PLATFORM="linux"
1720
echo "🐧 Linux detected"
@@ -84,16 +87,17 @@ setup_cluster_env() {
8487
start_cluster() {
8588
echo "🗄️ Starting Valkey cluster in background..."
8689

87-
echo "🐳 Starting Docker containers in background..."
90+
echo "🐳 Starting containers with $CONTAINER_ENGINE in background..."
8891
cd "$TOOLS_DIR"
89-
DOCKER_PLATFORM="$DOCKER_PLATFORM" docker compose --profile populate up --build -d
92+
export DOCKER_PLATFORM
93+
compose --profile populate up --build -d
9094

91-
# Wait for cluster to be ready
95+
# Wait for cluster to be ready (stay in $TOOLS_DIR so `compose` finds the file).
9296
echo "⏳ Waiting for cluster to be ready..."
93-
cd ../..
9497

9598
for i in {1..30}; do
96-
if docker exec valkey-cluster-valkey-7001-1 valkey-cli -p 7001 cluster info 2>/dev/null | grep -q "cluster_state:ok"; then
99+
cid=$(compose ps -q valkey-7001 2>/dev/null || true)
100+
if [ -n "$cid" ] && "$CONTAINER_ENGINE" exec "$cid" valkey-cli -p 7001 cluster info 2>/dev/null | grep -q "cluster_state:ok"; then
97101
echo "✅ Cluster is ready!"
98102
break
99103
fi
@@ -104,6 +108,8 @@ start_cluster() {
104108
echo " Checking cluster health... ($i/30)"
105109
sleep 2
106110
done
111+
112+
cd ../..
107113
}
108114

109115
# Function to run common setup steps

tools/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
### Run Sample Instances of Valkey Cluster or Standalone
22

3-
Docker is a prerequisite as these are Docker containers.
3+
Docker **or Podman** is a prerequisite. The scripts prefer Docker when its daemon is running and fall back to Podman otherwise; force a choice with `CONTAINER_ENGINE=docker` or `CONTAINER_ENGINE=podman`.
44

55
From root run:
66

77
`./tools/valkey-standalone/build_run_standalone.sh` for a standalone instance populated with seed data.
88

99
`./tools/valkey-cluster/scripts/build_run_cluster.sh` for a cluster instance populated with seed data.
1010

11+
#### Podman notes
12+
13+
Podman 4.x or newer is recommended, and the `podman compose` Compose v2 provider is required (the `podman-compose` v1 tool is not supported). On macOS, run `podman machine start` first. Machines with the `podman-docker` shim are detected as Docker, which works fine.
14+
1115
### Logical databases
1216

1317
Both stacks expose **16 logical databases** by default. The cluster stack passes `--cluster-databases 16` to every node, and the standalone stack passes `--databases 16`. The `populate.mjs` scripts iterate every configured database and seed each one with the typed sample dataset (string, list, set, hash, sorted set, geo, bitmap, stream) plus a bulk string load.
@@ -33,6 +37,8 @@ POPULATE_DB_COUNT=4 POPULATE_BULK_KEYS=1000 \
3337
--profile populate run --rm populate
3438
```
3539

40+
With Podman, substitute `podman compose` for `docker compose`.
41+
3642
#### Cluster Valkey 9+ baseline
3743

3844
Multiple logical databases on a Valkey **cluster** require Valkey 9.0.0 or newer. The bundled Compose files use `valkey/valkey:latest`, which satisfies the baseline. If you pin an older tag, pin `valkey/valkey:9.0` or newer — otherwise the cluster populate script exits non-zero before issuing any write to a database greater than `0`, naming the detected version and the required baseline.

tools/common/container-engine.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
# Container engine selection: prefers Docker, falls back to Podman.
3+
# Source this file (`. .../container-engine.sh`); it defines compose() and
4+
# exports CONTAINER_ENGINE (docker|podman) and COMPOSE_CMD (display string).
5+
# Force a specific engine with CONTAINER_ENGINE=docker|podman.
6+
7+
_engine_alive() {
8+
command -v "$1" >/dev/null 2>&1 && "$1" info >/dev/null 2>&1
9+
}
10+
11+
case "${CONTAINER_ENGINE:-}" in
12+
docker|podman)
13+
if ! _engine_alive "$CONTAINER_ENGINE"; then
14+
echo "Error: CONTAINER_ENGINE=$CONTAINER_ENGINE requested, but '$CONTAINER_ENGINE info' failed. Is it installed and running?" >&2
15+
exit 1
16+
fi
17+
;;
18+
"")
19+
if _engine_alive docker; then
20+
CONTAINER_ENGINE=docker
21+
elif _engine_alive podman; then
22+
CONTAINER_ENGINE=podman
23+
else
24+
echo "Error: no working container engine found." >&2
25+
echo " - Docker: install Docker Desktop / docker-ce and start the daemon." >&2
26+
echo " - Podman: install podman (on macOS also run 'podman machine start')." >&2
27+
exit 1
28+
fi
29+
;;
30+
*)
31+
echo "Error: unsupported CONTAINER_ENGINE '$CONTAINER_ENGINE' (expected 'docker' or 'podman')." >&2
32+
exit 1
33+
;;
34+
esac
35+
36+
if [ "$CONTAINER_ENGINE" = "docker" ]; then
37+
if docker compose version >/dev/null 2>&1; then
38+
COMPOSE_CMD="docker compose"
39+
else
40+
echo "Error: 'docker compose' (Compose v2 plugin) is not available." >&2
41+
exit 1
42+
fi
43+
else
44+
if podman compose version >/dev/null 2>&1; then
45+
COMPOSE_CMD="podman compose"
46+
else
47+
echo "Error: podman found, but 'podman compose' is not available. Install the docker-compose v2 provider that 'podman compose' delegates to." >&2
48+
exit 1
49+
fi
50+
fi
51+
52+
export CONTAINER_ENGINE COMPOSE_CMD
53+
54+
compose() {
55+
# shellcheck disable=SC2086 # intentional word-split of a fixed known string
56+
$COMPOSE_CMD "$@"
57+
}
58+
59+
echo "Using container engine: $CONTAINER_ENGINE (compose: $COMPOSE_CMD)"

tools/valkey-cluster/scripts/build_run_cluster.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
77
# Go up three levels to find the project root.
88
PROJECT_ROOT=$(dirname -- "$(dirname -- "$(dirname -- "$SCRIPT_DIR")")")
99

10+
# Select Docker or fall back to Podman; defines compose() and CONTAINER_ENGINE.
11+
. "$PROJECT_ROOT/tools/common/container-engine.sh"
12+
1013
# Define all paths as absolute paths from the project root.
1114
TOOLS_DIR="$PROJECT_ROOT/tools/valkey-cluster"
1215
ENV_FILE="$TOOLS_DIR/.env"
@@ -35,7 +38,7 @@ ARCH=$(uname -m)
3538
# Force ARM64 platform since rejson.so is ARM64 and works with emulation
3639
DOCKER_PLATFORM="linux/arm64"
3740

38-
echo "Detected architecture: $ARCH, using Docker platform: $DOCKER_PLATFORM (forced for rejson.so compatibility)"
41+
echo "Detected architecture: $ARCH, using container platform: $DOCKER_PLATFORM (forced for rejson.so compatibility)"
3942

4043
# Use sed without the '' flag for Linux compatibility
4144
if [ "$(uname)" = "Darwin" ]; then
@@ -52,4 +55,5 @@ cd "$TOOLS_DIR"
5255
echo "Starting Valkey cluster..."
5356
echo "Keep this terminal open to monitor cluster logs"
5457
echo ""
55-
DOCKER_PLATFORM="$DOCKER_PLATFORM" docker compose --profile populate up --build
58+
export DOCKER_PLATFORM
59+
compose --profile populate up --build

tools/valkey-standalone/build_run_standalone.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ set -eu
44
# Resolve script directory so docker-compose can find ./docker-compose.yml regardless of cwd.
55
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
66

7+
# Select Docker or fall back to Podman; defines compose() and CONTAINER_ENGINE.
8+
. "$SCRIPT_DIR/../common/container-engine.sh"
9+
710
# Get IP address - works on both macOS and Linux/WSL
811
if command -v ipconfig >/dev/null 2>&1; then
912
# macOS
@@ -23,14 +26,21 @@ cd "$SCRIPT_DIR"
2326
# Defensive cleanup: the previous version of this script created a container with
2427
# `docker run --name valkey-standalone`. If that stale container still exists on a
2528
# user's machine, it would collide with `container_name: valkey-standalone` below.
26-
docker rm -f valkey-standalone >/dev/null 2>&1 || true
29+
"$CONTAINER_ENGINE" rm -f valkey-standalone >/dev/null 2>&1 || true
2730

2831
echo "Starting Valkey instance on port 6379..."
29-
docker compose up -d --build --wait valkey-standalone
32+
# Poll for health instead of `compose up --wait` (a docker-compose-v2-only flag).
33+
compose up -d --build valkey-standalone
34+
for i in $(seq 1 30); do
35+
status=$("$CONTAINER_ENGINE" inspect --format '{{.State.Health.Status}}' valkey-standalone 2>/dev/null || true)
36+
[ "$status" = "healthy" ] && break
37+
[ "$i" -eq 30 ] && { echo "Error: valkey-standalone did not become healthy." >&2; exit 1; }
38+
sleep 2
39+
done
3040

3141
echo "Populating Valkey with test data..."
32-
docker compose --profile populate run --rm populate
42+
compose --profile populate run --rm populate
3343

3444
echo ""
3545
echo "Done! Valkey instance running on $ANNOUNCE_IP:6379 (also reachable on localhost:6379)"
36-
echo "To stop and clean up: docker compose -f tools/valkey-standalone/docker-compose.yml down -v"
46+
echo "To stop and clean up: $COMPOSE_CMD -f tools/valkey-standalone/docker-compose.yml down -v"

0 commit comments

Comments
 (0)