Containerfile
| 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 |
| 5 | 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. |
| 13 | COPY . . |
| 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 | # catatonit is a tiny init that reaps zombies and forwards signals to the server. |
| 22 | RUN apk add --no-cache libstdc++ libgcc catatonit |
| 23 | |
| 24 | # The compiled server plus the static assets it serves from ./assets at runtime. |
| 25 | COPY --from=build /app/zbin-server ./zbin-server |
| 26 | COPY --from=build /app/assets ./assets |
| 27 | |
| 28 | EXPOSE 3000 |
| 29 | ENTRYPOINT ["/usr/bin/catatonit", "--"] |
| 30 | CMD ["./zbin-server"] |
| 31 |