63 lines
2.1 KiB
Docker
63 lines
2.1 KiB
Docker
# Production-ready Dockerfile for Next.js
|
|
|
|
# Receive build arguments passed by Coolify for the builder stage
|
|
ARG NEXT_PUBLIC_SUPABASE_URL
|
|
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
|
|
|
|
# Builder stage
|
|
FROM node:20-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
# 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
|
|
|
|
# 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
|
|
# This will also install eslint if it's in devDependencies and package-lock.json is up to date
|
|
RUN npm ci
|
|
|
|
# Copy the rest of your app's source code from the 'myfavstuff' subdirectory
|
|
COPY myfavstuff .
|
|
|
|
# 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
|
|
|
|
# Production stage (runner)
|
|
FROM node:20-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
# Runtime environment variables will be set by Coolify directly in the container environment.
|
|
|
|
# Create a non-root user for security IN THIS STAGE
|
|
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
|
|
|
|
# Copy standalone output from the builder stage
|
|
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 assets (if any, like favicon, images in /public)
|
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME=0.0.0.0
|
|
|
|
# Run the Next.js standalone server
|
|
CMD ["node", "server.js"]
|