Skip to content

Commit 0935ed1

Browse files
committed
build: Refactor Dockerfile for multi-stage build and smaller image size
1 parent 03d9006 commit 0935ed1

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

Dockerfile

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
FROM oven/bun:1.2.5 AS base
2-
WORKDIR /usr/src/app
1+
FROM oven/bun:alpine AS builder
2+
WORKDIR /app
33

4-
FROM base AS install
5-
COPY package.json bun.lock ./
6-
RUN bun install --frozen-lockfile --production
4+
COPY ./package.json ./bun.lock ./
5+
RUN bun install --frozen-lockfile
76

8-
9-
FROM base AS prerelease
10-
COPY --from=install /usr/src/app/node_modules node_modules
117
COPY . .
12-
13-
ENV NODE_ENV=production
14-
RUN bun test
158
RUN bun run build
169

17-
FROM base AS release
18-
COPY --from=install /usr/src/app/node_modules node_modules
19-
COPY --from=prerelease /usr/src/app/dist/ .
10+
FROM oven/bun:alpine AS runner
11+
WORKDIR /app
12+
13+
COPY ./package.json ./bun.lock ./
14+
RUN bun install --frozen-lockfile --production --ignore-scripts --no-cache
15+
16+
COPY --from=builder /app/dist ./dist
17+
18+
EXPOSE 4141
2019

21-
USER bun
22-
EXPOSE 4141/tcp
23-
ENTRYPOINT [ "bun", "main.js"]
20+
CMD ["bun", "run", "dist/main.js"]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"knip": "knip-bun",
2828
"lint": "eslint .",
2929
"prepack": "bun run build",
30-
"prepare": "NODE_ENV=production || simple-git-hooks",
30+
"prepare": "simple-git-hooks",
3131
"release": "bumpp && bun publish --access public",
3232
"start": "NODE_ENV=production bun run ./src/main.ts"
3333
},

0 commit comments

Comments
 (0)