collective-boredom-dial/Dockerfile

75 lines
1.6 KiB
Docker

# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
# Remove tailwind postcss config
RUN rm -f postcss.config.js tailwind.config.js
RUN npm uninstall tailwindcss @tailwindcss/postcss 2>/dev/null || true
RUN npm run build
# Production stage
FROM nginx:alpine
COPY --from=builder /app/build /usr/share/nginx/html
# Nginx config with WebSocket proxy
RUN cat > /etc/nginx/conf.d/default.conf << 'EOF'
upstream websocket {
server boredom-ws:3001;
}
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# WebSocket proxy
location /ws {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 86400;
}
# Health check endpoint
location /health {
proxy_pass http://websocket/health;
}
# API endpoints
location /api {
proxy_pass http://websocket/api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# React app
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";
}
}
EOF
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]