Skip to content

Commit fc1488d

Browse files
committed
feat: Update deployment instructions to support optional MongoDB configurations
1 parent 736efc9 commit fc1488d

File tree

3 files changed

+69
-18
lines changed

3 files changed

+69
-18
lines changed

DEPLOYMENT.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,40 @@ nano .env
5151

5252
Update the following variables:
5353
- `DOMAIN`: Your domain name (e.g., `trakrlog.com` or `api.trakrlog.com`)
54-
- `MONGODB_URL`: MongoDB connection string (e.g., `mongodb://admin:your_password@mongo:27017`)
54+
- `MONGODB_URL`: MongoDB connection string
55+
- For local container: `mongodb://admin:your_password@mongo:27017`
56+
- For MongoDB Atlas: `mongodb+srv://user:pass@cluster.mongodb.net/`
57+
- For other external MongoDB: Use your provider's connection string
5558
- `MONGODB_DATABASE`: Database name (default: `trakrlog`)
56-
- `MONGODB_PASSWORD`: MongoDB password (must match the password in MONGODB_URL)
59+
- `MONGODB_PASSWORD`: MongoDB root password (only needed for local container)
5760
- `SESSION_SECRET`: Generate with `openssl rand -hex 32`
5861
- `GOOGLE_CLIENT_ID`: Your Google OAuth client ID
5962
- `GOOGLE_CLIENT_SECRET`: Your Google OAuth client secret
6063
- `GOOGLE_CALLBACK_URL`: `https://yourdomain.com/auth/google/callback`
6164

62-
### 4. Configure Google OAuth
65+
### 4. Choose MongoDB Deployment Option
66+
67+
**Option A: Use MongoDB Atlas (Recommended for Production)**
68+
69+
1. Create a free account at [MongoDB Atlas](https://www.mongodb.com/cloud/atlas)
70+
2. Create a new cluster
71+
3. Get your connection string (looks like `mongodb+srv://...`)
72+
4. Set `MONGODB_URL` to your Atlas connection string in `.env`
73+
5. Deploy without local MongoDB:
74+
```bash
75+
docker compose -f docker-compose.prod.yml up -d
76+
```
77+
78+
**Option B: Use Local MongoDB Container**
79+
80+
1. Set `MONGODB_URL=mongodb://admin:yourpassword@mongo:27017` in `.env`
81+
2. Set `MONGODB_PASSWORD=yourpassword` in `.env`
82+
3. Deploy with local MongoDB:
83+
```bash
84+
docker compose -f docker-compose.prod.yml --profile local-db up -d
85+
```
86+
87+
### 5. Configure Google OAuth
6388

6489
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
6590
2. Create a new project or select an existing one
@@ -69,27 +94,44 @@ Update the following variables:
6994
- `https://yourdomain.com/auth/google/callback` (production)
7095
- `http://localhost:4000/auth/google/callback` (local development)
7196

72-
### 5. Build and deploy
97+
### 6. Build and deploy
7398

7499
```bash
75-
# Build and start all services
100+
# Build and start all services (with external MongoDB like Atlas)
76101
docker compose -f docker-compose.prod.yml up -d --build
77102

103+
# OR: Build and start with local MongoDB container
104+
docker compose -f docker-compose.prod.yml --profile local-db up -d --build
105+
78106
# View logs
79107
docker compose -f docker-compose.prod.yml logs -f
80108

81109
# Check service status
82110
docker compose -f docker-compose.prod.yml ps
83111
```
84112

85-
### 6. Verify deployment
113+
### 7. Verify deployment
86114

87115
- Visit `https://yourdomain.com` - should show your frontend
88-
- Visit `https://yourdomain.com/api/health` - should return health status
89-
- Try logging in with Google OAuth
90-
91116
## Architecture
92117

118+
**With External MongoDB (e.g., Atlas):**
119+
```
120+
┌─────────────────┐
121+
│ Internet │
122+
└────────┬────────┘
123+
124+
┌────▼────┐
125+
│ Caddy │ :80, :443 (Reverse Proxy + SSL)
126+
└────┬────┘
127+
128+
┌────▼────┐ ┌──────────────┐
129+
│ App │ :4000 ────────────►│ MongoDB Atlas│
130+
└─────────┘ │ (External) │
131+
└──────────────┘
132+
```
133+
134+
**With Local MongoDB Container:**
93135
```
94136
┌─────────────────┐
95137
│ Internet │
@@ -110,7 +152,11 @@ docker compose -f docker-compose.prod.yml ps
110152

111153
## Services
112154

113-
### MongoDB
155+
### MongoDB (Optional - use --profile local-db)
156+
- Internal port: 27017 (when using local container)
157+
- Data persisted in Docker volume: `mongo_data`
158+
- Credentials configured via environment variables
159+
- **Alternative**: Use MongoDB Atlas or any external MongoDB service
114160
- Internal port: 27017
115161
- Data persisted in Docker volume: `mongo_data`
116162
- Credentials configured via environment variables

docker-compose.local.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
services:
2-
# MongoDB Database
2+
# MongoDB Database (optional - enable with --profile local-db)
33
mongo:
44
image: mongo:7
55
restart: unless-stopped
6+
profiles:
7+
- local-db # Only starts if 'local-db' profile is enabled
68
ports:
79
- "27018:27017" # Use 27018 externally to avoid conflict with local MongoDB
810
environment:
@@ -35,9 +37,11 @@ services:
3537
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
3638
GOOGLE_CALLBACK_URL: ${GOOGLE_CALLBACK_URL:-http://localhost:4000/auth/google/callback}
3739
APP_ENV: development
38-
depends_on:
39-
mongo:
40-
condition: service_healthy
40+
# Note: depends_on removed by default - set MONGODB_URL to external DB or use --profile local-db
41+
# If using local mongo profile, uncomment the depends_on section below
42+
# depends_on:
43+
# mongo:
44+
# condition: service_healthy
4145
networks:
4246
- trakrlog-network
4347
healthcheck:

docker-compose.prod.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
services:
2-
# MongoDB Database
2+
# MongoDB Database (optional - only used if not connecting to external MongoDB like Atlas)
33
mongo:
44
image: mongo:7
55
restart: unless-stopped
6+
profiles:
7+
- local-db # Only starts if 'local-db' profile is enabled
68
environment:
79
# Extract password from MONGODB_URL (format: mongodb://user:pass@host:port)
810
MONGO_INITDB_ROOT_USERNAME: admin
@@ -24,16 +26,15 @@ services:
2426
restart: unless-stopped
2527
environment:
2628
PORT: 4000
29+
# Use external MongoDB by default (e.g., Atlas)
30+
# For local MongoDB container, use: MONGODB_URL=mongodb://admin:yourpassword@mongo:27017
2731
MONGODB_URL: ${MONGODB_URL}
2832
MONGODB_DATABASE: ${MONGODB_DATABASE}
2933
SESSION_SECRET: ${SESSION_SECRET}
3034
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
3135
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
3236
GOOGLE_CALLBACK_URL: ${GOOGLE_CALLBACK_URL}
3337
APP_ENV: production
34-
depends_on:
35-
mongo:
36-
condition: service_healthy
3738
networks:
3839
- trakrlog-network
3940
healthcheck:

0 commit comments

Comments
 (0)