Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,57 +1,45 @@
# ---------------------
# Build stage
# ---------------------
FROM node:22-alpine AS build
FROM oven/bun:1.3.3-alpine AS build

# Enable corepack and install a specific pnpm version securely
RUN corepack enable && corepack prepare pnpm@10.3.0 --activate


# Set working directory
WORKDIR /app

# Copy only necessary files
COPY package.json pnpm-lock.yaml ./
# Copy dependency manifests
COPY package.json bun.lock ./

# Install dependencies
# sonarcloud: disable=ShellScriptExecutionRisk
RUN pnpm install
RUN bun install

# Copy the rest of the source code
# Copy source
COPY . .
# COPY .next ./.next
# COPY public ./public
# COPY node_modules ./node_modules

# Build Next.js app
RUN bun --bun run build

# Build the Next.js application
RUN pnpm run build

# ---------------------
# Production stage
# ---------------------
FROM node:22-alpine AS production
FROM oven/bun:1.3.3-alpine AS production

# Create a non-root user
# RUN groupadd -r appgroup && useradd -r -g appgroup appuser
# Create non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Set working directory

WORKDIR /app

# Copy necessary build artifacts from build stage
# Copy required runtime files
COPY --from=build /app/package.json ./
COPY --from=build /app/.next ./.next
COPY --from=build /app/public ./public
COPY --from=build /app/node_modules ./node_modules

# Change ownership to non-root user
# Fix ownership
RUN chown -R appuser:appgroup /app

# Switch to non-root user
USER appuser

# Expose port
EXPOSE 3000

# Start the Next.js application
CMD ["npm", "start"]
# Start Next.js
CMD ["bun", "run", "start"]
Loading