-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (57 loc) · 2.23 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (57 loc) · 2.23 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
# Multi-stage optimized build for Hook Forge
# Uses Bun 1.2 for ultra-fast builds and execution
# --- STAGE 0: BASE ---
FROM oven/bun:1.2-alpine AS base
WORKDIR /app
# --- STAGE 1: DEV DEPENDENCIES ---
# Installs everything (including compilers like tsc)
FROM base AS dev-deps
# Ensure we install devDeps
ENV NODE_ENV=development
COPY package.json bun.lock ./
COPY client/package.json client/bun.lock ./client/
COPY server/package.json server/bun.lock ./server/
RUN bun install --frozen-lockfile
RUN cd client && bun install --frozen-lockfile
RUN cd server && bun install --frozen-lockfile
# --- STAGE 2: PRODUCTION DEPENDENCIES ---
# Installs ONLY production dependencies for the final runner
FROM base AS prod-deps
ENV NODE_ENV=production
COPY package.json bun.lock ./
COPY server/package.json server/bun.lock ./server/
# We only need server production deps for the runner
RUN cd server && bun install --frozen-lockfile --production
# --- STAGE 3: BUILD CLIENT ---
FROM base AS client-builder
COPY --from=dev-deps /app/client/node_modules ./client/node_modules
COPY client/ ./client/
RUN cd client && bun run build
# --- STAGE 4: BUILD SERVER ---
FROM base AS server-builder
COPY --from=dev-deps /app/server/node_modules ./server/node_modules
COPY server/ ./server/
RUN cd server && bun run build
# --- STAGE 5: RUNNER ---
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
# Create a non-root user for security
RUN addgroup --system --gid 1001 bunjs && \
adduser --system --uid 1001 hookforge
# Copy only what's necessary for execution
# 1. API Binary/JS build
COPY --from=server-builder --chown=hookforge:bunjs /app/server/dist ./server/dist
# 2. Production dependencies
COPY --from=prod-deps --chown=hookforge:bunjs /app/server/node_modules ./server/node_modules
# 3. Frontend static files (served by the Express server)
COPY --from=client-builder --chown=hookforge:bunjs /app/client/dist ./client/dist
# 4. Root configurations
COPY --chown=hookforge:bunjs package.json ./package.json
COPY --chown=hookforge:bunjs server/package.json ./server/package.json
# Setup data persistence directory
RUN mkdir -p /app/server/data && chown -R hookforge:bunjs /app/server/data
USER hookforge
EXPOSE 3001
# Start the server using bun
CMD ["bun", "run", "start:prod"]