FROM rust:latest AS builder
WORKDIR /app

RUN apt update && apt install -y musl-tools \ 
    pkg-config \ 
    libssl-dev \ 
    openssl
RUN rustup target add x86_64-unknown-linux-gnu

COPY . .

# PKG_CONFIG_PATH VAR TESTING 
ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/openssl.pc
ARG PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/openssl.pc

RUN cargo build --release --target=x86_64-unknown-linux-gnu

FROM alpine:latest
WORKDIR /app

COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/ml-api /app/ml-api
RUN ls /app
RUN apk add --no-cache ca-certificates

EXPOSE 5134

ENTRYPOINT ["/app/ml-api"]