Files
clawmates/images/broker.Dockerfile
T
Omar Sobh a1d1097b52
ci / gates (push) Successful in 5s
ci / frontend (push) Successful in 26s
ci / rust (push) Successful in 4m27s
ci / e2e (push) Skipped
ci / publish (push) Successful in 3m39s
ci + ops: cargo-build retry wrapper + runtime systemd unit
Two durability fixes closing recurring flakes:

CI flake wrapper (broker + server Dockerfiles):
  Wrapped the cargo build step in a 3-attempt retry loop with
  linear backoff (10s / 20s). Directly targets the crates.io
  transient network errors that keep hitting CI on the runners
  ('curl failed: SSL_ERROR_SYSCALL, errno 0'). Each build only
  loses time on transient failures; a real compile error still
  fails all 3 attempts and surfaces the last error normally.

Runtime systemd unit (deploy/clawmates-runtime/):
  Replaces the manual 'docker run' that had been starting the
  ZeroClaw runtime with no persistence for its network topology.
  Ephemeral prod fixes at 09:30 PDT 2026-07-21 (task #38) were:
    - anthropic.default provider block added to
      /root/clawmates-runtime/data/.zeroclaw/config.toml (already
      durable — bind-mounted from host)
    - docker network connect clawmates_edge clawmates-runtime
      (NOT durable — vanishes on container recreate)
  New systemd unit clawmates-runtime.service (installed +
  enabled on gw-04):
    - ExecStart docker-runs the container attached to
      clawmates_core, then connects clawmates_edge in the same
      shell command, then docker waits.
    - Bind-mounts both /root/clawmates-runtime/data and
      /var/lib/clawmates-missions (for security_scan +
      benchmark_runner).
    - --rm so upgrading is just docker pull + systemctl restart.
    - Restart=on-failure with 5s backoff.

Closes task #38 and preemptively closes the CI flake pattern.
2026-07-21 12:53:30 -07:00

45 lines
2.0 KiB
Docker

# The secret broker: its own minimal image, its own process boundary.
# Shares the builder pattern with the server image; ships ONLY the broker
# binary.
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 for attempt in 1 2 3; do \
cargo build --release --target "$(cat /rust-target)" -p clawmates-broker && break; \
rc=$?; \
echo "cargo build failed with exit $rc on attempt $attempt/3 — retrying in $((attempt*10))s"; \
sleep $((attempt*10)); \
done \
&& cp "target/$(cat /rust-target)/release/clawmates-broker" /clawmates-broker
FROM scratch
COPY --from=builder /clawmates-broker /clawmates-broker
USER 10001:10001
ENTRYPOINT ["/clawmates-broker"]