From df9f598d8761d8b254cb0f5dd247a24b8a6d66a8 Mon Sep 17 00:00:00 2001 From: owenqwenstarsky Date: Sat, 24 Jan 2026 17:02:39 -0600 Subject: [PATCH] Adding docker files --- .dockerignore | 12 +++++++++++ Dockerfile | 54 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 31 ++++++++++++++++++++++++++ next.config.ts | 1 + 4 files changed, 98 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..48e08f6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +Dockerfile +.dockerignore +docker-compose.yml +node_modules +npm-debug.log +.next +.git +.gitignore +README.md +.env +.env.* +!.env.example diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..26a0052 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +FROM node:20-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# Copy package files +COPY package.json package-lock.json* ./ +COPY prisma ./prisma/ + +# Install dependencies +RUN npm ci + +# Generate Prisma client +RUN npx prisma generate + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Build the application +RUN npm run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public +COPY --from=builder /app/prisma ./prisma + +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# Automatically leverage output traces to reduce image size +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..31d0561 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile +# ports: +# - "3000:3000" + environment: + - DATABASE_URL=postgresql://postgres:postgres@db:5432/teachmesomethingnew + depends_on: + db: + condition: service_healthy + restart: unless-stopped + + db: + image: postgres:16-alpine + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=teachmesomethingnew + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + restart: unless-stopped + +volumes: + postgres_data: diff --git a/next.config.ts b/next.config.ts index 63ecdb3..b466da0 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { + output: 'standalone', images: { remotePatterns: [ {