Some checks failed
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 2m4s
79 lines
1.8 KiB
Docker
79 lines
1.8 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
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# Generate Prisma client
|
|
RUN bun run db:generate
|
|
|
|
# Build the application
|
|
RUN bun run build
|
|
|
|
# Stage 3: Runner
|
|
FROM node:20-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# 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"]
|