Skip to content

Commit 8b7153a

Browse files
committed
feat: improve Docker setup and simplify Mongo setup
1 parent ebabecd commit 8b7153a

11 files changed

Lines changed: 138 additions & 161 deletions

File tree

‎.dockerignore‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ coverage
99
dist
1010
build
1111
*.log
12-
.env.local
13-
.env.*.local
12+
.env*
13+
!.env.example
1414
.turbo

‎.env.example‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
MONGODB_URI=mongodb://localhost:27017/able-alliance
1+
# Docker Compose defaults; use localhost URLs when running services on the host.
2+
MONGODB_URI=mongodb://mongo:27017/able-alliance
3+
WATCHPACK_POLLING=true
24

35
# SuperAdmin — seeded on server startup if not already in DB
46
SUPERADMIN_FIRSTNAME=Super
@@ -7,11 +9,14 @@ SUPERADMIN_CAS_USERNAME=superadmin
79

810
# NextAuth
911
NEXTAUTH_SECRET=dev-secret-change-in-production
12+
AUTH_TRUST_HOST=true
1013
DEPLOY_PRIME_URL=http://localhost:3000
14+
# Server-to-server URL for the websocket server to reach the Next.js app
15+
APP_INTERNAL_URL=http://app:3000
1116

1217
# CAS Authentication
13-
# Server-to-server CAS URL (e.g. use http://cas:8443/cas when running in Docker)
14-
CAS_BASE_URL=http://localhost:8443/cas
18+
# Server-to-server CAS URL
19+
CAS_BASE_URL=http://cas:8443/cas
1520
# Browser-facing URL (used for login redirects visible to the user)
1621
CAS_BASE_URL_BROWSER=http://localhost:8443/cas
1722

@@ -24,8 +29,7 @@ JUNO_EMAIL_SENDER_NAME=Able Alliance
2429
# WebSocket server for real-time chat and toast notifications
2530
NEXT_PUBLIC_WS_URL=http://localhost:4000
2631
# Server-to-server URL for the Next.js app to reach the websocket server
27-
# (e.g. http://websocket:4000 when running in Docker)
28-
WEBSOCKET_INTERNAL_URL=http://localhost:4000
32+
WEBSOCKET_INTERNAL_URL=http://websocket:4000
2933
# Shared secret authorizing the Next.js app to push notifications via the
3034
# websocket server's internal /notify endpoint. Must match the value the
3135
# websocket server is started with.

‎Dockerfile.dev‎

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
1-
# ── Stage 1: deps ────────────────────────────────────────────────────────────
2-
# Install node_modules in an isolated layer so they are only reinstalled when
3-
# package-lock.json changes, not on every source code change.
4-
FROM node:24-slim AS deps
1+
FROM node:24-slim
52

63
WORKDIR /app
74

8-
# Copy only the lockfiles — changes to source never invalidate this layer
95
COPY package.json package-lock.json ./
6+
RUN npm ci
107

11-
# ci installs exact versions from the lockfile; --prefer-offline avoids
12-
# redundant registry requests when the layer is cached
13-
RUN --mount=type=cache,target=/root/.npm \
14-
npm ci --prefer-offline
15-
16-
# ── Stage 2: dev ─────────────────────────────────────────────────────────────
17-
# Runtime image — source is bind-mounted at run time, not baked in.
18-
FROM node:24-slim AS dev
19-
20-
WORKDIR /app
21-
22-
# Copy node_modules from deps stage
23-
COPY --from=deps /app/node_modules ./node_modules
24-
25-
# Copy static config files that don't change often
26-
# (source and public are bind-mounted via docker-compose volumes)
27-
COPY package.json package-lock.json ./
288
COPY next.config.ts tsconfig.json postcss.config.mjs ./
299

3010
EXPOSE 3000
3111

32-
# Docker Compose supplies the development command so it can filter noisy watch output.
3312
CMD ["npm", "run", "dev"]

‎Dockerfile.prod‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:24-slim
2+
3+
WORKDIR /app
4+
5+
COPY package.json package-lock.json ./
6+
RUN npm ci
7+
8+
COPY . .
9+
RUN --mount=type=secret,id=app_env,target=/app/.env \
10+
npm run build && rm -rf .next/cache
11+
12+
ENV NODE_ENV=production
13+
14+
EXPOSE 3000
15+
16+
CMD ["npm", "run", "start"]

‎README.md‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ Able Alliance is a GT student organization that is dedicated to improving on-cam
66

