diff --git a/Dockerfile b/Dockerfile index 10a76f6..ef7399e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # Production-ready Dockerfile for Next.js -# Receive build arguments passed by Coolify + +# Receive build arguments passed by Coolify for the builder stage ARG NEXT_PUBLIC_SUPABASE_URL ARG NEXT_PUBLIC_SUPABASE_ANON_KEY @@ -7,41 +8,47 @@ ARG NEXT_PUBLIC_SUPABASE_ANON_KEY FROM node:20-alpine AS builder WORKDIR /app -# Set environment variables for the builder stage from build arguments +# These ARGs are available to RUN commands in this stage +ARG NEXT_PUBLIC_SUPABASE_URL +ARG NEXT_PUBLIC_SUPABASE_ANON_KEY + ENV NODE_ENV=production -ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL -ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY # Copy package.json and package-lock.json from the 'myfavstuff' subdirectory COPY myfavstuff/package.json myfavstuff/package-lock.json* ./ # Install dependencies including dev dependencies needed for build +# npm ci should install eslint from devDependencies RUN npm ci # Copy the rest of your app's source code from the 'myfavstuff' subdirectory COPY myfavstuff . -# Debug the environment variables -RUN echo "--- Debugging Build Environment Variables (Builder Stage) ---" && \ - echo "NEXT_PUBLIC_SUPABASE_URL: ($NEXT_PUBLIC_SUPABASE_URL)" && \ - echo "NEXT_PUBLIC_SUPABASE_ANON_KEY: ($NEXT_PUBLIC_SUPABASE_ANON_KEY)" && \ +# Debug the environment variables that npm run build will see +# Pass ARGs directly to the build command's environment +RUN echo "--- Debugging Build Environment Variables (Passed to Build) ---" && \ + echo "NEXT_PUBLIC_SUPABASE_URL (from ARG): $NEXT_PUBLIC_SUPABASE_URL" && \ + echo "NEXT_PUBLIC_SUPABASE_ANON_KEY (from ARG): $NEXT_PUBLIC_SUPABASE_ANON_KEY" && \ echo "--- End Debugging --- " && \ + NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL \ + NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY \ npm run build -# Use a non-root user for security -RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 - # Production stage FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV=production -ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL -ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY +# Runtime environment variables will be set by Coolify directly in the container environment. +# We don't need to re-declare ARGs here or pass them from the builder stage for runtime ENV. +# Coolify injects them into the final container. + +# Create a non-root user for security IN THIS STAGE +RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 COPY --from=builder /app/public ./public -# Look for .next output (either standalone or regular) COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next +# If you decide to use standalone output later, you'd copy /app/.next/standalone and /app/.next/static USER nextjs @@ -50,4 +57,5 @@ EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME=0.0.0.0 +# The start script in package.json should be `next start` CMD ["npm", "start"] diff --git a/myfavstuff/next.config.js b/myfavstuff/next.config.js index 4a0112d..3b929fe 100644 --- a/myfavstuff/next.config.js +++ b/myfavstuff/next.config.js @@ -1,16 +1,10 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - // Enable output.standalone to create a standalone build - // This is recommended for deployments to containerized environments - output: 'export', - - // Set to true for improved page load performance - swcMinify: true, + // output: 'standalone', // Consider this if you want a smaller Docker image, requires Next.js 12.2+ // Configure images if using them from external domains images: { - unoptimized: true, // For static export - domains: [], + // domains: ['example.com'], // Add your image domains here if needed }, // Add any other configurations needed