FROM ci.nxtgauge.com/admin/rust:alpine AS builder

WORKDIR /usr/src/app

RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static && \
    rustup target add x86_64-unknown-linux-musl

COPY Cargo.toml Cargo.lock ./
COPY crates ./crates
COPY apps ./apps

ENV RUSTFLAGS='-C target-feature=+crt-static'
ENV OPENSSL_STATIC=1
ENV OPENSSL_DIR=/usr
RUN cargo build --release --bin graphic_designers --target x86_64-unknown-linux-musl

FROM ci.nxtgauge.com/admin/alpine:latest AS runtime

RUN apk add --no-cache ca-certificates

RUN adduser -D -u 1000 appuser
WORKDIR /app

COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/graphic_designers ./graphic_designers

USER appuser

CMD ["./graphic_designers"]
