From ec04e1bd0badd8c69aea7731bdc464d0f925a756 Mon Sep 17 00:00:00 2001 From: xCyanGrizzly Date: Wed, 18 Feb 2026 20:05:16 +0100 Subject: [PATCH] add docker compose --- .dockerignore | 10 ++++++--- Dockerfile | 48 +++++++++++++++++++++----------------------- docker-entrypoint.sh | 13 +----------- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/.dockerignore b/.dockerignore index 21ce4b7..2106fbe 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,9 +2,13 @@ node_modules .next .git .gitignore -*.md -docker-compose*.yml -.env* +.env +.env.* !.env.example +*.md +Dockerfile +docker-compose*.yml +.dockerignore +.claude .vscode .idea diff --git a/Dockerfile b/Dockerfile index b254ead..d206e52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,51 @@ -# ---- Base ---- FROM node:20-alpine AS base -RUN apk add --no-cache libc6-compat openssl + +# --- Install dependencies --- +FROM base AS deps +RUN apk add --no-cache libc6-compat WORKDIR /app -# ---- Dependencies ---- -FROM base AS deps COPY package.json package-lock.json ./ -RUN npm ci --ignore-scripts COPY prisma ./prisma/ -COPY prisma.config.ts ./ -RUN npx prisma generate +RUN npm ci -# ---- Build ---- +# --- Build the application --- FROM base AS builder WORKDIR /app + COPY --from=deps /app/node_modules ./node_modules COPY . . ENV NEXT_TELEMETRY_DISABLED=1 -ENV NODE_ENV=production - RUN npm run build -# ---- Production ---- +# --- Production image --- FROM base AS runner WORKDIR /app -ENV NEXT_TELEMETRY_DISABLED=1 ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 nextjs -# Copy standalone output +# Copy public assets COPY --from=builder /app/public ./public + +# Copy prisma schema + migrations for runtime migrate deploy +COPY --from=builder /app/prisma ./prisma + +# Copy standalone build output COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static -# Copy Prisma files for migrations -COPY --from=builder /app/prisma ./prisma -COPY --from=builder /app/prisma.config.ts ./prisma.config.ts -COPY --from=deps /app/node_modules/.prisma ./node_modules/.prisma -COPY --from=deps /app/node_modules/@prisma ./node_modules/@prisma +# Copy node_modules for prisma CLI (needed for migrate deploy at startup) +COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma +COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma +COPY --from=builder /app/node_modules/prisma ./node_modules/prisma -# Copy entrypoint -COPY docker-entrypoint.sh ./ +# Copy entrypoint script +COPY --chown=nextjs:nodejs docker-entrypoint.sh ./ RUN chmod +x docker-entrypoint.sh USER nextjs @@ -53,8 +54,5 @@ EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" -HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1 - ENTRYPOINT ["./docker-entrypoint.sh"] CMD ["node", "server.js"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index df4cc06..01e514e 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,20 +1,9 @@ #!/bin/sh set -e -echo "Dragon's Stash - Starting..." - -# Run database migrations echo "Running database migrations..." -npx prisma migrate deploy 2>/dev/null || { - echo "WARNING: Migration failed. Database may not be ready yet." - echo "Retrying in 5 seconds..." - sleep 5 - npx prisma migrate deploy -} +npx prisma migrate deploy -echo "Migrations complete." - -# Optionally seed database if [ "$SEED_DATABASE" = "true" ]; then echo "Seeding database..." npx prisma db seed || echo "Seeding skipped or already done."