chore(docker): add Dockerfiles and docker-compose for frontend and backend

- Add frontend Dockerfile with multi-stage build using node and nginx
- Add backend Dockerfile with multi-stage build to compile and serve app
- Add docker-compose.yml to define frontend and backend services with environment variables
- Configure nginx to serve SPA, enable gzip compression and caching for static assets
- Set up nginx reverse proxy for API requests to backend service on /api path
This commit is contained in:
MUIS1436
2026-01-31 10:03:30 +05:00
parent 5fa3fb3d15
commit d5cb1ded3e
4 changed files with 120 additions and 0 deletions

29
Dockerfile Normal file
View File

@@ -0,0 +1,29 @@
# Frontend Dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy source code
COPY . .
# Build the app
RUN npm run build
# Production stage
FROM nginx:alpine
# Copy built assets
COPY --from=builder /app/dist /usr/share/nginx/html
# Copy nginx config
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

28
docker-compose.yml Normal file
View File

@@ -0,0 +1,28 @@
version: '3.8'
services:
frontend:
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- backend
environment:
- VITE_MS_CLIENT_ID=${VITE_MS_CLIENT_ID}
- VITE_GOOGLE_CLIENT_ID=${VITE_GOOGLE_CLIENT_ID}
backend:
build:
context: ./server
dockerfile: Dockerfile
ports:
- "3001:3001"
environment:
- PORT=3001
- VITE_MS_CLIENT_ID=${VITE_MS_CLIENT_ID}
- MS_CLIENT_SECRET=${MS_CLIENT_SECRET}
- VITE_GOOGLE_CLIENT_ID=${VITE_GOOGLE_CLIENT_ID}
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
- REDIRECT_URI=${REDIRECT_URI}

31
nginx.conf Normal file
View File

@@ -0,0 +1,31 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
# Handle SPA routing
location / {
try_files $uri $uri/ /index.html;
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# Proxy API requests to backend
location /api {
proxy_pass http://backend:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

32
server/Dockerfile Normal file
View File

@@ -0,0 +1,32 @@
# Backend Dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy source code
COPY . .
# Build TypeScript
RUN npm run build
# Production stage
FROM node:20-alpine
WORKDIR /app
# Copy package files and install production deps only
COPY package*.json ./
RUN npm ci --only=production
# Copy built code
COPY --from=builder /app/dist ./dist
EXPOSE 3001
CMD ["node", "dist/index.js"]