77
## Deployment Preview
88

9-
A deployment preview of the main branch from netlify is available [here](https://able-alliance.netlify.app/). The
10-
websocket express js server is hosted seperately [here](https://able-alliance.onrender.com).
11-
12-
The mock cas express js server is hosted seperately [here](https://able-alliance-mock-cas.onrender.com)
9+
A deployment preview of the main branch from netlify is available [here](https://able-alliance.netlify.app/).
1310

1411
[![Netlify Status](https://api.netlify.com/api/v1/badges/85fa2c6e-6dac-463a-8467-1d6d02d37cb3/deploy-status)](https://app.netlify.com/projects/able-alliance/deploys)
1512

13+
## Environment Setup
14+
15+
Copy `.env.example` to `.env` and fill in your API keys:
16+
17+
```sh
18+
cp .env.example .env
19+
```
20+
21+
For host development, use `localhost` instead of Docker service names.
22+
1623
## Development Setup
1724

1825
- Install [Node.js 24](https://nodejs.org/en/download/)
@@ -26,11 +33,6 @@ The mock cas express js server is hosted seperately [here](https://able-alliance
2633
```sh
2734
npm ci
2835
```
29-
- Create a `.env` file in the project root with `MONGODB_URI`. Copy from `.env.example`:
30-
```sh
31-
cp .env.example .env
32-
```
33-
Then set `MONGODB_URI=mongodb://localhost:27017/able-alliance` (or your MongoDB connection string).
3436
- Start the Next.js dev server:
3537
```sh
3638
npm run dev
@@ -39,25 +41,22 @@ The mock cas express js server is hosted seperately [here](https://able-alliance
3941

4042
## Run With Docker
4143

42-
1. Install [Docker](https://docs.docker.com/engine/install/).
43-
2. From the project root, start the app and MongoDB with Docker Compose:
44-
```sh
45-
docker compose up
46-
```
47-
The app service receives `MONGODB_URI` from the Compose file (`mongodb://mongo:27017/able-alliance?replicaSet=rs0`). No extra env file is required for Docker.
48-
3. To rebuild after changing dependencies, run:
49-
`docker compose down -v`
50-
to delete the old containers and volumes and then rebuild with
51-
` docker compose up --build`
52-
53-
Note: If you run Mongo via Docker Compose, avoid starting another MongoDB on `localhost:27017`; Compose will start Mongo inside the stack and expose it.
44+
- Install [Docker](https://docs.docker.com/engine/install/).
45+
- Development:
46+
```sh
47+
docker compose up --build --watch
48+
```
49+
- Production:
50+
```sh
51+
docker compose -f docker-compose-prod.yml up --build
52+
```
5453

5554
### Seeding the Database
5655

5756
To seed the database with sample users, locations, vehicles, and routes, run:
5857

5958
```sh
60-
npm run seed -- "mongodb://localhost:27017/able-alliance?replicaSet=rs0&directConnection=true"
59+
npm run seed -- "mongodb://localhost:27017/able-alliance"
6160
```
6261

6362
## Major Technologies

‎docker-compose-prod.yml‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: ./Dockerfile.prod
6+
secrets:
7+
- app_env
8+
env_file: .env
9+
ports:
10+
- "3000:3000"
11+
networks:
12+
- able-alliance-net
13+
depends_on:
14+
mongo:
15+
condition: service_healthy
16+
cas:
17+
condition: service_started
18+
command: npm run start
19+
20+
mongo:
21+
image: mongo:7.0
22+
ports:
23+
- "27017:27017"
24+
networks:
25+
- able-alliance-net
26+
volumes:
27+
- mongodb-data:/data/db
28+
logging:
29+
driver: "none"
30+
healthcheck:
31+
test:
32+
["CMD", "mongosh", "--eval", "db.adminCommand({ ping: 1 })", "--quiet"]
33+
interval: 10s
34+
timeout: 5s
35+
retries: 5
36+
start_period: 40s
37+
38+
cas:
39+
build:
40+
context: ./mock-cas-server
41+
dockerfile: Dockerfile
42+
env_file: .env
43+
environment:
44+
PORT: "8443"
45+
ports:
46+
- "8443:8443"
47+
networks:
48+
- able-alliance-net
49+
50+
websocket:
51+
build:
52+
context: .
53+
dockerfile: websocket-server/Dockerfile
54+
ports:
55+
- "4000:4000"
56+
depends_on:
57+
mongo:
58+
condition: service_healthy
59+
env_file: .env
60+
environment:
61+
PORT: "4000"
62+
networks:
63+
- able-alliance-net
64+
65+
networks:
66+
able-alliance-net:
67+
driver: bridge
68+
69+
volumes:
70+
mongodb-data:
71+
72+
secrets:
73+
app_env:
74+
file: .env

‎docker-compose.yml‎

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,7 @@ services:
33
build:
44
context: .
55
dockerfile: ./Dockerfile.dev
6-
environment:
7-
JUNO_API_KEY: "your-juno-api-key"
8-
JUNO_BASE_URL: "your-juno-url"
9-
MONGODB_URI: "mongodb://mongo:27017/able-alliance?replicaSet=rs0"
10-
NEXTAUTH_SECRET: "dev-secret-change-in-production"
11-
DEPLOY_PRIME_URL: "http://localhost:3000"
12-
CAS_BASE_URL: "http://cas:8443/cas"
13-
CAS_BASE_URL_BROWSER: "http://localhost:8443/cas"
14-
SUPERADMIN_FIRSTNAME: "Super"
15-
SUPERADMIN_LASTNAME: "Admin"
16-
# The CAS identity for the SuperAdmin. Set explicitly in both services so
17-
# the app and the mock CAS server cannot disagree about who can log in.
18-
SUPERADMIN_CAS_USERNAME: "superadmin"
19-
WATCHPACK_POLLING: "true"
20-
NEXT_PUBLIC_WS_URL: "http://localhost:4000"
21-
WEBSOCKET_INTERNAL_URL: "http://websocket:4000"
22-
WEBSOCKET_INTERNAL_SECRET: "dev-internal-secret-change-in-production"
6+
env_file: .env
237
develop:
248
watch:
259
- action: rebuild
@@ -33,11 +17,9 @@ services:
3317
- ./emails:/app/emails
3418
- ./scripts:/app/scripts
3519
- ./public:/app/public
36-
- ./.env:/app/.env
3720
- ./next.config.ts:/app/next.config.ts
3821
- ./tsconfig.json:/app/tsconfig.json
3922
- ./postcss.config.mjs:/app/postcss.config.mjs
40-
- node_modules:/app/node_modules
4123
- next_cache:/app/.next
4224
ports:
4325
- "3000:3000"
@@ -59,14 +41,13 @@ services:
5941
- "27017:27017"
6042
networks:
6143
- able-alliance-net
62-
entrypoint: ["/bin/bash", "/app/mongo-init.sh"]
6344
volumes:
6445
- mongodb-data:/data/db
65-
- ./mongo-init.sh:/app/mongo-init.sh
6646
logging:
6747
driver: "none"
6848
healthcheck:
69-
test: ["CMD", "mongosh", "--eval", "rs.status().ok", "--quiet"]
49+
test:
50+
["CMD", "mongosh", "--eval", "db.adminCommand({ ping: 1 })", "--quiet"]
7051
interval: 10s
7152
timeout: 5s
7253
retries: 5
@@ -76,13 +57,9 @@ services:
7657
build:
7758
context: ./mock-cas-server
7859
dockerfile: Dockerfile
60+
env_file: .env
7961
environment:
8062
PORT: "8443"
81-
SUPERADMIN_FIRSTNAME: "Super"
82-
SUPERADMIN_LASTNAME: "Admin"
83-
# The CAS identity for the SuperAdmin. Set explicitly in both services so
84-
# the app and the mock CAS server cannot disagree about who can log in.
85-
SUPERADMIN_CAS_USERNAME: "superadmin"
8663
ports:
8764
- "8443:8443"
8865
networks:
@@ -97,11 +74,9 @@ services:
9774
depends_on:
9875
mongo:
9976
condition: service_healthy
77+
env_file: .env
10078
environment:
101-
- MONGODB_URI=mongodb://mongo:27017/able-alliance?replicaSet=rs0
102-
- NEXTAUTH_SECRET=dev-secret-change-in-production
103-
- DEPLOY_PRIME_URL=http://app:3000
104-
- WEBSOCKET_INTERNAL_SECRET=dev-internal-secret-change-in-production
79+
PORT: "4000"
10580
networks:
10681
- able-alliance-net
10782

@@ -111,5 +86,4 @@ networks:
11186

11287
volumes:
11388
mongodb-data:
114-
node_modules:
11589
next_cache:

‎mock-cas-server/.dockerignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
.env*

0 commit comments

Comments
 (0)