diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a199b80 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +node_modules +npm-debug.log +.git +.gitignore +.env +.env.* +*.md +test/ +coverage/ +.vscode/ +.idea/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9cc876e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +# Build stage +FROM node:18-alpine AS builder + +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install production dependencies only +RUN npm ci --omit=dev + +# Copy source code +COPY src/ ./src/ + +# Production stage +FROM node:18-alpine + +WORKDIR /app + +# Copy node_modules from builder +COPY --from=builder /app/node_modules ./node_modules + +# Copy source code +COPY --from=builder /app/src ./src +COPY package*.json ./ + +# Create non-root user +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 && \ + chown -R nodejs:nodejs /app + +USER nodejs + +# Expose port +EXPOSE 3000 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" + +# Start the application +CMD ["node", "src/index.js"]