-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerfile
More file actions
71 lines (54 loc) · 3.33 KB
/
Copy pathContainerfile
File metadata and controls
71 lines (54 loc) · 3.33 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
# ── Build stage ───────────────────────────────────────────────────────────────
FROM rust:1.96-slim-bookworm@sha256:c8a94a78f67ec8c4d474ec7f71e0720f21eb7e584e158daec0874cafa7c30e4d AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config libssl-dev curl \
&& 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:95a34da32a840bd9b3b09a5b773591c16923e350174b1c50e1200c75bf15eaa9 AS ui-builder
WORKDIR /ui
COPY ui/package.json ui/package-lock.json ./
RUN npm ci
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 && \
npm run generate && \
npm run build
# ── Runtime image ─────────────────────────────────────────────────────────────
FROM gcr.io/distroless/cc-debian12:latest@sha256:d703b626ba455c4e6c6fbe5f36e6f427c85d51445598d564652a2f334179f96e 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"]