-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (53 loc) · 2.3 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (53 loc) · 2.3 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
# Bun + Elysia — multi-stage. Runs from source (Bun resolves tsconfig paths).
FROM oven/bun:1.2-alpine AS base
WORKDIR /app
# ===================================================
# Stage 1: Install dependencies (cached on lockfile)
# ===================================================
FROM base AS install
# dev deps (drizzle-kit, types, ...) — used by the dev image and migrations
RUN mkdir -p /temp/dev
COPY package.json bun.lock /temp/dev/
# --ignore-scripts: skips the "prepare" lifecycle (husky install) — git hooks
# don't exist inside an image, and husky is a devDependency anyway.
RUN cd /temp/dev && bun install --frozen-lockfile --ignore-scripts
# prod-only deps — used by the release image
RUN mkdir -p /temp/prod
COPY package.json bun.lock /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production --ignore-scripts
# ===================================================
# Stage 2: Development (hot reload)
# ===================================================
FROM base AS development
COPY --from=install /temp/dev/node_modules node_modules
COPY . .
ENV NODE_ENV=development
EXPOSE 3000/tcp
CMD ["bun", "run", "dev"]
# ===================================================
# Stage 3: Migrator (drizzle-kit needs dev deps)
# docker build --target migrator -t clean-elysia:migrator .
# docker run --rm --env-file .env clean-elysia:migrator
# ===================================================
FROM base AS migrator
COPY --from=install /temp/dev/node_modules node_modules
COPY src ./src
COPY tsconfig.json package.json drizzle.config.ts ./
ENV NODE_ENV=production
ENTRYPOINT ["bun", "run", "db:migrate"]
# ===================================================
# Stage 4: Production release (app only, prod deps)
# ===================================================
FROM base AS release
ENV NODE_ENV=production
COPY --from=install /temp/prod/node_modules node_modules
# Source + the files Bun needs to resolve aliases. No build step: src/index.ts
# is the entry and honours APP_CLUSTER_MODE / APP_REUSE_PORT at runtime.
COPY src ./src
COPY tsconfig.json package.json drizzle.config.ts ./
# pino writes to storage/logs/ relative to cwd — must exist and be writable
# by the non-root `bun` user.
RUN mkdir -p storage/logs && chown -R bun:bun storage
USER bun
EXPOSE 3000/tcp
ENTRYPOINT ["bun", "run", "src/index.ts"]