Skip to content

Commit b5b9a07

Browse files
committed
chore: Optimize docker image size 225MB -> 107MB
1 parent 422d817 commit b5b9a07

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

.dockerignore

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
.github
12
node_modules
2-
**/*.test.*
3-
/.*
43
/*.md
5-
tsconfig.tsbuildinfo
4+
.gitignore
5+
**/*.test.*
6+
cspell.yml
7+
scripts
8+
LICENSE
9+
Dockerfile
10+
.output
11+
.prettierignore
12+
.git
13+
.gitattributes
14+
.dockerignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ logs
55
# Generated files
66
node_modules
77
dist
8+
.output
89
src/@types/gql.d.ts
910
tsconfig.tsbuildinfo
1011

Dockerfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
FROM oven/bun AS base
2-
WORKDIR /app
3-
COPY package.json package.json
4-
COPY bun.lock bun.lock
5-
RUN bun install --production --ignore-scripts
1+
FROM oven/bun:1.3.12-alpine AS builder
2+
WORKDIR /build
3+
COPY package.json bun.lock ./
4+
RUN bun install --frozen-lockfile
65
COPY . .
7-
ENTRYPOINT ["bun", "src/main.ts"]
6+
RUN bun run build
7+
8+
FROM alpine:3.21
9+
RUN apk add --no-cache libstdc++ libgcc
10+
COPY --from=builder /build/.output/server server
11+
RUN adduser -D app
12+
USER app
13+
ENTRYPOINT ["/server"]

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
"type": "module",
55
"packageManager": "bun@1.3.12",
66
"scripts": {
7+
"check": "check",
78
"dev": "bun run --watch scripts/dev.ts",
9+
"build": "bun build src/main.ts --compile --minify --sourcemap --bytecode --outfile .output/server",
810
"gen": "bun run gen:types",
911
"gen:types": "bun run scripts/generate-types.ts",
1012
"docker:build": "docker build . -t aklinker1/store-api",
11-
"docker:run": "docker run -it -p 3000:3000 aklinker1/store-api",
13+
"docker:run": "docker run --rm -p 3000:3000 aklinker1/store-api",
1214
"docker:build:amd": "bun docker:build --platform linux/amd64",
1315
"docker:push": "bun docker:build --platform linux/amd64 && docker push aklinker1/store-api",
14-
"postinstall": "simple-git-hooks",
15-
"check": "check"
16+
"postinstall": "simple-git-hooks"
1617
},
1718
"dependencies": {
1819
"@aklinker1/zero-ioc": "^1.5.1",

0 commit comments

Comments
 (0)