MyFavStuff/Dockerfile

62 lines
2.0 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
# 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 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
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.
# 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
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
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
# The start script in package.json should be `next start`
CMD ["npm", "start"]