Enable Production

This commit is contained in:
TheMaddax 2024-11-23 14:38:56 -06:00
parent f24a6e5551
commit 4715b3b6a0
3 changed files with 40 additions and 4 deletions

View file

@ -1,5 +1,7 @@
# Build stage
FROM node:18-alpine as build
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /app
COPY package*.json ./
RUN npm install
@ -8,7 +10,11 @@ RUN npm run build
# Production stage
FROM nginx:alpine
# Add security headers and optimization configs
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost/ || exit 1
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View file

@ -1,7 +1,25 @@
version: '3.8'
services:
web:
build: .
build:
context: .
args:
NODE_ENV: production
ports:
- "80:80"
- "804:80"
restart: always
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
cpus: '0.50'
memory: 512M
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"

View file

@ -1,15 +1,27 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Security headers
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
add_header Strict-Transport-Security "max-age=31536000";
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://unpkg.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:;";
# Compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.html;
expires 1h;
add_header Cache-Control "public, no-transform";
}
# Cache static assets
# Static asset caching
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 30d;
add_header Cache-Control "public, no-transform";