FROM node:20-alpine AS runner
WORKDIR /app

ENV NODE_ENV production
ENV PORT 3000

# Install OpenSSL for compatibility
RUN apk add --no-cache openssl

# Copy necessary files
# Standalone build already includes node_modules
COPY .next/standalone ./
COPY .next/static ./.next/static
COPY public ./public

# Copy prisma for database migrations
COPY prisma ./prisma

EXPOSE 3000

# Run migrations and then start the server
CMD ["sh", "-c", "npx prisma db push && node server.js"]
