Skip to content

Commit 00ed790

Browse files
committed
build(docker): compile all services to distroless via turbo prune
- api: migrate from slim runtime + bun run to compiled binary on distroless (bundles 3027 modules via bun build --compile --minify --bytecode) - basket, links, uptime: replace manual per-package COPY lists with turbo prune --docker so adding a shared dep no longer requires editing every Dockerfile - dockerignore: remove duplicate entries (node_modules appeared 3x, dist 2x) All four services now share the same pruner -> builder -> distroless pattern.
1 parent 744a9ae commit 00ed790

5 files changed

Lines changed: 85 additions & 106 deletions

File tree

.dockerignore

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,55 @@
1-
# Dependencies
21
**/node_modules
2+
node_modules
3+
34
**/.next
5+
**/out
46
**/dist
7+
**/build
8+
.next
9+
out
10+
dist
11+
build
12+
13+
**/.turbo
14+
**/.wrangler
15+
.turbo
516

6-
# Development
717
**/.git
818
**/.github
919
**/.vscode
1020
**/.idea
11-
**/*.log
12-
**/.env*
13-
**/.dev.vars
14-
15-
# Build outputs
16-
**/build
17-
**/.turbo
18-
**/.wrangler
21+
.idea
22+
.vscode
1923

20-
# Test files
2124
**/__tests__
2225
**/*.test.*
2326
**/*.spec.*
2427

25-
# Documentation
2628
**/*.md
2729
**/docs
2830
**/LICENSE
2931

30-
# Other
31-
**/.DS_Store
32-
**/.env.local
33-
**/.env.development.local
34-
**/.env.test.local
35-
**/.env.production.local
36-
37-
# Node Dependencies (these should be installed *inside* the Docker image)
38-
# Matches node_modules at the root and in any subdirectory (apps/*, packages/*)
39-
**/node_modules
40-
node_modules
41-
42-
# Turborepo Cache & Logs
43-
.turbo
44-
*.log
45-
46-
# Build Artifacts (these should be generated *inside* the builder stage)
47-
# Add any other build output directories your apps/packages might use
48-
**/dist
49-
**/build
50-
**/.next
51-
**/out
52-
dist
53-
build
54-
.next
55-
out
56-
57-
# Local Environment Variables & Secrets
58-
# Avoid baking secrets into the image. Use runtime ENV variables or Docker secrets.
5932
.env*
6033
!.env.example
6134
!.env.template
35+
**/.env*
36+
**/.dev.vars
6237

63-
# Test Reports & Coverage
64-
coverage
6538
**/coverage
39+
coverage
6640
lcov.info
6741
*.lcov
6842

69-
# Operating System / Editor specific files
43+
**/.DS_Store
7044
.DS_Store
7145
Thumbs.db
72-
.idea
73-
.vscode
7446

75-
# Dependency Debug Logs
47+
*.log
7648
npm-debug.log*
7749
yarn-error.log*
7850
yarn-debug.log*
7951

80-
# Optional: TypeScript build info cache (if using)
8152
*.tsbuildinfo
8253

83-
# Optional: Specific temporary files or folders
8454
tmp/
85-
temp/
55+
temp/

api.Dockerfile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,32 @@ FROM oven/bun:1.3.11-slim AS builder
1111
WORKDIR /app
1212

1313
COPY --from=pruner /app/out/json/ .
14-
RUN bun install --ignore-scripts
14+
RUN bun install --frozen-lockfile --ignore-scripts
1515

1616
COPY --from=pruner /app/out/full/ .
1717
COPY turbo.json turbo.json
18-
RUN bunx turbo build --filter=@databuddy/api...
1918

20-
FROM oven/bun:1.3.11-slim
19+
ENV NODE_ENV=production
20+
21+
WORKDIR /app/apps/api
22+
23+
RUN bun build \
24+
--compile \
25+
--minify \
26+
--sourcemap \
27+
--bytecode \
28+
--outfile /app/server \
29+
./src/index.ts
30+
31+
FROM oven/bun:1.3.11-distroless
2132

2233
WORKDIR /app
2334

24-
COPY --from=builder /app/package.json ./
25-
COPY --from=builder /app/node_modules ./node_modules
26-
COPY --from=builder /app/apps/api ./apps/api
27-
COPY --from=builder /app/packages ./packages
35+
COPY --from=builder /app/server server
2836

2937
ENV NODE_ENV=production
3038

3139
EXPOSE 3001
3240

33-
WORKDIR /app/apps/api
34-
35-
CMD ["bun", "run", "src/index.ts"]
41+
ENTRYPOINT []
42+
CMD ["./server"]

basket.Dockerfile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
FROM oven/bun:1.3.11-slim AS build
1+
FROM oven/bun:1.3.11-slim AS pruner
22

33
WORKDIR /app
44

