-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathDockerfile.test
More file actions
63 lines (47 loc) · 1.6 KB
/
Dockerfile.test
File metadata and controls
63 lines (47 loc) · 1.6 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
# docker build -t ff .
# docker run -p 3000:3000 -it ff
# Build stage
FROM --platform=$BUILDPLATFORM node:24.14.0-trixie-slim AS builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
WORKDIR /ci
# Copy dependency files first for better caching
COPY package.json package-lock.json ./
# Install ALL dependencies once (including dev deps for build)
RUN npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 20000 && \
npm config set fetch-retry-maxtimeout 120000 && \
npm ci && \
npm cache clean --force
# Copy necessary config files
COPY next.config.js tsconfig.json tailwind.config.js postcss.config.js ./
COPY .env.test ./
# Copy source files
COPY ./src ./src
COPY ./public ./public
COPY ./config ./config
COPY ./start.sh ./
ENV NODE_ENV=test
# Build and prune
RUN npm run build && \
npm prune --omit=dev;
# Production stage
FROM node:24.14.0-trixie-slim AS runner
WORKDIR /ci
RUN addgroup --system --gid 1001 nextjs && \
adduser --system --uid 1001 nextjs
# Copy only production dependencies
COPY --from=builder --chown=nextjs:nextjs /ci/package.json ./
COPY --from=builder --chown=nextjs:nextjs /ci/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nextjs /ci/config ./config
COPY --from=builder --chown=nextjs:nextjs /ci/.next ./.next
COPY --from=builder --chown=nextjs:nextjs /ci/public ./public
COPY --from=builder --chown=nextjs:nextjs /ci/start.sh ./start.sh
RUN mkdir -p .next/cache/images && \
chmod +x start.sh && \
chown -R nextjs:nextjs .next/cache
USER nextjs:nextjs
ENV NODE_ENV=test \
PORT=3000 \
NEXT_TELEMETRY_DISABLED=1
CMD ["sh", "./start.sh"]