-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathDockerfile
More file actions
92 lines (71 loc) · 2.88 KB
/
Copy pathDockerfile
File metadata and controls
92 lines (71 loc) · 2.88 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
FROM node:lts-slim AS pnpm
WORKDIR /app
# Set environment variables for better performance
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Install pnpm globally with better caching
RUN corepack enable
FROM pnpm AS deps
# Set environment variables for better performance
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Copy package files first for better layer caching
COPY --link package.json pnpm-lock.yaml* ./
# Install dependencies with better caching strategy
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm fetch --frozen-lockfile | \
grep -v "cross-device link not permitted\|Falling back to copying packages from store"
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm i --frozen-lockfile --ignore-scripts --prefer-offline
# Build stage with optimized caching
FROM pnpm AS build
# Set environment variables for build stage
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Copy dependencies from deps stage
COPY --link --from=deps /app/node_modules ./node_modules/
COPY --link . /app
RUN pnpm run next-ws && \
pnpm run build && \
# Clean up cache to reduce image size
rm -rf .next/standalone/.next/cache && \
mkdir -p /config
# Production stage with minimal footprint
FROM dhi.io/node:24 AS runner
WORKDIR /app
# Add labels for better image metadata
LABEL org.opencontainers.image.title="PeaNUT"
LABEL org.opencontainers.image.description="A tiny dashboard for Network UPS Tools"
LABEL org.opencontainers.image.url="https://github.com/Brandawg93/PeaNUT"
LABEL org.opencontainers.image.source='https://github.com/Brandawg93/PeaNUT'
LABEL org.opencontainers.image.licenses='Apache-2.0'
# Copy built application and set permissions to default node user
COPY --link --from=build --chown=1000:1000 /app/.next/standalone ./
COPY --link --from=build --chown=1000:1000 /app/.next/static ./.next/static
# Create config directory and set permissions for non-root user
COPY --link --from=build --chown=1000:1000 /config /config
# Copy only API source files needed for Swagger documentation generation
COPY --link --from=build --chown=1000:1000 /app/src/app/api ./src/app/api
COPY --link --from=build --chown=1000:1000 /app/package.json ./package.json
# Copy and set up entrypoint script
COPY --link --chmod=755 --chown=1000:1000 entrypoint.mjs ./entrypoint.mjs
COPY --link --chmod=755 --chown=1000:1000 healthcheck.mjs ./healthcheck.mjs
# Set environment variables
ENV CI=true
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV WEB_HOST=0.0.0.0
ENV WEB_PORT=8080
ENV BASE_PATH=""
ENV SETTINGS_FILE=/config/settings.yml
ENV AUTH_FILE_PATH=/config/auth.yaml
ENV DEBUG=false
EXPOSE $WEB_PORT
# Optimized healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["node", "healthcheck.mjs"]
ENTRYPOINT ["node", "entrypoint.mjs"]