FROM rust:1-bookworm AS build
RUN apt-get update && apt-get install -y --no-install-recommends build-essential perl pkg-config && rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY Cargo.toml Cargo.lock ./
COPY src ./src
COPY public ./public
COPY tests ./tests
COPY compatibility ./compatibility
RUN cargo build --locked --release

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
RUN groupadd --gid 10001 twofauth && useradd --uid 10001 --gid twofauth --no-create-home twofauth && mkdir /data && chown twofauth:twofauth /data
WORKDIR /app
COPY --from=build /src/target/release/twofauth-rs /usr/local/bin/twofauth-rs
COPY public ./public
COPY LICENSE NOTICE ./
USER 10001:10001
ENV DATABASE_URL=sqlite:///data/2fauth.sqlite LISTEN_ADDR=0.0.0.0:8080 RUST_PUBLIC_DIR=/app/public STORAGE_PATH=/data/storage PASSPORT_KEY_PATH=/data/storage
EXPOSE 8080
ENTRYPOINT ["twofauth-rs"]
CMD ["serve"]
