feat: add easy-dataset and mongodb-replicaset-single

This commit is contained in:
Sun-ZhenXing
2025-10-22 10:05:17 +08:00
parent 37b52545a2
commit 84e8b85990
15 changed files with 736 additions and 39 deletions

View File

@@ -24,6 +24,12 @@ x-mongo: &mongo
chown 999:999 /tmp/rs0.key
export MONGO_INITDB_ROOT_USERNAME MONGO_INITDB_ROOT_PASSWORD MONGO_INITDB_DATABASE
exec docker-entrypoint.sh mongod --replSet ${MONGO_REPLICA_SET_NAME:-rs0} --keyFile /tmp/rs0.key
healthcheck:
test: mongosh --eval "db.adminCommand('ping')"
interval: 5s
timeout: 3s
retries: 10
start_period: 30s
deploy:
resources:
limits:
@@ -38,11 +44,75 @@ services:
<<: *mongo
ports:
- "${MONGO_PORT_OVERRIDE_1:-27017}:27017"
mongo2:
<<: *mongo
ports:
- "${MONGO_PORT_OVERRIDE_2:-27018}:27017"
mongo3:
<<: *mongo
ports:
- "${MONGO_PORT_OVERRIDE_3:-27019}:27017"
mongo-init:
<<: *default
image: mongo:${MONGO_VERSION:-8.0.13}
depends_on:
mongo1:
condition: service_healthy
mongo2:
condition: service_healthy
mongo3:
condition: service_healthy
environment:
TZ: ${TZ:-UTC}
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-root}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-password}
MONGO_REPLICA_SET_NAME: ${MONGO_REPLICA_SET_NAME:-rs0}
MONGO_PORT_1: ${MONGO_PORT_OVERRIDE_1:-27017}
MONGO_PORT_2: ${MONGO_PORT_OVERRIDE_2:-27018}
MONGO_PORT_3: ${MONGO_PORT_OVERRIDE_3:-27019}
MONGO_HOST: ${MONGO_HOST:-mongo1}
volumes:
- ./secrets/rs0.key:/data/rs0.key:ro
entrypoint:
- bash
- -c
- |
set -e
echo "Waiting for MongoDB nodes to be ready..."
sleep 5
mongosh \
--host "mongodb://$${MONGO_INITDB_ROOT_USERNAME}:$${MONGO_INITDB_ROOT_PASSWORD}@$${MONGO_HOST}:$${MONGO_PORT_1}" \
--authenticationDatabase admin \
--eval "
const config = {
_id: '$${MONGO_REPLICA_SET_NAME}',
members: [
{ _id: 0, host: 'mongo1:27017' },
{ _id: 1, host: 'mongo2:27017' },
{ _id: 2, host: 'mongo3:27017' }
]
};
try {
const result = rs.status();
print('Replica set already initialized');
} catch (e) {
print('Initializing replica set...');
rs.initiate(config);
print('Replica set initialized successfully');
}
"
echo "Init container completed successfully"
deploy:
resources:
limits:
cpus: '0.25'
memory: 256M
reservations:
cpus: '0.10'
memory: 128M