Skip to content

Commit 753b6d2

Browse files
committed
[UPD] updated
1 parent 877f250 commit 753b6d2

File tree

4 files changed

+4593
-5520
lines changed

4 files changed

+4593
-5520
lines changed

Dockerfile

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,70 @@
1-
# Build stage
2-
FROM node:20-alpine AS builder
1+
# Dependencies stage
2+
FROM node:20-slim AS deps
33

4-
# Set working directory
54
WORKDIR /app
65

7-
# Add pnpm to path
8-
ENV PNPM_HOME=/usr/local/bin
6+
# Install build dependencies
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
python3 \
9+
make \
10+
g++ \
11+
&& rm -rf /var/lib/apt/lists/*
912

10-
# Install pnpm - use exact version for reproducibility
11-
RUN npm install -g [email protected] \
12-
&& pnpm config set store-dir /.pnpm-store
13+
# Install corepack and pnpm
14+
RUN corepack enable && corepack prepare [email protected] --activate
1315

14-
# Copy package.json and lockfile
16+
# Copy package files
1517
COPY package.json pnpm-lock.yaml* .npmrc* ./
1618

17-
# Install dependencies with cache optimization
18-
RUN --mount=type=cache,id=pnpm,target=/.pnpm-store \
19-
pnpm install --frozen-lockfile --prod=false
19+
# Install dependencies
20+
RUN pnpm install --frozen-lockfile
2021

21-
# Copy application code
22+
# Builder stage
23+
FROM node:20-slim AS builder
24+
25+
WORKDIR /app
26+
27+
RUN corepack enable && corepack prepare [email protected] --activate
28+
29+
# Copy dependencies and source
30+
COPY --from=deps /app/node_modules ./node_modules
2231
COPY . .
2332

2433
# Build application
34+
ENV NEXT_TELEMETRY_DISABLED=1
2535
RUN pnpm build
2636

2737
# Production stage
28-
FROM node:20-alpine AS runner
38+
FROM node:20-slim AS runner
2939

30-
# Set working directory
3140
WORKDIR /app
3241

33-
# Set environment variables
3442
ENV NODE_ENV=production \
35-
PNPM_HOME=/usr/local/bin
43+
NEXT_TELEMETRY_DISABLED=1
3644

37-
# Add a non-root user to run the application
38-
RUN addgroup --system --gid 1001 nodejs \
39-
&& adduser --system --uid 1001 nextjs \
40-
&& npm install -g [email protected]
45+
# Install wget for healthcheck
46+
RUN apt-get update && apt-get install -y --no-install-recommends \
47+
wget \
48+
&& rm -rf /var/lib/apt/lists/*
4149

42-
# Copy only necessary files from builder
43-
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
50+
# Create non-root user
51+
RUN groupadd -r nodejs --gid=1001 && \
52+
useradd -r -g nodejs --uid=1001 nextjs
53+
54+
# Copy built application
4455
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
4556
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
46-
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
47-
COPY --from=builder --chown=nextjs:nodejs /app/pnpm-lock.yaml ./pnpm-lock.yaml
48-
49-
# Install production dependencies and necessary dev dependencies
50-
RUN --mount=type=cache,id=pnpm,target=/.pnpm-store \
51-
pnpm install --frozen-lockfile --prod --no-optional \
52-
&& pnpm add -D @next/bundle-analyzer
53-
54-
# Set proper permissions
55-
RUN chmod -R 755 /app
57+
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
58+
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
59+
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
5660

57-
# Switch to non-root user
5861
USER nextjs
5962

60-
# Expose the port the app runs on
6163
EXPOSE 3000
6264

63-
# Define healthcheck
64-
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
65+
ENV PORT=3000
66+
67+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
6568
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
6669

67-
# Run the application
68-
CMD ["pnpm", "start"]
70+
CMD ["node_modules/.bin/next", "start"]

elastic-apm-node.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

next.config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,22 @@ const config = {
3434
};
3535

3636
if (process.env.NODE_ENV === 'development') {
37-
const withPreconstruct = require('@preconstruct/next');
38-
module.exports = withPreconstruct(withNextra(config));
39-
} else {
37+
try {
38+
const withPreconstruct = require('@preconstruct/next');
39+
module.exports = withPreconstruct(withNextra(config));
40+
} catch (e) {
41+
module.exports = withNextra(config);
42+
}
43+
} else if (process.env.ANALYZE === 'true') {
4044
try {
4145
const withBundleAnalyzer = require('@next/bundle-analyzer')({
42-
enabled: process.env.ANALYZE === 'true',
46+
enabled: true,
4347
});
4448
module.exports = withBundleAnalyzer(withNextra(config));
4549
} catch (e) {
46-
// If @next/bundle-analyzer is not available, just use withNextra
47-
console.warn('Warning: @next/bundle-analyzer not found, skipping bundle analysis');
50+
console.warn('Warning: @next/bundle-analyzer not available');
4851
module.exports = withNextra(config);
4952
}
53+
} else {
54+
module.exports = withNextra(config);
5055
}

0 commit comments

Comments
 (0)