chore: Enhance Dockerfile.fast for improved caching, dependency installation, and security by adding a non-root user
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 18m19s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 18m19s
This commit is contained in:
+25
-11
@@ -5,44 +5,58 @@ WORKDIR /app/frontend
|
||||
# Install build dependencies for native modules
|
||||
RUN apk add --no-cache python3 make g++
|
||||
|
||||
# Set npm config for better performance
|
||||
# Set npm config for better performance and caching
|
||||
RUN npm config set registry https://registry.npmjs.org/
|
||||
RUN npm config set fetch-timeout 300000
|
||||
RUN npm config set fetch-retry-mintimeout 20000
|
||||
RUN npm config set fetch-retry-maxtimeout 120000
|
||||
RUN npm config set cache /tmp/.npm
|
||||
|
||||
# Copy package files first for better caching
|
||||
COPY frontend/package*.json ./
|
||||
|
||||
# Install dependencies with specific flags for speed and force rebuild
|
||||
RUN npm ci --no-audit --no-fund --prefer-offline --build-from-source
|
||||
# Clean install dependencies to fix rollup issue with optimized flags
|
||||
RUN rm -rf node_modules package-lock.json
|
||||
RUN npm install --no-audit --no-fund --prefer-offline --build-from-source --production=false --cache /tmp/.npm
|
||||
|
||||
# Copy source code
|
||||
COPY frontend/ .
|
||||
# Copy source code (only what's needed for build)
|
||||
COPY frontend/src/ ./src/
|
||||
COPY frontend/public/ ./public/
|
||||
COPY frontend/index.html ./
|
||||
COPY frontend/vite.config.js ./
|
||||
COPY frontend/eslint.config.js ./
|
||||
|
||||
# Build the application
|
||||
# Build the application with optimized settings
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: Setup Node.js backend and serve everything
|
||||
FROM node:20-alpine
|
||||
WORKDIR /app
|
||||
|
||||
# Set npm config for better performance
|
||||
# Set npm config for better performance and caching
|
||||
RUN npm config set registry https://registry.npmjs.org/
|
||||
RUN npm config set fetch-timeout 300000
|
||||
RUN npm config set cache /tmp/.npm
|
||||
|
||||
# Copy package files first for better caching
|
||||
COPY backend/package*.json ./
|
||||
|
||||
# Install production dependencies only
|
||||
RUN npm ci --only=production --no-audit --no-fund --prefer-offline
|
||||
# Install production dependencies only with optimized flags
|
||||
RUN npm ci --only=production --no-audit --no-fund --prefer-offline --cache /tmp/.npm
|
||||
|
||||
# Copy backend source code
|
||||
COPY backend/ .
|
||||
# Copy backend source code (only what's needed)
|
||||
COPY backend/server.js ./
|
||||
COPY backend/package.json ./
|
||||
|
||||
# Copy built frontend assets from the previous stage
|
||||
COPY --from=frontend-builder /app/frontend/dist ./public
|
||||
|
||||
# Create non-root user for security
|
||||
RUN addgroup -g 1001 -S nodejs
|
||||
RUN adduser -S nodejs -u 1001
|
||||
RUN chown -R nodejs:nodejs /app
|
||||
USER nodejs
|
||||
|
||||
# The port the backend runs on
|
||||
EXPOSE 3001
|
||||
|
||||
|
||||
Reference in New Issue
Block a user