FROM docker.io/library/rust:1.96-slim-trixie AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
      ca-certificates build-essential cmake perl pkg-config clang mold \
    && rm -rf /var/lib/apt/lists/*
ENV RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=mold"
WORKDIR /src
COPY Cargo.toml Cargo.lock rust-toolchain.toml ./
COPY bobbin/crates ./bobbin/crates
COPY shuttle ./shuttle
COPY lexicons ./lexicons
COPY knot2/lexicons ./knot2/lexicons
COPY knot2/crates ./knot2/crates
COPY knot2/third_party ./knot2/third_party
RUN cargo build --release --package knot-server
RUN strip target/release/knot-server

FROM gcr.io/distroless/cc-debian13:latest@sha256:1e3c6d9c255be500eb680cdea0ad07554f52ae92dfcbdf07043a2a435b4c1fe3
COPY --from=builder /src/target/release/knot-server /usr/local/bin/knot-server
EXPOSE 5555 2222
ENTRYPOINT ["/usr/local/bin/knot-server"]
CMD ["/etc/knot/config.toml"]
