You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a `.env` file in the project root. All variables have sensible defaults for local development, so a minimal `.env` can be empty — but you should at least set a proper JWT secret:
73
+
Create a `.env` file in the project root:
74
+
75
+
```bash
76
+
cp .env.example .env
77
+
```
78
+
79
+
Use these values as a baseline for local development:
73
80
74
81
```dotenv
75
82
# .env
@@ -85,13 +92,18 @@ POSTGRES_PORT=5432
85
92
POSTGRES_DB=syncdesk_db
86
93
87
94
# MongoDB
88
-
MONGO_USER=
89
-
MONGO_PASSWORD=
95
+
MONGO_USER=mongouser
96
+
MONGO_PASSWORD=mongopassword
90
97
MONGO_HOST=localhost
91
98
MONGO_PORT=27017
92
99
MONGO_DB=syncdesk_db
93
100
101
+
# Mongo root user (required when Mongo runs via docker compose)
102
+
MONGO_INITDB_ROOT_USERNAME=mongouser
103
+
MONGO_INITDB_ROOT_PASSWORD=mongopassword
104
+
94
105
# JWT (change the secrets in any non-local environment)
106
+
JWT_SECRET_KEY=change-me-in-production
95
107
ACCESS_TOKEN_SIGNING_KEY=change-me-in-production
96
108
REFRESH_TOKEN_SIGNING_KEY=change-me-in-production
97
109
JWT_ALGORITHM=HS256
@@ -109,22 +121,32 @@ PROJECT_VERSION=0.1.0
109
121
110
122
Full variable reference is in the [core/ docs](app/core/README.md#configuration-configpy).
111
123
124
+
Important:
125
+
126
+
- For Docker Compose, keep `MONGO_USER` / `MONGO_PASSWORD` equal to `MONGO_INITDB_ROOT_USERNAME` / `MONGO_INITDB_ROOT_PASSWORD`.
127
+
- The app authenticates MongoDB using `authSource=admin` when credentials are present.
128
+
112
129
### 3. Set up the databases
113
130
114
-
#### Option A: Development mode (auto-setup)
131
+
#### Option A: Local API run (with local DB services)
115
132
116
133
When `ENVIRONMENT=development`, the app:
117
134
118
135
- connects to MongoDB on startup,
119
-
- and **automatically creates the PostgreSQL database and all tables** (drops and recreates).
136
+
- creates the PostgreSQL database if it does not exist,
137
+
- and runs Alembic migrations if the schema is behind `head`.
120
138
121
-
Make sure both PostgreSQL and MongoDB are running:
139
+
Start databases first (one simple option is using Compose only for DB services):
122
140
123
141
```bash
124
-
make dev
142
+
docker compose up -d db mongo
125
143
```
126
144
127
-
> **Warning:** Postgres auto-setup drops all tables every startup in development. Use only for local development.
145
+
Then run the API locally:
146
+
147
+
```bash
148
+
make dev
149
+
```
128
150
129
151
#### Option B: Using Alembic migrations (recommended for staging/production)
130
152
@@ -207,19 +229,37 @@ POSTGRES_DB=syncdesk_db
207
229
POSTGRES_HOST=localhost
208
230
POSTGRES_PORT=5432
209
231
232
+
MONGO_INITDB_ROOT_USERNAME=mongouser
233
+
MONGO_INITDB_ROOT_PASSWORD=mongopassword
234
+
MONGO_USER=mongouser
235
+
MONGO_PASSWORD=mongopassword
210
236
MONGO_HOST=localhost
211
237
MONGO_PORT=27017
212
238
MONGO_DB=syncdesk_db
213
239
```
214
240
215
241
`POSTGRES_HOST` is automatically overridden to `db`, and `MONGO_HOST` to `mongo`, inside the API container.
216
242
243
+
`MONGO_INITDB_ROOT_*` is used to create the MongoDB root user on first startup. The API connects with `MONGO_USER`/`MONGO_PASSWORD` and authenticates against `admin`.
244
+
217
245
### 2. Start all services
218
246
219
247
```bash
220
248
docker compose up --build
221
249
```
222
250
251
+
To run in detached mode:
252
+
253
+
```bash
254
+
docker compose up -d --build
255
+
```
256
+
257
+
To follow API logs:
258
+
259
+
```bash
260
+
docker compose logs -f api
261
+
```
262
+
223
263
What happens automatically:
224
264
225
265
- PostgreSQL container starts and becomes healthy
@@ -229,6 +269,15 @@ What happens automatically:
229
269
- Alembic runs: `alembic upgrade head`
230
270
- FastAPI starts on `http://localhost:8000`
231
271
272
+
If you previously changed Mongo credentials and still get `Authentication failed`, recreate containers and volumes once:
273
+
274
+
```bash
275
+
docker compose down -v
276
+
docker compose up --build
277
+
```
278
+
279
+
If ports are already in use locally, adjust host ports in `docker-compose.yaml`.
280
+
232
281
### 3. Stop services
233
282
234
283
```bash
@@ -240,6 +289,21 @@ To also remove Postgres and Mongo persisted data:
240
289
```bash
241
290
docker compose down -v
242
291
```
292
+
293
+
Data persistence behavior:
294
+
295
+
-`docker compose down` keeps DB data (named volumes are preserved)
0 commit comments