# clawmates-server: static musl build into distroless. The same image serves # the air-gapped bundle and the cloud registry. FROM rust:1.96-slim AS builder ARG TARGETARCH # git + cmake are needed for the clawhdf5 git dependency (fetched via the git # CLI — libgit2 chokes on Gitea smart-HTTP) and its zlib-ng C build (cmake). RUN apt-get update \ && apt-get install -y --no-install-recommends musl-tools git cmake make pkg-config \ && rm -rf /var/lib/apt/lists/* WORKDIR /src COPY Cargo.toml Cargo.lock rust-toolchain.toml ./ COPY crates ./crates COPY tools ./tools COPY images/seccomp ./images/seccomp COPY migrations ./migrations COPY .sqlx ./.sqlx # Install the musl target AFTER rust-toolchain.toml is in place, so rustup adds # it to the toolchain the workspace pins (channel 1.96.0), not the base image's # default. Doing this before the COPY installs into a toolchain cargo won't # actually use, and the build then fails with E0463 (no core for musl). RUN case "$TARGETARCH" in \ arm64) echo aarch64-unknown-linux-musl > /rust-target ;; \ *) echo x86_64-unknown-linux-musl > /rust-target ;; \ esac \ && rustup target add "$(cat /rust-target)" ENV SQLX_OFFLINE=true # Fetch git deps with the system git (libgit2 fails against Gitea smart-HTTP); # build the zlib-ng C dep with the musl cross compiler for the static target. ENV CARGO_NET_GIT_FETCH_WITH_CLI=true \ CC_x86_64_unknown_linux_musl=musl-gcc \ CC_aarch64_unknown_linux_musl=musl-gcc RUN cargo build --release --target "$(cat /rust-target)" -p clawmates-server \ && cp "target/$(cat /rust-target)/release/clawmates-server" /clawmates-server FROM gcr.io/distroless/static-debian12:nonroot COPY --from=builder /clawmates-server /usr/local/bin/clawmates-server USER nonroot ENTRYPOINT ["/usr/local/bin/clawmates-server"]