Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (54 loc) · 1.76 KB
/
Copy pathDockerfile
File metadata and controls
73 lines (54 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Dockerfile for ElasticScope
# Multi-stage build for production
# ============================================
# Stage 1: Build Next.js app
# ============================================
FROM node:20-slim AS app-builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install all dependencies (including devDependencies for build)
RUN npm ci
# Copy source code
COPY . ./
# Build Next.js application
RUN npm run build
# ============================================
# Stage 2: Production image
# ============================================
FROM node:20-slim AS production
WORKDIR /app
# Install dumb-init and wget for healthcheck
RUN apt-get update && apt-get install -y --no-install-recommends \
dumb-init \
wget \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -g 1001 elasticscope && \
useradd -r -u 1001 -g elasticscope elasticscope
# Copy package files
COPY package*.json ./
# Install production dependencies
RUN npm ci --omit=dev && \
npm cache clean --force
# Copy built Next.js app and server-side modules
COPY --from=app-builder /app/.next ./.next
COPY --from=app-builder /app/public ./public
COPY --from=app-builder /app/next.config.mjs ./next.config.mjs
COPY --from=app-builder /app/server ./server
# Create data directory for SQLite
RUN mkdir -p /app/data && chown -R elasticscope:elasticscope /app/data
# Set environment variables
ENV NODE_ENV=production
ENV PORT=3001
ENV DATA_DIR=/app/data
# Switch to non-root user
USER elasticscope
# Expose ports
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3001/api/status || exit 1
# Start the application
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "run", "start"]