FROM rust:bookworm AS builder
WORKDIR /app
COPY Cargo.lock licensing_profiles.json ./
RUN printf '[workspace]\nmembers = ["shared", "server"]\nresolver = "2"\n[workspace.package]\nedition = "2021"\nauthors = ["Stevan Freeborn"]\n[workspace.dependencies]\nserde = { version = "1", features = ["derive"] }\nserde_json = "1"\ned25519-dalek = "3.0.0"\nbase64 = "0.22.1"\nsha2 = "0.11.0"\nthiserror = "2"\nurl = "2.5.8"\nlog = "0.4"\n[profile.release]\nlto = true\ncodegen-units = 1\nstrip = "symbols"\nopt-level = "s"\npanic = "abort"\n' > Cargo.toml
COPY shared/ shared/
COPY server/ server/
RUN cargo build --release -p clean-copy-server

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/clean-copy-server /usr/local/bin/server
COPY server/static/ /app/server/static/
VOLUME /data
ENV DATABASE_URL=sqlite:/data/cleancopy.db?mode=rwc
ENV RELEASE_DIR=/data/releases
ENV STATIC_DIR=/app/server/static
ENV PORT=3000
EXPOSE 3000
CMD ["server"]
