# Build context is the `central/` dir (see docker-compose) so we can copy both
# server/ and db/ — the server embeds db/init.sql via include_str!("../../db/init.sql").
FROM rust:1-bookworm AS build
WORKDIR /build
COPY server/Cargo.toml server/Cargo.toml
COPY server/src server/src
COPY db db
WORKDIR /build/server
RUN cargo build --release

FROM debian:bookworm-slim
# nfs-common provides mount.nfs for `nfs`-kind projects (mounted on demand at sync/download time).
# libimage-exiftool-perl provides exiftool for the GPS-track extraction sweep (map/chainage).
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates nfs-common \
       libimage-exiftool-perl \
    && rm -rf /var/lib/apt/lists/*
COPY --from=build /build/server/target/release/central-server /usr/local/bin/central-server
ENV BIND_ADDR=0.0.0.0:8080
EXPOSE 8080
CMD ["central-server"]
