Skip to content

Commit f44589c

Browse files
committed
feat(infra): add PostgreSQL support as database backend option
Implement PostgreSQL as an alternative database backend alongside MongoDB. Users can now select postgres via SHELLHUB_DATABASE environment variable. - Add PostgreSQL configuration env vars (username, password, database) - Create docker-compose.postgres.yml with postgres:18.0 service - Update bin/utils to recognize 'postgres' as valid database option - Configure healthcheck for PostgreSQL service
1 parent 7e4e8e8 commit f44589c

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ SHELLHUB_AUTO_SSL=false
3636

3737
SHELLHUB_DATABASE=mongo
3838

39+
SHELLHUB_POSTGRES_USERNAME=admin
40+
SHELLHUB_POSTGRES_PASSWORD=admin
41+
SHELLHUB_POSTGRES_DATABASE=main
42+
3943
# The domain of the server.
4044
# NOTICE: Required only if automatic HTTPS is enabled.
4145
# VALUES: A valid domain name

bin/utils

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ COMPOSE_FILE="docker-compose.yml"
7373

7474
SHELLHUB_DATABASE=${SHELLHUB_DATABASE:-mongo}
7575
case "$SHELLHUB_DATABASE" in
76-
mongo)
76+
mongo|postgres)
7777
COMPOSE_FILE="${COMPOSE_FILE}:docker-compose.${SHELLHUB_DATABASE}.yml"
7878
;;
7979
*)

docker-compose.postgres.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
postgres:
3+
image: postgres:18.0
4+
command: postgres -c io_method=io_uring
5+
security_opt:
6+
# Disable seccomp to allow io_uring syscalls (io_uring_setup, io_uring_enter, io_uring_register)
7+
# which are blocked by Docker's default seccomp profile for security reasons.
8+
- seccomp=unconfined
9+
healthcheck:
10+
start_period: 90s
11+
interval: 5s
12+
timeout: 5s
13+
retries: 5
14+
test: ["CMD-SHELL", "pg_isready -U ${SHELLHUB_POSTGRES_USERNAME} -d ${SHELLHUB_POSTGRES_DATABASE}"]
15+
environment:
16+
- POSTGRES_USER=${SHELLHUB_POSTGRES_USERNAME}
17+
- POSTGRES_PASSWORD=${SHELLHUB_POSTGRES_PASSWORD}
18+
- POSTGRES_DB=${SHELLHUB_POSTGRES_DATABASE}
19+
networks:
20+
- shellhub
21+
api:
22+
depends_on:
23+
postgres:
24+
condition: service_healthy

0 commit comments

Comments
 (0)