Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions .github/workflows/e2etests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:

- name: Run tests (pytest)
run: |
export TEST_SOURCE_URI=mongodb://adm:pass@rs00:30000
export TEST_TARGET_URI=mongodb://adm:pass@rs10:30100
export TEST_SOURCE_URI=mongodb://rs00:30000
export TEST_TARGET_URI=mongodb://rs10:30100
export TEST_PCSM_URL=http://127.0.0.1:2242
export TEST_PCSM_BIN=./bin/pcsm_test

Expand Down Expand Up @@ -96,8 +96,8 @@ jobs:

- name: Run tests (pytest)
run: |
export TEST_SOURCE_URI=mongodb://adm:pass@src-mongos:27017
export TEST_TARGET_URI=mongodb://adm:pass@tgt-mongos:29017
export TEST_SOURCE_URI=mongodb://src-mongos:27017
export TEST_TARGET_URI=mongodb://tgt-mongos:29017
export TEST_PCSM_URL=http://127.0.0.1:2242
export TEST_PCSM_BIN=./bin/pcsm_test

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/rs/mongo/users.adm.js

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/rs/mongo/users.js

This file was deleted.

4 changes: 1 addition & 3 deletions .github/workflows/rs/util
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,5 @@ rsinit() {
echo "uninitialized primary: $1"
exit 1
fi
msh "$2" "/cfg/users.adm.js"
msh "adm:pass@$2" "/cfg/users.js"
msh "adm:pass@$2" "/cfg/scripts/deprioritize.js"
msh "$2" "/cfg/scripts/deprioritize.js"
}
5 changes: 0 additions & 5 deletions .github/workflows/sh/mongo/users.adm.js

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/sh/mongo/users.js

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/sh/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ mwait "src-rs00:30000" && rsinit "src/rs0" "src-rs00:30000"
mwait "src-rs10:30100" && rsinit "src/rs1" "src-rs10:30100"

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

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

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

dcf up -d tgt-mongos && mwait "tgt-mongos:27017"
msh "adm:pass@tgt-mongos:27017" --eval "
msh "tgt-mongos:27017" --eval "
sh.addShard('rs0/tgt-rs00:40000'); //
sh.addShard('rs1/tgt-rs10:40100');
"
msh "adm:pass@tgt-mongos:27017" --eval "db.adminCommand('transitionFromDedicatedConfigServer');"
msh "tgt-mongos:27017" --eval "db.adminCommand('transitionFromDedicatedConfigServer');"
4 changes: 1 addition & 3 deletions .github/workflows/sh/util
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,5 @@ rsinit() {
echo "uninitialized primary: $1"
exit 1
fi
msh "$2" "/cfg/users.adm.js"
msh "adm:pass@$2" "/cfg/users.js"
msh "adm:pass@$2" "/cfg/scripts/deprioritize.js"
msh "$2" "/cfg/scripts/deprioritize.js"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.env

/bin/
/tmp/
vendor/

.pytest_cache
Expand Down
78 changes: 78 additions & 0 deletions hack/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
# Clean up Docker resources for test environments
# Removes: containers, volumes, networks
#
# Usage: ./cleanup.sh [ENV...]
# (no args) Clean all (rs, sh, sh-ha)
# rs Replica set only
# sh Sharded cluster only (3→2 shards, project: s1)
# sh-ha Sharded cluster HA only
#
# Example:
# ./cleanup.sh rs sh # rs and sh

set -euo pipefail

SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
ENVS_TO_CLEAN=()

if [[ $# -eq 0 ]]; then
ENVS_TO_CLEAN=("rs" "sh" "sh-ha")
else
while [[ $# -gt 0 ]]; do
case $1 in
rs|sh|sh-ha)
ENVS_TO_CLEAN+=("$1")
shift
;;
*)
echo "Unknown environment: $1"
echo "Valid: rs, sh, sh-ha"
exit 1
;;
esac
done
fi

# Function to clean up a compose environment
cleanup_env() {
local name=$1
local compose_file=$2
local project_name=${3:-}

if [[ ! -f "$compose_file" ]]; then
echo "Skipping $name (compose file not found)"
return
fi

echo "Cleaning $name..."

local compose_cmd="docker compose -f $compose_file"
if [[ -n "$project_name" ]]; then
compose_cmd="docker compose -p $project_name -f $compose_file"
fi

# Stop and remove containers, then remove volumes
$compose_cmd down --remove-orphans 2>/dev/null || true
$compose_cmd down -v 2>/dev/null || true
}

# Clean specified environments
for env in "${ENVS_TO_CLEAN[@]}"; do
case $env in
rs)
cleanup_env "rs" "$SCRIPT_DIR/rs/compose.yml"
docker volume ls -q | grep -E '^rs[0-9]+' | xargs -r docker volume rm 2>/dev/null || true
;;
sh)
cleanup_env "sh" "$SCRIPT_DIR/sh/compose.yml" "s1"
docker volume ls -q | grep -E '^(src-|tgt-|s1_)' | xargs -r docker volume rm 2>/dev/null || true
;;
sh-ha)
cleanup_env "sh-ha" "$SCRIPT_DIR/sh-ha/compose.yml" "s1"
docker volume ls -q | grep -E '^s1_' | xargs -r docker volume rm 2>/dev/null || true
;;
esac
done

