Skip to content

Commit 309617e

Browse files
committed
feat(infra): make database engine configurable
Add support for pluggable database backends via SHELLHUB_DATABASE env var. MongoDB service moved from main docker-compose.yml to separate compose files. - Add SHELLHUB_DATABASE env var (defaults to mongo) - Add logic in bin/utils to load database-specific compose files - Remove hardcoded mongo service from main docker-compose.yml
1 parent d52e1b0 commit 309617e

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SHELLHUB_PROXY=false
3434
# Enable automatic HTTPS with Let's Encrypt.
3535
SHELLHUB_AUTO_SSL=false
3636

37+
SHELLHUB_DATABASE=mongo
38+
3739
# The domain of the server.
3840
# NOTICE: Required only if automatic HTTPS is enabled.
3941
# VALUES: A valid domain name

bin/utils

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ COMPOSE_FILE="docker-compose.yml"
7171
[ "$SHELLHUB_ENTERPRISE" = "true" ] && [ "$SHELLHUB_ENV" != "development" ] && COMPOSE_FILE="${COMPOSE_FILE}:docker-compose.enterprise.yml"
7272
[ -f docker-compose.override.yml ] && COMPOSE_FILE="${COMPOSE_FILE}:docker-compose.override.yml"
7373

74+
SHELLHUB_DATABASE=${SHELLHUB_DATABASE:-mongo}
75+
case "$SHELLHUB_DATABASE" in
76+
mongo)
77+
COMPOSE_FILE="${COMPOSE_FILE}:docker-compose.${SHELLHUB_DATABASE}.yml"
78+
;;
79+
*)
80+
echo "⚠️ WARNING: Unknown SHELLHUB_DATABASE '$SHELLHUB_DATABASE'. Defaulting to mongodb."
81+
SHELLHUB_DATABASE="mongodb"
82+
COMPOSE_FILE="${COMPOSE_FILE}:docker-compose.mongodb.yml"
83+
;;
84+
esac
85+
7486
[ -f "$EXTRA_COMPOSE_FILE" ] && COMPOSE_FILE="${COMPOSE_FILE}:${EXTRA_COMPOSE_FILE}"
7587

7688
export COMPOSE_FILE

docker-compose.mongo.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
mongo:
3+
image: mongo:4.4.29
4+
restart: unless-stopped
5+
healthcheck:
6+
test: 'test $$(echo "rs.initiate({ _id: ''rs'', members: [ { _id: 0, host: ''mongo:27017'' } ] }).ok || rs.status().ok" | mongo --quiet) -eq 1'
7+
interval: 30s
8+
start_period: 10s
9+
command: ["--replSet", "rs", "--bind_ip_all"]
10+
networks:
11+
- shellhub
12+
api:
13+
depends_on:
14+
mongo:
15+
condition: service_healthy

docker-compose.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ services:
6060
- SHELLHUB_INTERNAL_HTTP_CLIENT_API_BASE_URL=${SHELLHUB_INTERNAL_HTTP_CLIENT_API_BASE_URL}
6161
- SHELLHUB_INTERNAL_HTTP_CLIENT_ENTERPRISE_BASE_URL=${SHELLHUB_INTERNAL_HTTP_CLIENT_ENTERPRISE_BASE_URL}
6262
depends_on:
63-
- mongo
6463
- redis
6564
links:
66-
- mongo
6765
- redis
6866
secrets:
6967
- api_private_key
@@ -145,16 +143,6 @@ services:
145143
- SHELLHUB_LOG_FORMAT=${SHELLHUB_LOG_FORMAT}
146144
networks:
147145
- shellhub
148-
mongo:
149-
image: mongo:4.4.29
150-
restart: unless-stopped
151-
healthcheck:
152-
test: 'test $$(echo "rs.initiate({ _id: ''rs'', members: [ { _id: 0, host: ''mongo:27017'' } ] }).ok || rs.status().ok" | mongo --quiet) -eq 1'
153-
interval: 30s
154-
start_period: 10s
155-
command: ["--replSet", "rs", "--bind_ip_all"]
156-
networks:
157-
- shellhub
158146
redis:
159147
image: redis
160148
restart: unless-stopped

0 commit comments

Comments
 (0)