improve container build

AuthorKonata <konata@posteo.jp>
Date
Commit6aa994c3908bcd1cc508bbbf8c6493e48ad779e4
Parent85792be
1 file changed, 25 insertions(+), 5 deletions(-)
MContainerfile
@@ -1,8 +1,28 @@
1-FROM debian:12-slim
2-RUN apt-get update && apt-get install -y curl unzip
3-RUN curl -fsSL https://bun.sh/install | bash
1+# --- build stage -------------------------------------------------------------
2+# Use the Alpine-flavored Bun image so the compiled binary is musl-linked and
3+# runs directly on the Alpine runtime image below.
4+FROM oven/bun:1-alpine AS build
45 WORKDIR /app
6+
7+# Install deps first for better layer caching.
8+COPY package.json bun.lock ./
9+RUN bun install --frozen-lockfile
10+
11+# Build the client bundles into assets/dist, then compile the server into a
12+# single standalone binary that embeds the Bun runtime.
513 COPY . .
6-RUN /root/.bun/bin/bun install
14+RUN bun run build && bun build --compile src/index.ts --outfile zbin-server
15+
16+# --- runtime stage -----------------------------------------------------------
17+FROM alpine:3.21
18+WORKDIR /app
19+
20+# The musl-linked Bun binary still dynamically links libstdc++/libgcc.
21+RUN apk add --no-cache libstdc++ libgcc
22+
23+# The compiled server plus the static assets it serves from ./assets at runtime.
24+COPY --from=build /app/zbin-server ./zbin-server
25+COPY --from=build /app/assets ./assets
26+
727 EXPOSE 3000
8-CMD ["/root/.bun/bin/bun", "run", "prod"]
28+CMD ["./zbin-server"]