Skip to content

Commit 461bf66

Browse files
authored
Merge pull request #6 from PoCInnovation/lhnfe/dis-8-dockerize-application
Add Dockerfiles and docker-compose configuration
2 parents 33aa6e7 + b48cafb commit 461bf66

10 files changed

Lines changed: 126 additions & 1 deletion

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
POSTGRES_DB=dispatch
2+
POSTGRES_USER=dispatch
3+
POSTGRES_PASSWORD=dispatch

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

backend/.dockerignore

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

backend/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM oven/bun:1-alpine AS deps
2+
WORKDIR /app
3+
COPY package.json bun.lock ./
4+
RUN bun install --frozen-lockfile
5+
6+
FROM deps AS dev
7+
COPY . .
8+
EXPOSE 3000
9+
CMD ["bun", "run", "start:dev"]
10+
11+
FROM deps AS build
12+
COPY . .
13+
RUN bun run build
14+
15+
FROM node:22-alpine AS prod
16+
WORKDIR /app
17+
COPY --from=build /app/dist ./dist
18+
COPY --from=build /app/node_modules ./node_modules
19+
COPY package.json ./
20+
EXPOSE 3000
21+
CMD ["node", "dist/main"]

docker-compose.dev.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
services:
2+
backend:
3+
build:
4+
context: ./backend
5+
target: dev
6+
ports:
7+
- "3001:3000"
8+
environment:
9+
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
10+
volumes:
11+
- ./backend:/app
12+
- backend_node_modules:/app/node_modules
13+
depends_on:
14+
postgres:
15+
condition: service_healthy
16+
17+
frontend:
18+
build:
19+
context: ./frontend
20+
target: dev
21+
ports:
22+
- "3000:3000"
23+
volumes:
24+
- ./frontend:/app
25+
- frontend_node_modules:/app/node_modules
26+
depends_on:
27+
- backend
28+
29+
volumes:
30+
backend_node_modules:
31+
frontend_node_modules:

docker-compose.override.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
backend:
3+
build:
4+
context: ./backend
5+
target: prod
6+
ports:
7+
- "3001:3000"
8+
environment:
9+
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
10+
depends_on:
11+
postgres:
12+
condition: service_healthy
13+
14+
frontend:
15+
build:
16+
context: ./frontend
17+
target: prod
18+
ports:
19+
- "3000:3000"
20+
depends_on:
21+
- backend

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
postgres:
3+
image: postgres:18-alpine
4+
environment:
5+
POSTGRES_DB: ${POSTGRES_DB}
6+
POSTGRES_USER: ${POSTGRES_USER}
7+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
8+
volumes:
9+
- postgres_data:/var/lib/postgresql
10+
ports:
11+
- "5432:5432"
12+
healthcheck:
13+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
14+
interval: 10s
15+
timeout: 5s
16+
retries: 5
17+
18+
volumes:
19+
postgres_data:

frontend/.dockerignore

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

frontend/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM oven/bun:1-alpine AS deps
2+
WORKDIR /app
3+
COPY package.json bun.lock ./
4+
RUN bun install --frozen-lockfile
5+
6+
FROM deps AS dev
7+
COPY . .
8+
EXPOSE 3000
9+
CMD ["bun", "run", "dev"]
10+
11+
FROM deps AS build
12+
COPY . .
13+
RUN bun run build
14+
15+
FROM node:22-alpine AS prod
16+
WORKDIR /app
17+
ENV NODE_ENV=production
18+
COPY --from=build /app/public ./public
19+
COPY --from=build /app/.next/standalone ./
20+
COPY --from=build /app/.next/static ./.next/static
21+
EXPOSE 3000
22+
CMD ["node", "server.js"]

frontend/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
4-
/* config options here */
4+
output: "standalone",
55
};
66

77
export default nextConfig;

0 commit comments

Comments
 (0)