# build stage
FROM rust:1.93 AS builder

WORKDIR /project

RUN mkdir -p /usr/local/cargo && \
    cat > /usr/local/cargo/config.toml << 'EOF'
[source.crates-io]
replace-with = "rsproxy"

[source.rsproxy]
registry = "sparse+https://rsproxy.cn/index/"

[registries.rsproxy]
index = "sparse+https://rsproxy.cn/index/"
EOF

COPY . .
RUN cargo build -p {{ app_crate }} --release

# runtime stage
FROM debian:trixie-slim

WORKDIR /usr/local/bin

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*
COPY --from=builder /project/target/release/{{ app_crate }} .

EXPOSE 8000

ENTRYPOINT ["{{ app_crate }}"]
CMD ["--config", "/data/config.toml", "serve"]