echo "Done."
16 changes: 0 additions & 16 deletions hack/rs/mongo/keyFile

This file was deleted.

5 changes: 0 additions & 5 deletions hack/rs/mongo/users.adm.js

This file was deleted.

11 changes: 0 additions & 11 deletions hack/rs/mongo/users.js

This file was deleted.

7 changes: 0 additions & 7 deletions hack/rs/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ RDIR="$BASE/rs"

export compose="$RDIR/compose.yml"

# https://www.mongodb.com/docs/v7.0/tutorial/deploy-sharded-cluster-with-keyfile-access-control/
if [ ! -s "$RDIR/mongo/keyFile" ]; then
echo >&2 generate "$RDIR/mongo/keyFile"
openssl rand -base64 756 >"$RDIR/mongo/keyFile"
chmod 400 "$RDIR/mongo/keyFile"
fi

dcf up -d rs00 rs01 rs02 rs10 rs11 rs12

mwait "rs00:30000"
Expand Down
1 change: 0 additions & 1 deletion hack/sh-ha/mongo/configsvr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ systemLog.quiet: true
net.bindIpAll: true
storage.dbPath: /data/db
sharding.clusterRole: configsvr
security.keyFile: /cfg/keyFile
16 changes: 0 additions & 16 deletions hack/sh-ha/mongo/keyFile

This file was deleted.

1 change: 0 additions & 1 deletion hack/sh-ha/mongo/mongos.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
systemLog.quiet: true
net.bindIpAll: true
security.keyFile: /cfg/keyFile
1 change: 0 additions & 1 deletion hack/sh-ha/mongo/shardsvr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ systemLog.quiet: true
net.bindIpAll: true
storage.dbPath: /data/db
sharding.clusterRole: shardsvr
security.keyFile: /cfg/keyFile
5 changes: 0 additions & 5 deletions hack/sh-ha/mongo/users.adm.js

This file was deleted.

20 changes: 0 additions & 20 deletions hack/sh-ha/mongo/users.js

This file was deleted.

6 changes: 2 additions & 4 deletions hack/sh-ha/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ source "$BASE/util"

SDIR="$BASE/sh-ha"

chmod 400 "$SDIR"/mongo/keyFile

export compose=$SDIR/compose.yml

# dcf up -d src-cfg0 src-rs00 src-rs10 tgt-cfg0 tgt-rs00 tgt-rs10
Expand All @@ -30,7 +28,7 @@ mwait "src-rs12:30102"
rsinit "src/rs1" "src-rs10:30100"

dcf up -d src-mongos && mwait "src-mongos:27017"
msh "adm:pass@src-mongos:27017" --eval "
msh "src-mongos:27017" --eval "
sh.addShard('rs0/src-rs00:30000'); //
sh.addShard('rs0/src-rs01:30001'); //
sh.addShard('rs0/src-rs02:30002'); //
Expand All @@ -55,7 +53,7 @@ mwait "tgt-rs12:40102"
rsinit "tgt/rs1" "tgt-rs10:40100"

dcf up -d tgt-mongos && mwait "tgt-mongos:27017"
msh "adm:pass@tgt-mongos:27017" --eval "
msh "tgt-mongos:27017" --eval "
sh.addShard('rs0/tgt-rs00:40000'); //
sh.addShard('rs0/tgt-rs01:40001'); //
sh.addShard('rs0/tgt-rs02:40002'); //
Expand Down
36 changes: 36 additions & 0 deletions hack/sh/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ services:
"30100",
]

src-rs20:
image: "${MONGO_IMAGE:-percona/percona-server-mongodb:8.0}"
container_name: src-rs20
hostname: src-rs20
ports: ["30200:30200"]
volumes: ["src-rs20:/data/db", "./mongo/:/cfg:ro"]
command:
[
"mongod",
"-f",
"/cfg/shardsvr.conf",
"--replSet",
"rs2",
"--port",
"30200",
]

# ----------------- Target -----------------
tgt-mongos:
image: "${MONGO_IMAGE:-percona/percona-server-mongodb:8.0}"
Expand Down Expand Up @@ -134,10 +151,29 @@ services:
"40100",
]

tgt-rs20:
image: "${MONGO_IMAGE:-percona/percona-server-mongodb:8.0}"
container_name: tgt-rs20
hostname: tgt-rs20
ports: ["40200:40200"]
volumes: ["tgt-rs20:/data/db", "./mongo/:/cfg:ro"]
command:
[
"mongod",
"-f",
"/cfg/shardsvr.conf",
"--replSet",
"rs2",
"--port",
"40200",
]

volumes:
src-cfg0:
src-rs00:
src-rs10:
src-rs20:
tgt-cfg0:
tgt-rs00:
tgt-rs10:
tgt-rs20:
1 change: 0 additions & 1 deletion hack/sh/mongo/configsvr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ systemLog.quiet: true
net.bindIpAll: true
storage.dbPath: /data/db
sharding.clusterRole: configsvr
security.keyFile: /cfg/keyFile
Loading
Loading