Files
Mana-Loop/Dockerfile
zhipu ee0268d9f6
All checks were successful
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 3m11s
Fix Docker build: exclude .config file and simplify Dockerfile
2026-03-25 18:00:09 +00:00

77 lines
1.8 KiB
Docker

# Mana Loop - Next.js Game Docker Image
FROM node:20-alpine AS builder
WORKDIR /app
# Install dependencies
RUN apk add --no-cache libc6-compat openssl
# Install bun
RUN npm install -g bun
# Copy package files first for better caching
COPY package.json bun.lockb* ./
COPY prisma ./prisma/
# Install dependencies
RUN bun install --frozen-lockfile
# Copy the rest of the application
COPY . .
# Set environment variables for build
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
ENV DATABASE_URL="file:./dev.db"
# Generate Prisma client
RUN bunx prisma generate --schema=./prisma/schema.prisma
# Build the application
RUN bun run build
# Production image
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"]