FROM archlinux:latest AS builder

RUN pacman -Syu --noconfirm && \
    pacman -S --noconfirm rust cargo && \
    pacman -Scc --noconfirm

WORKDIR /app

COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
RUN rm -rf src

COPY src ./src
RUN touch src/main.rs
RUN cargo build --release

FROM archlinux:latest

RUN pacman -Syu --noconfirm && \
    pacman -S --noconfirm openssl ca-certificates && \
    pacman -Scc --noconfirm

WORKDIR /app

COPY --from=builder /app/target/release/family_budget .

ENV RUST_LOG=info

EXPOSE 8080

CMD ["./family_budget"]
