From 042ee91fb266e32b9859ed4020f493febff4fceb Mon Sep 17 00:00:00 2001 From: Salam-vsem Date: Sun, 18 May 2025 12:07:53 +0300 Subject: [PATCH] optimize docckerfile --- Dockerfile | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3f80ada..3ebedca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,38 @@ -FROM node:lts AS build +# Build stage +FROM node:lts-alpine AS build WORKDIR /app -# Copy package files first to leverage cache +# Install dependencies first to leverage Docker cache COPY package*.json ./ -RUN npm ci +RUN npm ci --no-audit --no-fund --production && \ + npm cache clean --force -# Copy remaining files +# Copy source code and build COPY . . RUN npm run build -FROM httpd:2.4 AS runtime +# Runtime stage +FROM httpd:2.4-alpine AS runtime + +# Copy custom httpd config if needed +# COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf + +# Copy built assets from build stage COPY --from=build /app/dist /usr/local/apache2/htdocs/ -EXPOSE 80 \ No newline at end of file + +# Add security headers +RUN echo 'Header set X-Content-Type-Options "nosniff"' >> /usr/local/apache2/conf/httpd.conf && \ + echo 'Header set X-Frame-Options "SAMEORIGIN"' >> /usr/local/apache2/conf/httpd.conf && \ + echo 'Header set X-XSS-Protection "1; mode=block"' >> /usr/local/apache2/conf/httpd.conf + +# Use non-root user for better security +RUN adduser -D -H -u 1000 appuser && \ + chown -R appuser:appuser /usr/local/apache2/htdocs/ + +USER appuser + +EXPOSE 80 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s \ + CMD wget --quiet --tries=1 --spider http://localhost:80/ || exit 1 \ No newline at end of file