From 4715b3b6a0c064e28b08ce5247bc9f2a1bbc7fae Mon Sep 17 00:00:00 2001 From: TheMaddax Date: Sat, 23 Nov 2024 14:38:56 -0600 Subject: [PATCH] Enable Production --- Dockerfile | 6 ++++++ docker-compose.yml | 22 ++++++++++++++++++++-- nginx.conf | 16 ++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4a4dfc5..3be09d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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;"] diff --git a/docker-compose.yml b/docker-compose.yml index 707218e..bcb40e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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" \ No newline at end of file diff --git a/nginx.conf b/nginx.conf index 9dccd41..936f441 100644 --- a/nginx.conf +++ b/nginx.conf @@ -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";