-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
92 lines (69 loc) · 2.28 KB
/
Dockerfile
File metadata and controls
92 lines (69 loc) · 2.28 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
# syntax=docker/dockerfile:1
# ============================================
# Stage 1: Dependencies
# ============================================
FROM oven/bun:1-alpine AS deps
WORKDIR /app
# Copy package files
COPY package.json bun.lock ./
# Install dependencies (production only)
RUN bun install --frozen-lockfile --production
# ============================================
# Stage 2: Builder (for any build steps)
# ============================================
FROM oven/bun:1-alpine AS builder
WORKDIR /app
# Copy package files
COPY package.json bun.lock ./
# Install all dependencies (including dev)
RUN bun install --frozen-lockfile
# Copy source code and config
COPY src ./src
COPY tsconfig.json tsdown.config.ts ./
# Build with tsdown
RUN bun run build
# ============================================
# Stage 3: Production runtime
# ============================================
FROM oven/bun:1-alpine AS runtime
# Install runtime dependencies for sharp and resvg-js
# These native modules need specific system libraries
RUN apk add --no-cache \
libstdc++ \
libgcc \
# For sharp (libvips)
vips-dev \
# For general networking
ca-certificates \
# For healthcheck
curl
# Create non-root user for security
RUN addgroup -g 1001 -S pixelserve && \
adduser -u 1001 -S pixelserve -G pixelserve
WORKDIR /app
# Copy production dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Copy source code (Bun runs TypeScript directly)
COPY --chown=pixelserve:pixelserve src ./src
COPY --chown=pixelserve:pixelserve package.json ./
# Copy templates directory
COPY --chown=pixelserve:pixelserve templates ./templates
# Create cache and fonts directories with proper permissions
RUN mkdir -p cache fonts && \
chown -R pixelserve:pixelserve cache fonts
# Environment variables with sensible defaults
ENV NODE_ENV=production \
PORT=3000 \
CACHE_MODE=disk \
CACHE_DIR=./cache \
TEMPLATES_DIR=./templates \
CLUSTER_WORKERS=0
# Switch to non-root user
USER pixelserve
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# Start the application (clustered mode for multi-core utilization)
CMD ["bun", "run", "src/cluster.ts"]