5-
COPY package.json package.json
6-
COPY bun.lock bun.lock
7-
COPY apps/basket/package.json ./apps/basket/package.json
8-
COPY packages/*/package.json ./packages/
5+
COPY . .
96

10-
COPY packages/ ./packages/
7+
RUN bunx turbo prune @databuddy/basket --docker
118

12-
RUN bun install --ignore-scripts
9+
FROM oven/bun:1.3.11-slim AS builder
1310

14-
COPY apps/basket/src ./apps/basket/src
15-
COPY apps/basket/tsconfig.json ./apps/basket/tsconfig.json
11+
WORKDIR /app
12+
13+
COPY --from=pruner /app/out/json/ .
14+
RUN bun install --frozen-lockfile --ignore-scripts
15+
16+
COPY --from=pruner /app/out/full/ .
17+
COPY turbo.json turbo.json
1618

1719
ENV NODE_ENV=production
1820

1921
WORKDIR /app/apps/basket
2022

2123
RUN bun build \
2224
--compile \
23-
--minify-whitespace \
24-
--minify-syntax \
25-
--target bun \
26-
--outfile /app/server \
25+
--minify \
2726
--sourcemap \
2827
--bytecode \
28+
--outfile /app/server \
2929
./src/index.ts
3030

3131
FROM oven/bun:1.3.11-distroless
3232

3333
WORKDIR /app
3434

35-
COPY --from=build /app/server server
35+
COPY --from=builder /app/server server
3636

3737
ENV NODE_ENV=production
3838

links.Dockerfile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
FROM oven/bun:1.3.11-slim AS build
1+
FROM oven/bun:1.3.11-slim AS pruner
22

33
WORKDIR /app
44

5-
COPY package.json package.json
6-
COPY bun.lock bun.lock
7-
COPY apps/links/package.json ./apps/links/package.json
8-
COPY packages/*/package.json ./packages/
5+
COPY . .
96

10-
COPY packages/ ./packages/
7+
RUN bunx turbo prune @databuddy/links --docker
118

12-
RUN bun install --ignore-scripts
9+
FROM oven/bun:1.3.11-slim AS builder
1310

14-
COPY apps/links/src ./apps/links/src
15-
COPY apps/links/tsconfig.json ./apps/links/tsconfig.json
11+
WORKDIR /app
12+
13+
COPY --from=pruner /app/out/json/ .
14+
RUN bun install --frozen-lockfile --ignore-scripts
15+
16+
COPY --from=pruner /app/out/full/ .
17+
COPY turbo.json turbo.json
1618

1719
ENV NODE_ENV=production
1820

1921
WORKDIR /app/apps/links
2022

2123
RUN bun build \
2224
--compile \
23-
--minify-whitespace \
24-
--minify-syntax \
25-
--target bun \
26-
--outfile /app/server \
25+
--minify \
2726
--sourcemap \
2827
--bytecode \
28+
--outfile /app/server \
2929
./src/index.ts
3030

3131
FROM oven/bun:1.3.11-distroless
3232

3333
WORKDIR /app
3434

35-
COPY --from=build /app/server server
35+
COPY --from=builder /app/server server
3636

3737
ENV NODE_ENV=production
3838

uptime.Dockerfile

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
FROM oven/bun:1.3.11-slim AS build
1+
FROM oven/bun:1.3.11-slim AS pruner
22

33
WORKDIR /app
44

5-
COPY package.json package.json
6-
COPY bun.lock bun.lock
7-
COPY apps/uptime/package.json ./apps/uptime/package.json
8-
COPY packages/*/package.json ./packages/
5+
COPY . .
96

10-
COPY packages/ ./packages/
7+
RUN bunx turbo prune @databuddy/uptime --docker
118

12-
RUN bun install --ignore-scripts
9+
FROM oven/bun:1.3.11-slim AS builder
1310

14-
COPY apps/uptime/src ./apps/uptime/src
15-
COPY apps/uptime/tsconfig.json ./apps/uptime/tsconfig.json
11+
WORKDIR /app
12+
13+
COPY --from=pruner /app/out/json/ .
14+
RUN bun install --frozen-lockfile --ignore-scripts
15+
16+
COPY --from=pruner /app/out/full/ .
17+
COPY turbo.json turbo.json
1618

1719
ENV NODE_ENV=production
1820

21+
WORKDIR /app/apps/uptime
22+
1923
RUN bun build \
20-
--compile \
21-
--minify-whitespace \
22-
--minify-syntax \
23-
--target bun \
24-
--outfile /app/server \
25-
--sourcemap \
26-
--bytecode \
27-
./apps/uptime/src/index.ts
24+
--compile \
25+
--minify \
26+
--sourcemap \
27+
--bytecode \
28+
--outfile /app/server \
29+
./src/index.ts
2830

2931
FROM oven/bun:1.3.11-distroless
3032

3133
WORKDIR /app
3234

33-
COPY --from=build /app/server server
35+
COPY --from=builder /app/server server
3436

3537
ENV NODE_ENV=production
3638

0 commit comments

Comments
 (0)