Files
Mana-Loop/Dockerfile
zhipu 5e9f560f26
Some checks failed
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 2m4s
Fix Docker build: use npx prisma generate and multi-stage build
2026-03-25 17:47:27 +00:00

90 lines
2.1 KiB
Docker

# Mana Loop - Next.js Game Docker Image
# Multi-stage build for optimized production image
# Stage 1: Dependencies
FROM node:20-alpine AS deps
WORKDIR /app
# Install dependencies for native modules
RUN apk add --no-cache libc6-compat openssl
# Copy package files
COPY package.json bun.lockb* ./
COPY prisma ./prisma/
# Install bun for faster installs
RUN npm install -g bun
# Install dependencies (including devDependencies for build)
RUN bun install --frozen-lockfile
# Stage 2: Builder
FROM node:20-alpine AS builder
WORKDIR /app
# Install openssl for Prisma
RUN apk add --no-cache openssl
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Install bun for build
RUN npm install -g bun
# Set environment variables for build
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
ENV DATABASE_URL="file:./dev.db"
# Generate Prisma client using npx (more reliable in Docker)
RUN npx prisma generate --schema=./prisma/schema.prisma
# Build the application
RUN bun run build
# Stage 3: Runner
FROM node:20-alpine AS runner
WORKDIR /app
# Install openssl for Prisma
RUN apk add --no-cache openssl
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV DATABASE_URL="file:./data/dev.db"
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Create data directory for SQLite
RUN mkdir -p /app/data && chown nextjs:nodejs /app/data
# Copy necessary files from builder
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
# Set correct ownership
RUN chown -R nextjs:nodejs /app
# Switch to non-root user
USER nextjs
# Expose port
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1
# Start the server
CMD ["node", "server.js"]