Skip to content

Commit 0fa3f60

Browse files
committed
PCSM-202: Add 3-shard local dev environment
- Add third shard (rs2) to source cluster in hack/sh - Disable keyFile authentication for local development to avoid Docker volume permission issues - Remove keyFile and user creation scripts - Add cleanup.sh script for environment teardown - Add /tmp/ to .gitignore for demo artifacts
1 parent 6fec171 commit 0fa3f60

File tree

23 files changed

+115
-141
lines changed

23 files changed

+115
-141
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
.env
1010

1111
/bin/
12+
/tmp/
1213
vendor/
1314

1415
.pytest_cache

hack/cleanup.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
# Clean up Docker resources for test environments
3+
# Removes: containers, volumes, networks
4+
#
5+
# Usage: ./cleanup.sh [ENV...]
6+
# (no args) Clean all (rs, sh, sh-ha)
7+
# rs Replica set only
8+
# sh Sharded cluster only (3→2 shards, project: s1)
9+
# sh-ha Sharded cluster HA only
10+
#
11+
# Example:
12+
# ./cleanup.sh rs sh # rs and sh
13+
14+
set -euo pipefail
15+
16+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
17+
ENVS_TO_CLEAN=()
18+
19+
if [[ $# -eq 0 ]]; then
20+
ENVS_TO_CLEAN=("rs" "sh" "sh-ha")
21+
else
22+
while [[ $# -gt 0 ]]; do
23+
case $1 in
24+
rs|sh|sh-ha)
25+
ENVS_TO_CLEAN+=("$1")
26+
shift
27+
;;
28+
*)
29+
echo "Unknown environment: $1"
30+
echo "Valid: rs, sh, sh-ha"
31+
exit 1
32+
;;
33+
esac
34+
done
35+
fi
36+
37+
# Function to clean up a compose environment
38+
cleanup_env() {
39+
local name=$1
40+
local compose_file=$2
41+
local project_name=${3:-}
42+
43+
if [[ ! -f "$compose_file" ]]; then
44+
echo "Skipping $name (compose file not found)"
45+
return
46+
fi
47+
48+
echo "Cleaning $name..."
49+
50+
local compose_cmd="docker compose -f $compose_file"
51+
if [[ -n "$project_name" ]]; then
52+
compose_cmd="docker compose -p $project_name -f $compose_file"
53+
fi
54+
55+
# Stop and remove containers, then remove volumes
56+
$compose_cmd down --remove-orphans 2>/dev/null || true
57+
$compose_cmd down -v 2>/dev/null || true
58+
}
59+
60+
# Clean specified environments
61+
for env in "${ENVS_TO_CLEAN[@]}"; do
62+
case $env in
63+
rs)
64+
cleanup_env "rs" "$SCRIPT_DIR/rs/compose.yml"
65+
docker volume ls -q | grep -E '^rs[0-9]+' | xargs -r docker volume rm 2>/dev/null || true
66+
;;
67+
sh)
68+
cleanup_env "sh" "$SCRIPT_DIR/sh/compose.yml" "s1"
69+
docker volume ls -q | grep -E '^(src-|tgt-|s1_)' | xargs -r docker volume rm 2>/dev/null || true
70+
;;
71+
sh-ha)
72+
cleanup_env "sh-ha" "$SCRIPT_DIR/sh-ha/compose.yml" "s1"
73+
docker volume ls -q | grep -E '^s1_' | xargs -r docker volume rm 2>/dev/null || true
74+
;;
75+
esac
76+
done
77+
78+
echo "Done."

hack/rs/mongo/keyFile

Lines changed: 0 additions & 16 deletions
This file was deleted.

hack/rs/mongo/users.adm.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

hack/rs/mongo/users.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

hack/rs/run.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ RDIR="$BASE/rs"
99

1010
export compose="$RDIR/compose.yml"
1111

12-
# https://www.mongodb.com/docs/v7.0/tutorial/deploy-sharded-cluster-with-keyfile-access-control/
13-
if [ ! -s "$RDIR/mongo/keyFile" ]; then
14-
echo >&2 generate "$RDIR/mongo/keyFile"
15-
openssl rand -base64 756 >"$RDIR/mongo/keyFile"
16-
chmod 400 "$RDIR/mongo/keyFile"
17-
fi
18-
1912
dcf up -d rs00 rs01 rs02 rs10 rs11 rs12
2013

2114
mwait "rs00:30000"

hack/sh-ha/mongo/configsvr.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ systemLog.quiet: true
22
net.bindIpAll: true
33
storage.dbPath: /data/db
44
sharding.clusterRole: configsvr
5-
security.keyFile: /cfg/keyFile

hack/sh-ha/mongo/keyFile

Lines changed: 0 additions & 16 deletions
This file was deleted.

hack/sh-ha/mongo/mongos.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
systemLog.quiet: true
22
net.bindIpAll: true
3-
security.keyFile: /cfg/keyFile

hack/sh-ha/mongo/shardsvr.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ systemLog.quiet: true
22
net.bindIpAll: true
33
storage.dbPath: /data/db
44
sharding.clusterRole: shardsvr
5-
security.keyFile: /cfg/keyFile

0 commit comments

Comments
 (0)