feat: docker and compose

This commit is contained in:
Julien Froidefond
2025-12-01 08:14:04 +01:00
parent 34874aae86
commit 86236aeb04
4 changed files with 104 additions and 0 deletions

16
.dockerignore Normal file
View File

@@ -0,0 +1,16 @@
node_modules
.next
.git
.gitignore
.env
.env.local
.env*.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.DS_Store
*.pem
README.md
.vscode
.idea

67
Dockerfile Normal file
View File

@@ -0,0 +1,67 @@
FROM node:20-alpine AS base
# Install OpenSSL and libc6-compat for Prisma
RUN apk add --no-cache openssl3 libc6-compat
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# Install dependencies only when needed
FROM base AS deps
WORKDIR /app
# Copy package files
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build args for environment variables needed during build
ARG NEXTAUTH_SECRET=dummy-secret-for-build-only
ARG NEXTAUTH_URL=http://localhost:3000
ARG DATABASE_URL=file:./prisma/dev.db
# Set environment variables for build
ENV NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
ENV NEXTAUTH_URL=${NEXTAUTH_URL}
ENV DATABASE_URL=${DATABASE_URL}
ENV NODE_ENV=production
# Generate Prisma Client
RUN pnpm prisma generate
# Build Next.js
RUN pnpm build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV DATABASE_URL=file:./prisma/dev.db
ENV NEXTAUTH_URL=http://localhost:3000
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Copy prisma schema (will be mounted as volume in dev)
COPY --from=builder /app/prisma ./prisma
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]

20
docker-compose.yml Normal file
View File

@@ -0,0 +1,20 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET:-dummy-secret-for-build-only}
- NEXTAUTH_URL=${NEXTAUTH_URL:-http://localhost:4000}
- DATABASE_URL=${DATABASE_URL:-file:./prisma/dev.db}
ports:
- "4000:3000"
volumes:
- ./prisma:/app/prisma
environment:
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
- NEXTAUTH_URL=${NEXTAUTH_URL:-http://localhost:4000}
- DATABASE_URL=${DATABASE_URL:-file:./prisma/dev.db}
env_file:
- .env

View File

@@ -6,6 +6,7 @@ const nextConfig = {
images: { images: {
unoptimized: true, unoptimized: true,
}, },
output: 'standalone',
}; };
export default nextConfig; export default nextConfig;