Skip to content

Commit 73cece2

Browse files
authored
PCSM-202: Cleanup local dev environment (#155)
PCSM-202: Make local sharded cluster setup configurable Add flexible shard configuration to hack/sh environment with support for asymmetric cluster testing (different shard counts between source and target). Also remove authentication from all local dev environments to simplify setup and avoid Docker volume permission issues. Authentication removal (all environments: rs, sh, sh-ha): Remove keyFile files and keyFile config from all *.conf files Remove users.adm.js and users.js user creation scripts Update hack/util rsinit function to skip user creation Remove auth prefixes (adm:pass@) from all mongosh calls Fix hack/cleanup.sh to handle sh-ha environment properly Configurable shard setup (hack/sh): Make run.sh configurable via SRC_SHARDS and TGT_SHARDS env vars Default: 2 shards each (changed from hardcoded 3→2) Maximum: 3 shards each (validated against available init scripts) Dynamic service startup and initialization loops Usage documentation in script header Add third shard support for both source and target Create hack/sh/mongo/src/rs2.js init script Create hack/sh/mongo/tgt/rs2.js init script Add src-rs20 and tgt-rs20 services/volumes to compose.yml Add hack/cleanup.sh script for environment teardown Add /tmp/ to .gitignore for demo artifacts Test configurations now supported: 1→1, 2→2, 3→3 shards (symmetric) 3→2, 2→3 shards (asymmetric, for PCSM-202 testing) Any combination from 1-3 shards per cluster Usage examples: ./hack/sh/run.sh # 2→2 (default) SRC_SHARDS=3 TGT_SHARDS=2 ./hack/sh/run.sh # 3→2 SRC_SHARDS=2 TGT_SHARDS=3 ./hack/sh/run.sh # 2→3 SRC_SHARDS=1 TGT_SHARDS=1 ./hack/sh/run.sh # 1→1
1 parent 288a42b commit 73cece2

32 files changed

+233
-208
lines changed

.github/workflows/e2etests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646
4747
- name: Run tests (pytest)
4848
run: |
49-
export TEST_SOURCE_URI=mongodb://adm:pass@rs00:30000
50-
export TEST_TARGET_URI=mongodb://adm:pass@rs10:30100
49+
export TEST_SOURCE_URI=mongodb://rs00:30000
50+
export TEST_TARGET_URI=mongodb://rs10:30100
5151
export TEST_PCSM_URL=http://127.0.0.1:2242
5252
export TEST_PCSM_BIN=./bin/pcsm_test
5353
@@ -96,8 +96,8 @@ jobs:
9696
9797
- name: Run tests (pytest)
9898
run: |
99-
export TEST_SOURCE_URI=mongodb://adm:pass@src-mongos:27017
100-
export TEST_TARGET_URI=mongodb://adm:pass@tgt-mongos:29017
99+
export TEST_SOURCE_URI=mongodb://src-mongos:27017
100+
export TEST_TARGET_URI=mongodb://tgt-mongos:29017
101101
export TEST_PCSM_URL=http://127.0.0.1:2242
102102
export TEST_PCSM_BIN=./bin/pcsm_test
103103

.github/workflows/rs/mongo/users.adm.js

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

.github/workflows/rs/mongo/users.js

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

.github/workflows/rs/util

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,5 @@ rsinit() {
5151
echo "uninitialized primary: $1"
5252
exit 1
5353
fi
54-
msh "$2" "/cfg/users.adm.js"
55-
msh "adm:pass@$2" "/cfg/users.js"
56-
msh "adm:pass@$2" "/cfg/scripts/deprioritize.js"
54+
msh "$2" "/cfg/scripts/deprioritize.js"
5755
}

.github/workflows/sh/mongo/users.adm.js

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

.github/workflows/sh/mongo/users.js

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

.github/workflows/sh/run

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ mwait "src-rs00:30000" && rsinit "src/rs0" "src-rs00:30000"
1313
mwait "src-rs10:30100" && rsinit "src/rs1" "src-rs10:30100"
1414

1515
dcf up -d src-mongos && mwait "src-mongos:27017"
16-
msh "adm:pass@src-mongos:27017" --eval "
16+
msh "src-mongos:27017" --eval "
1717
sh.addShard('rs0/src-rs00:30000'); //
1818
sh.addShard('rs1/src-rs10:30100');
1919
"
20-
msh "adm:pass@src-mongos:27017" --eval "db.adminCommand('transitionFromDedicatedConfigServer');"
20+
msh "src-mongos:27017" --eval "db.adminCommand('transitionFromDedicatedConfigServer');"
2121

2222
dcf up -d tgt-cfg0 tgt-rs00 tgt-rs10
2323

@@ -26,8 +26,8 @@ mwait "tgt-rs00:40000" && rsinit "tgt/rs0" "tgt-rs00:40000"
2626
mwait "tgt-rs10:40100" && rsinit "tgt/rs1" "tgt-rs10:40100"
2727

2828
dcf up -d tgt-mongos && mwait "tgt-mongos:27017"
29-
msh "adm:pass@tgt-mongos:27017" --eval "
29+
msh "tgt-mongos:27017" --eval "
3030
sh.addShard('rs0/tgt-rs00:40000'); //
3131
sh.addShard('rs1/tgt-rs10:40100');
3232
"
33-
msh "adm:pass@tgt-mongos:27017" --eval "db.adminCommand('transitionFromDedicatedConfigServer');"
33+
msh "tgt-mongos:27017" --eval "db.adminCommand('transitionFromDedicatedConfigServer');"

.github/workflows/sh/util

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,5 @@ rsinit() {
5555
echo "uninitialized primary: $1"
5656
exit 1
5757
fi
58-
msh "$2" "/cfg/users.adm.js"
59-
msh "adm:pass@$2" "/cfg/users.js"
60-
msh "adm:pass@$2" "/cfg/scripts/deprioritize.js"
58+
msh "$2" "/cfg/scripts/deprioritize.js"
6159
}

.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."

0 commit comments

Comments
 (0)