Skip to content

Commit 34cb567

Browse files
committed
Add Docker configuration for frontend and backend services
1 parent b69802d commit 34cb567

File tree

4 files changed

+118
-10
lines changed

4 files changed

+118
-10
lines changed

docker-compose.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,26 @@ services:
55
dockerfile: Dockerfile
66
image: kayvan999/taskaza:latest
77
container_name: taskaza-api
8-
9-
# <port on localhost>:<port on container>
8+
depends_on:
9+
db:
10+
condition: service_healthy
11+
restart: unless-stopped
1012
ports:
1113
- 8000:8000
12-
13-
# creating a bind mount to keep our container and dev env in sync
14-
# with read only command for added security
1514
volumes:
1615
- ./backend:/usr/src/app:ro
1716
- ./backend/data:/usr/src/app/data
18-
19-
# override the command to start the server with --reload
2017
command: fastapi dev app/main.py --host 0.0.0.0 --port 8000
21-
2218
env_file: ./backend/.env
23-
19+
environment:
20+
TSKZ_DATABASE_URL: postgresql+asyncpg://taskaza_user:taskaza_password@db:5432/taskaza_db
2421
networks:
2522
- taskaza-nw
2623

2724
db:
2825
image: postgres:17
2926
container_name: taskaza-db
30-
restart: always
27+
restart: unless-stopped
3128
environment:
3229
POSTGRES_USER: taskaza_user
3330
POSTGRES_PASSWORD: taskaza_password
@@ -38,6 +35,30 @@ services:
3835
- 5432:5432
3936
networks:
4037
- taskaza-nw
38+
healthcheck:
39+
test: ["CMD-SHELL", "pg_isready -U taskaza_user -d taskaza_db"]
40+
interval: 5s
41+
timeout: 3s
42+
retries: 10
43+
44+
frontend:
45+
image: kayvan999/taskaza-ui:latest
46+
build:
47+
context: ./frontend
48+
dockerfile: Dockerfile.dev
49+
container_name: taskaza-ui
50+
ports:
51+
- "3000:3000"
52+
volumes:
53+
- ./frontend:/app
54+
- /app/node_modules
55+
environment:
56+
NODE_ENV: development
57+
NEXT_TELEMETRY_DISABLED: 1
58+
command: npm run dev
59+
networks:
60+
- taskaza-nw
61+
restart: unless-stopped
4162

4263
networks:
4364
taskaza-nw:

frontend/.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Node / Next
2+
node_modules
3+
.next
4+
out
5+
# Vercel/CI
6+
.vercel
7+
.github
8+
# Logs & misc
9+
npm-debug.log*
10+
yarn.lock
11+
pnpm-lock.yaml
12+
*.local
13+
.DS_Store
14+
coverage
15+
.next
16+
Dockerfile.*

frontend/Dockerfile.dev

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:20-alpine
2+
WORKDIR /app
3+
4+
ENV NEXT_TELEMETRY_DISABLED=1
5+
6+
COPY package.json package-lock.json ./
7+
RUN npm ci
8+
9+
COPY . .
10+
11+
EXPOSE 3000
12+
CMD ["npm", "run", "dev"]

frontend/Dockerfile.prod

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# ---- Base metadata ----
2+
# Build-time args (optional overrides)
3+
ARG NODE_VERSION=20-alpine
4+
5+
# ---- Deps stage: install only production deps based on lockfile ----
6+
FROM node:${NODE_VERSION} AS deps
7+
WORKDIR /app
8+
9+
# Speed up installs & keep image clean
10+
ENV CI=true \
11+
NEXT_TELEMETRY_DISABLED=1
12+
13+
# Copy only files needed to compute dependency graph
14+
COPY package.json package-lock.json ./
15+
16+
# Install deps (ci = clean install from lockfile)
17+
RUN npm ci
18+
19+
# ---- Builder stage: build Next.js app ----
20+
FROM node:${NODE_VERSION} AS builder
21+
WORKDIR /app
22+
ENV CI=true NEXT_TELEMETRY_DISABLED=1
23+
24+
# Copy installed deps from deps stage
25+
COPY --from=deps /app/node_modules ./node_modules
26+
27+
# Copy the rest of the app
28+
# (Your repo has code under src/, app/, components/, etc.)
29+
COPY . .
30+
31+
# Build Next.js for production
32+
RUN npm run build
33+
34+
# ---- Runner stage: minimal runtime image ----
35+
FROM node:${NODE_VERSION} AS runner
36+
WORKDIR /app
37+
38+
ENV NODE_ENV=production \
39+
NEXT_TELEMETRY_DISABLED=1 \
40+
PORT=3000 \
41+
HOSTNAME=0.0.0.0
42+
43+
# Create non-root user
44+
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
45+
46+
# Copy the standalone output produced by Next.js
47+
# This keeps runtime image small and fast
48+
COPY --from=builder /app/.next/standalone ./
49+
# Static assets
50+
COPY --from=builder /app/.next/static ./.next/static
51+
# Public folder (favicons, images, robots.txt, etc.)
52+
COPY --from=builder /app/public ./public
53+
54+
# Ownership for non-root
55+
RUN chown -R nextjs:nodejs /app
56+
USER nextjs
57+
58+
EXPOSE 3000
59+
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)