Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#!/bin/sh

# Acknowledgements:
# Acknowledgment required before using this docker-compose setup:
# - New users: This will be set to true by default.
# - Existing users: If you have a previous setup (e.g., using the Bitnami MongoDB image), you must manually set this to true after running the steps in the README.md
# Without this acknowledgment, the compose file will fail to run to avoid unintended changes.
# Example: When migrating from Bitnami MongoDB to the official MongoDB image, data loss or misconfigurations can occur
# if the acknowledgment is not explicitly provided. This ensures a safe transition for existing setups.
ACK_MONGODB_BITNAMI_MIGRATION=true

# Change these
REG_TOKEN=
DOMAIN=localhost
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/data/
node_modules
.env
backup/
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You can login to Grafana at: http://grafana.localhost with the default credentia

First, clone this repository:


```bash
git clone --depth 1 https://github.com/RocketChat/rocketchat-compose.git
```
Expand Down Expand Up @@ -126,3 +127,73 @@ podman compose \
-f compose.yml \
up -d
```

---

## Advanced Migrating to Oficial MongoDB

Set `ACK_MONGODB_BITNAMI_MIGRATION=true` in your `.env` just after the backup is finished

If you're updating from older MongoDB (Bitnami) to the official MongoDB container:

### Step 1: Backup Your Data
1. Find your MongoDB container:
```bash
docker ps
# or if you are using podman
podman ps
```
2. Create a backup inside the container:
```bash
docker exec -it <YOUR_MONGO_CONTAINER> mongodump -o /tmp/backup
# or if you are using podman
podman exec -it <YOUR_MONGO_CONTAINER> mongodump -o /tmp/backup
```
3. Copy the backup to your computer:
```bash
docker cp <YOUR_MONGO_CONTAINER>:/tmp/backup ./backup
# or if you are using podman
podman cp <YOUR_MONGO_CONTAINER>:/tmp/backup ./backup
```
4. Ack the migration process adding `ACK_MONGODB_BITNAMI_MIGRATION=true` to your `.env` file

### Step 2: Update the Setup
1. Stop all services:
```bash
docker compose -f compose.database.yml -f compose.monitoring.yml -f compose.traefik.yml -f compose.yml down
# or if you are using podman
podman compose -f compose.database.yml -f compose.monitoring.yml -f compose.traefik.yml -f compose.yml down
```
2. Update setup files:
```bash
git pull origin main
```

### Step 3: Restore Data
1. Start only MongoDB:
```bash
docker compose -f compose.database.yml up -d
# or if you are using podman
podman compose -f compose.database.yml up -d
```
2. Copy your backup back into MongoDB:
```bash
docker cp ./backup <YOUR_MONGO_CONTAINER>:/tmp/backup
# or if you are using podman
podman cp ./backup <YOUR_MONGO_CONTAINER>:/tmp/backup
```
3. Restore the backup:
```bash
docker exec -it <YOUR_MONGO_CONTAINER> mongorestore /tmp/backup
# or if you are using podman
podman exec -it <YOUR_MONGO_CONTAINER> mongorestore /tmp/backup
```

### Step 4: Restart Everything
1. Start all services again:
```bash
docker compose -f compose.database.yml -f compose.monitoring.yml -f compose.traefik.yml -f compose.yml up -d
# or if you are using podman
podman compose -f compose.database.yml -f compose.monitoring.yml -f compose.traefik.yml -f compose.yml up -d
```

55 changes: 44 additions & 11 deletions compose.database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ services:
- -varz
- "http://nats:8222"
mongodb:
image: docker.io/bitnamilegacy/mongodb:${MONGODB_VERSION:-6.0}
image: docker.io/mongo:${MONGODB_VERSION:-6.0}
restart: always
volumes:
- ${MONGODB_HOST_PATH:-mongodb_data}:/bitnami/mongodb:rw
- ${MONGODB_HOST_PATH:-oficial_mongodb_data}:/data/db:rw
command: ["--replSet", "${MONGODB_REPLICA_SET_NAME:-rs0}", "--bind_ip_all", "--port", "${MONGODB_PORT_NUMBER:-27017}"]
environment:
MONGODB_REPLICA_SET_MODE: ${MONGODB_REPLICA_SET_MODE:-primary}
MONGODB_REPLICA_SET_NAME: ${MONGODB_REPLICA_SET_NAME:-rs0}
MONGODB_PORT_NUMBER: ${MONGODB_PORT_NUMBER:-27017}
MONGODB_INITIAL_PRIMARY_HOST: ${MONGODB_INITIAL_PRIMARY_HOST:-mongodb}
MONGODB_INITIAL_PRIMARY_PORT_NUMBER: ${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}
MONGODB_ADVERTISED_HOSTNAME: ${MONGODB_ADVERTISED_HOSTNAME:-mongodb}
MONGODB_ENABLE_JOURNAL: ${MONGODB_ENABLE_JOURNAL:-true}
ALLOW_EMPTY_PASSWORD: ${ALLOW_EMPTY_PASSWORD:-yes}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE:-admin}
ACK_MONGODB_BITNAMI_MIGRATION: ${ACK_MONGODB_BITNAMI_MIGRATION:?Please refer to https://github.com/RocketChat/rocketchat-compose?tab=readme-ov-file#advanced-migrating-to-oficial-mongodb}

# healthcheck:
# test: ["CMD", "mongosh", "--host", "mongodb", "--port", "${MONGODB_PORT_NUMBER:-27017}", "--eval", "db.adminCommand('ping')"]
# interval: 30s
Expand All @@ -47,6 +43,43 @@ services:
- ${MONGODB_PORT_NUMBER:-27017}
ports:
- "${MONGODB_BIND_IP:-127.0.0.1}:${MONGODB_PORT_NUMBER:-27017}:${MONGODB_PORT_NUMBER:-27017}"
mongodb-init:
image: docker.io/mongo:${MONGODB_VERSION:-6.0}
restart: on-failure
command:
- bash
- -c
- |
# $$ is to use the bash $ or this will be interpreted by docker/podman and use variables from env
# for the MONGODB_PORT_NUMBER we actually want to use the one from the .env
echo "Waiting for MongoDB to be ready"
until mongosh --host mongodb --port ${MONGODB_PORT_NUMBER:-27017} --eval "db.adminCommand('ping')" >/dev/null 2>&1; do
echo "Waiting for MongoDB to be ready..."
sleep 5
done
echo "MongoDB ready"

REPLICA_STATUS="$(mongosh --host mongodb --port ${MONGODB_PORT_NUMBER:-27017} --eval "rs.status().ok" 2>/dev/null || echo "")"
if [ -z "$$REPLICA_STATUS" ]; then
echo "Initializing the replica set..."
mongosh --host mongodb --port ${MONGODB_PORT_NUMBER:-27017} --eval "rs.initiate({_id: '${MONGODB_REPLICA_SET_NAME:-rs0}', members: [{ _id: 0, host: 'mongodb:${MONGODB_PORT_NUMBER:-27017}' }]})"
else
echo "Replica set already initialized."
exit 0
fi

sleep 1

# Check if the replicaset is initialized
REPLICA_STATUS=$(mongosh --host mongodb --port ${MONGODB_PORT_NUMBER:-27017} --eval "rs.status().ok" 2>/dev/null || echo "")
if [ -z "$$REPLICA_STATUS" ]; then
echo "Replica set not initialized."
else
echo "Replica set already initialized."
fi
depends_on:
- mongodb

mongodb-exporter:
image: docker.io/percona/mongodb_exporter:${MONGODB_EXPORTER_VERSION:-0.44.0}
depends_on:
Expand All @@ -58,4 +91,4 @@ services:
- --collect-all
- --compatible-mode
volumes:
mongodb_data: {driver: local}
oficial_mongodb_data: {driver: local}