From 72b4272cfd50668995b17249111614b6447c6508 Mon Sep 17 00:00:00 2001 From: EreQ Date: Thu, 8 Jan 2026 11:35:17 +0300 Subject: [PATCH 1/3] Update Dockerfile --- Dockerfile | 55 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index df7ec930..1d22132f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,69 +1,66 @@ -# Multi-stage Dockerfile for QCX - Optimized for Google Cloud Build -# Stage 1: Dependencies installation -FROM oven/bun:1.1.3-alpine AS deps +# Multi-stage Dockerfile for QCX - Optimized for Google Cloud Build and Production +# Uses latest stable Bun with Alpine for smaller images and better compatibility (as of January 2026) + +# Stage 1: Install dependencies +FROM oven/bun:alpine AS deps WORKDIR /app # Copy package files COPY package.json bun.lock* ./ -# Install dependencies +# Install dependencies (frozen lockfile for reproducibility) RUN bun install --frozen-lockfile -# Stage 2: Build stage -FROM oven/bun:1.1.3-alpine AS builder +# Stage 2: Build the Next.js application +FROM oven/bun:alpine AS builder WORKDIR /app -# Copy dependencies from deps stage +# Copy node_modules from deps stage COPY --from=deps /app/node_modules ./node_modules -# Copy application source +# Copy source code COPY . . -# Set build-time environment variables +# Disable telemetry during build ENV NEXT_TELEMETRY_DISABLED=1 ENV NODE_ENV=production -# Build the Next.js application +# Build the application (standalone output) RUN bun run build -# Stage 3: Production runtime -FROM oven/bun:1.1.3-alpine AS runner +# Stage 3: Production runtime (minimal image running with Bun) +FROM oven/bun:alpine AS runner WORKDIR /app -# Install only necessary runtime dependencies -RUN apk add --no-cache \ - nodejs \ - tini \ - curl \ - && addgroup -g 1001 -S nodejs \ +# Create non-root user for security +RUN addgroup -g 1001 -S nodejs \ && adduser -S nextjs -u 1001 -# Set production environment +# Environment variables ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" -# Copy built application from builder +# Copy standalone build output COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +# Copy static assets COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +# Copy public folder COPY --from=builder --chown=nextjs:nodejs /app/public ./public -# Switch to non-root user for security +# Switch to non-root user USER nextjs -# Expose the application port +# Expose port EXPOSE 3000 -# Health check for container orchestration +# Health check (adjust path if your app has a different health endpoint) HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ - CMD curl -f http://localhost:3000/api/health || exit 1 - -# Use tini as init system to handle signals properly -ENTRYPOINT ["/sbin/tini", "--"] + CMD ["bun", "--eval", "fetch('http://localhost:3000/api/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))"] -# Start the application -CMD ["node", "server.js"] +# Run with Bun (excellent Node.js compatibility, faster cold starts) +CMD ["bun", "server.js"] From 5723110a0996a55b7634ac626c879e03753a34c9 Mon Sep 17 00:00:00 2001 From: EreQ Date: Thu, 8 Jan 2026 11:56:59 +0300 Subject: [PATCH 2/3] Update Dockerfile --- Dockerfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1d22132f..50055b97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ # Multi-stage Dockerfile for QCX - Optimized for Google Cloud Build and Production -# Uses latest stable Bun with Alpine for smaller images and better compatibility (as of January 2026) +# Uses pinned Bun v1.3.5-alpine for reproducible builds (January 2026) # Stage 1: Install dependencies -FROM oven/bun:alpine AS deps +FROM oven/bun:1.3.5-alpine AS deps WORKDIR /app @@ -13,7 +13,7 @@ COPY package.json bun.lock* ./ RUN bun install --frozen-lockfile # Stage 2: Build the Next.js application -FROM oven/bun:alpine AS builder +FROM oven/bun:1.3.5-alpine AS builder WORKDIR /app @@ -31,13 +31,13 @@ ENV NODE_ENV=production RUN bun run build # Stage 3: Production runtime (minimal image running with Bun) -FROM oven/bun:alpine AS runner +FROM oven/bun:1.3.5-alpine AS runner WORKDIR /app -# Create non-root user for security +# Create non-root group and user, with nextjs belonging to nodejs group RUN addgroup -g 1001 -S nodejs \ - && adduser -S nextjs -u 1001 + && adduser -S -u 1001 -G nodejs nextjs # Environment variables ENV NODE_ENV=production @@ -45,7 +45,7 @@ ENV NEXT_TELEMETRY_DISABLED=1 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" -# Copy standalone build output +# Copy standalone build output (optimized for minimal size) COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ # Copy static assets COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static @@ -58,9 +58,9 @@ USER nextjs # Expose port EXPOSE 3000 -# Health check (adjust path if your app has a different health endpoint) +# Health check (uses Bun to fetch; adjust /api/health if your endpoint differs) HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD ["bun", "--eval", "fetch('http://localhost:3000/api/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))"] -# Run with Bun (excellent Node.js compatibility, faster cold starts) +# Run the standalone server with Bun (fully compatible in Bun 1.3+) CMD ["bun", "server.js"] From c6e68639a67c7cddf61f000eebb748b0daeea62a Mon Sep 17 00:00:00 2001 From: EreQ Date: Thu, 8 Jan 2026 12:01:52 +0300 Subject: [PATCH 3/3] Update Dockerfile