-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
105 lines (76 loc) · 2.78 KB
/
Dockerfile
File metadata and controls
105 lines (76 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# ==============================================
# Stage 1: Dependencies - install all dependencies once
# Using Debian for compatibility with native modules
# ==============================================
FROM node:20 AS deps
WORKDIR /app
# Copy only dependency files for better caching
COPY package.json yarn.lock ./
# Install dependencies with retry and increased timeout
# --frozen-lockfile - don't update yarn.lock (deterministic build)
# --network-timeout - increased timeout for problematic networks
RUN yarn install --frozen-lockfile --network-timeout 100000
# Copy Prisma schemas and generate clients
COPY prisma ./prisma
RUN npx prisma generate && \
npx prisma generate --schema=prisma/events/schema.prisma
# ==============================================
# Stage 2: Base - base image with code and Prisma clients
# ==============================================
FROM node:20-alpine AS base
# Install redis-cli and other necessary tools
# openssl - for Prisma
# libc6-compat - for compatibility with some Node.js modules
RUN apk add --no-cache redis openssl libc6-compat
WORKDIR /app
# Copy node_modules from deps stage (including Prisma clients)
COPY --from=deps /app/node_modules ./node_modules
# Copy entire project code
COPY . .
# ==============================================
# Stage 3: Builder - build Next.js application
# ==============================================
FROM base AS builder
WORKDIR /app
# Accept DATABASE_URL as build arguments
# Required for Next.js build, since API routes initialize Prisma
ARG DATABASE_URL
ARG EVENTS_DATABASE_URL
# Set as environment variables for build process
ENV DATABASE_URL=${DATABASE_URL}
ENV EVENTS_DATABASE_URL=${EVENTS_DATABASE_URL}
# Build Next.js application
RUN yarn build
# ==============================================
# Stage 4: Migrations - image for database migrations
# ==============================================
FROM base AS migrations
WORKDIR /app
# Create uploads directory
RUN mkdir -p /app/uploads
# Command will be overridden in docker-compose.yml
CMD ["echo", "Migrations service ready"]
# ==============================================
# Stage 5: Frontend - production image for Next.js
# ==============================================
FROM base AS frontend
WORKDIR /app
# Copy built application from builder stage
COPY --from=builder /app/.next ./.next
# Create uploads directory
RUN mkdir -p /app/uploads
# Expose port
EXPOSE 3000
# Start production server
CMD ["yarn", "start"]
# ==============================================
# Stage 6: Indexer - image for background jobs
# ==============================================
FROM base AS indexer
WORKDIR /app
# Create uploads directory
RUN mkdir -p /app/uploads
# Expose port
EXPOSE 3001
# Start indexer (flushall moved to init-chains)
CMD ["npx", "tsx", "server/indexer.ts"]