Refactor Dockerfile for improved build process and configuration management

- Updated the Dockerfile to use the latest base image and streamline the multi-stage build process.
- Enhanced dependency installation by copying additional configuration files and using the `--frozen-lockfile` option.
- Set environment variables for production settings and localization.
- Adjusted the command to start the application, ensuring it runs the correct entry point.
This commit is contained in:
m4x809 2025-10-25 03:55:59 +02:00
parent bdc5fbc8fd
commit ddbd73fd3e
Signed by: m4x809
SSH key fingerprint: SHA256:YCoFF78p2DUP94EnCScqLwldjkKDwdKSZq3r8p/6EiU

View file

@ -1,25 +1,33 @@
# Use bun as the base image
FROM oven/bun:1 AS base
FROM oven/bun:latest AS deps
# Install dependencies only when needed
FROM base AS deps
WORKDIR /app
# Copy dependency files
COPY package.json ./
COPY bun.lock* ./
COPY package.json bunfig.toml next.config.ts ./
# Install dependencies including devDependencies
RUN bun install --production=false
RUN bun install --frozen-lockfile
# Build the application
FROM base AS builder
FROM oven/bun:latest AS builder
WORKDIR /app
# Copy dependencies from deps stage
# Copy dependencies and config files
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/package.json ./
COPY --from=deps /app/bunfig.toml ./
COPY --from=deps /app/next.config.js ./
# Copy source code
COPY . .
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV SKIP_ENV_VALIDATION=1
ENV BETTER_AUTH_TELEMETRY=0
# Build Next.js application
RUN bun run build
@ -29,25 +37,26 @@ WORKDIR /app
ENV NODE_ENV=production
# Create a non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files
COPY --from=builder /app/public ./public
# Copy Next.js build artifacts
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
COPY --from=builder /app/src/env.js ./src/env.js
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/bunScripts ./bunScripts
# Set ownership to nextjs user
RUN chown -R nextjs:nodejs /app
USER nextjs
ENV TZ="CET"
ENV LANG="de_DE.UTF-8"
ENV LANGUAGE="de_DE:de"
ENV LC_ALL="de_DE.UTF-8"
ENV PORT=3000
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Start the application
CMD ["bun", "run", "start"]
CMD ["bun", "server.js"]