improve container build

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