FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef

# Create and change to the app directory.
WORKDIR /app

FROM chef AS planner
COPY . ./
RUN cargo +nightly chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

# Build dependencies - this is the caching docker layer
RUN cargo +nightly chef cook --release --recipe-path recipe.json

# Build application
COPY . ./
RUN cargo +nightly build --release

FROM debian:trixie-slim AS runtime

COPY --from=builder /app/target/release/lithium /usr/bin/lithium

ENV HTTP_PORT=3000
ENV HTTPS_PORT=3443

EXPOSE 3000
EXPOSE 3443

CMD ["/usr/bin/lithium"]
