A third party ATProto appview
1# Multi-stage build for a lean, production-ready AT Protocol AppView
2
3# Stage 1: Builder
4# This stage installs all dependencies (including dev) and builds the application.
5FROM node:20-slim AS builder
6
7WORKDIR /app
8
9# Copy package files and install all dependencies
10COPY package*.json ./
11RUN npm ci
12
13# Copy the rest of the application source code
14COPY . .
15
16# Build both the frontend (vite) and backend (esbuild)
17RUN npm run build
18
19# Stage 2: Production
20# This stage creates the final, lean image with only what's needed for production.
21FROM node:20-slim
22
23WORKDIR /app
24
25# Copy package files and install only production dependencies
26COPY package*.json ./
27RUN npm ci --omit=dev
28
29# Install drizzle-kit, typescript and dotenv for runtime migrations.
30# These are dev dependencies but are needed by the entrypoint script.
31RUN npm install drizzle-kit@0.31.4 typescript dotenv
32
33# Install PM2 globally for cluster mode
34RUN npm install -g pm2
35
36# Copy the built application from the builder stage
37COPY --from=builder /app/dist ./dist
38
39# Copy configuration files needed for runtime database migrations
40COPY drizzle.config.ts ./
41COPY tsconfig.json ./
42COPY shared ./shared
43
44# Copy and make the entrypoint script executable
45COPY docker-entrypoint.sh ./
46RUN chmod +x docker-entrypoint.sh
47
48# Set production environment
49ENV NODE_ENV=production
50
51# Configuration defaults (can be overridden in docker-compose.yml or at runtime)
52ENV RELAY_URL=wss://bsky.network
53ENV REDIS_URL=redis://localhost:6379
54ENV PORT=5000
55ENV APPVIEW_DID=did:web:appview.local
56ENV DATA_RETENTION_DAYS=0
57ENV DB_POOL_SIZE=32
58ENV MAX_CONCURRENT_OPS=80
59ENV NODE_OPTIONS="--max-old-space-size=2048"
60
61# Expose port
62EXPOSE 5000
63
64# Health check using the /health endpoint
65HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
66 CMD node -e "require('http').get('http://localhost:5000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
67
68# Run the application using the entrypoint script, which handles migrations
69CMD ["./docker-entrypoint.sh"]