# syntax=docker/dockerfile:1.7
#
# Multi-arch build for `prop-grid-rs`. wgrib2 is installed from Debian
# Trixie (same version the Elixir image uses). The binary runs as a
# non-root uid that matches the fsGroup on the NFS scores mount.
FROM rust:1.94-trixie AS builder
WORKDIR /src

# Cache deps: copy manifests first so dependency changes alone don't
# invalidate the source-layer cache.
COPY Cargo.toml Cargo.lock* ./
RUN mkdir -p src src/bin \
 && echo 'fn main() {}' > src/bin/worker.rs \
 && echo '' > src/lib.rs \
 && cargo build --release --bin worker \
 && rm -rf src

COPY src ./src
RUN cargo build --release --bin worker

# Runtime image: slim debian plus wgrib2. libexpat/libjasper pulled in
# transitively by wgrib2 for PNG/JPEG2000 GRIB2 decompression.
FROM debian:trixie-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
      wgrib2 \
      ca-certificates \
      tini \
 && rm -rf /var/lib/apt/lists/*

COPY --from=builder /src/target/release/worker /usr/local/bin/prop-grid-rs

USER 65534:65534
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/prop-grid-rs"]
