-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerfile
More file actions
77 lines (60 loc) · 3.73 KB
/
Copy pathContainerfile
File metadata and controls
77 lines (60 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# ── Build stage ───────────────────────────────────────────────────────────────
FROM rust:1.97-slim-bookworm@sha256:99e09cb2284e2ddbb73a995deee3e91783fd04d177602ccf6eab326d778ee777 AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config libssl-dev curl make \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
# Cache dependency compilation separately from source changes.
COPY Cargo.toml Cargo.lock ./
COPY crates/core/Cargo.toml crates/core/Cargo.toml
COPY crates/config/Cargo.toml crates/config/Cargo.toml
COPY crates/adapters/Cargo.toml crates/adapters/Cargo.toml
COPY crates/web/Cargo.toml crates/web/Cargo.toml
COPY crates/examples/Cargo.toml crates/examples/Cargo.toml
COPY server/Cargo.toml server/Cargo.toml
COPY cli/Cargo.toml cli/Cargo.toml
COPY patches/ patches/
# Stub out every lib/main so cargo can resolve and compile deps.
RUN for crate in crates/core crates/config crates/adapters crates/web; do \
mkdir -p $crate/src && echo "pub fn _stub() {}" > $crate/src/lib.rs; \
done && \
mkdir -p crates/examples/src && echo "pub fn _stub() {}" > crates/examples/src/lib.rs && \
mkdir -p server/src && echo "fn main() {}" > server/src/main.rs && \
mkdir -p cli/src && echo "fn main() {}" > cli/src/main.rs
RUN cargo build --release -p batlehub-server -p batlehub-cli 2>/dev/null; exit 0
# Now copy real source and rebuild (only changed crates recompile).
COPY crates/ crates/
COPY server/ server/
COPY cli/ cli/
# Touch lib/main files so cargo detects the change.
RUN touch crates/*/src/lib.rs server/src/main.rs cli/src/main.rs
RUN cargo build --release -p batlehub-server -p batlehub-cli
# Pre-create runtime directories so they can be copied into the shell-less distroless image.
RUN mkdir -p /var/cache/batlehub
# ── Frontend build stage ───────────────────────────────────────────────────────
FROM node:26-slim@sha256:715e55e4b84e4bb0ff48e49b398a848f08e55daed8eb6a0ea1839ae53bc57583 AS ui-builder
WORKDIR /ui
# Corepack is no longer distributed with Node (removed in Node 25), so pnpm is
# installed explicitly. Keep this version in sync with the `packageManager`
# field in ui/package.json.
RUN npm install -g pnpm@11.15.1
COPY ui/package.json ui/pnpm-lock.yaml ui/pnpm-workspace.yaml ./
# --frozen-lockfile is the `npm ci` equivalent: it fails rather than silently
# resolving something the committed lockfile does not describe.
RUN pnpm install --frozen-lockfile
COPY ui/ ./
# Generate the OpenAPI spec from the just-built binary and then the TS client.
COPY --from=builder /build/target/release/batlehub /usr/local/bin/batlehub
COPY config.example.toml /etc/batlehub/config.toml
RUN batlehub --config /etc/batlehub/config.toml dump-spec > openapi.json && \
pnpm run generate && \
pnpm run build
# ── Runtime image ─────────────────────────────────────────────────────────────
FROM gcr.io/distroless/cc-debian12:latest@sha256:7ee09f36862efbdbf70422db263e411c2618409ca46faa555bd5b636155307df AS runtime
COPY --from=builder /build/target/release/batlehub /usr/local/bin/batlehub
COPY --from=builder /build/target/release/batlehub-cli /usr/local/bin/batlehub-cli
COPY --from=builder /var/cache/batlehub /var/cache/batlehub
COPY --from=ui-builder /ui/dist /app/ui/dist
EXPOSE 8080
ENTRYPOINT ["batlehub"]
CMD ["--config", "/etc/batlehub/config.toml"]