feat: add Supabase environment variables and optimize Docker build process

This commit is contained in:
Greg 2025-05-18 16:23:20 +02:00
parent 0bd850b40d
commit 9d0debb968

View File

@ -1,22 +1,27 @@
# Production-ready Dockerfile for Next.js # Production-ready Dockerfile for Next.js
FROM node:20-alpine AS builder # Receive build arguments passed by Coolify
ARG NEXT_PUBLIC_SUPABASE_URL
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
# Set the working directory in the container # Builder stage
FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Set environment variables for the builder stage from build arguments
ENV NODE_ENV=production 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 package.json and package-lock.json from the 'myfavstuff' subdirectory
COPY myfavstuff/package.json myfavstuff/package-lock.json* ./ COPY myfavstuff/package.json myfavstuff/package-lock.json* ./
# Install dependencies # Install dependencies including dev dependencies needed for build
# Using npm ci for cleaner installs based on package-lock.json
RUN npm ci RUN npm ci
# Copy the rest of your app's source code from the 'myfavstuff' subdirectory # Copy the rest of your app's source code from the 'myfavstuff' subdirectory
COPY myfavstuff . COPY myfavstuff .
# Build the Next.js application # Debug the environment variables
RUN echo "--- Debugging Build Environment Variables (Builder Stage) ---" && \ RUN echo "--- Debugging Build Environment Variables (Builder Stage) ---" && \
echo "NEXT_PUBLIC_SUPABASE_URL: ($NEXT_PUBLIC_SUPABASE_URL)" && \ echo "NEXT_PUBLIC_SUPABASE_URL: ($NEXT_PUBLIC_SUPABASE_URL)" && \
echo "NEXT_PUBLIC_SUPABASE_ANON_KEY: ($NEXT_PUBLIC_SUPABASE_ANON_KEY)" && \ echo "NEXT_PUBLIC_SUPABASE_ANON_KEY: ($NEXT_PUBLIC_SUPABASE_ANON_KEY)" && \
@ -31,17 +36,18 @@ FROM node:20-alpine AS runner
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production 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 --from=builder /app/public ./public COPY --from=builder /app/public ./public
# Next.js 15 uses a standalone output by default in the .next/standalone directory # Look for .next output (either standalone or regular)
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs USER nextjs
EXPOSE 3000 EXPOSE 3000
ENV PORT 3000 ENV PORT=3000
ENV HOSTNAME 0.0.0.0 ENV HOSTNAME=0.0.0.0
CMD ["node", "server.js"] CMD ["npm", "start"]