35 lines
953 B
Docker
35 lines
953 B
Docker
FROM alpine:latest AS builder
|
|
|
|
WORKDIR /build
|
|
|
|
RUN apk add rustup build-base
|
|
# todo: arm64 target
|
|
RUN rustup-init --default-host x86_64-unknown-linux-musl --default-toolchain stable --profile default -y
|
|
|
|
ENV PATH=/root/.cargo/bin:$PATH
|
|
ENV RUSTFLAGS='-C link-arg=-s'
|
|
|
|
RUN cargo install cargo-chef --locked
|
|
|
|
# build dependencies first to cache
|
|
FROM builder AS recipe-builder
|
|
COPY . .
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
FROM builder AS binary-builder
|
|
COPY --from=recipe-builder /build/recipe.json recipe.json
|
|
RUN cargo chef cook --release --recipe-path recipe.json --target x86_64-unknown-linux-musl
|
|
|
|
COPY Cargo.toml /build/
|
|
COPY Cargo.lock /build/
|
|
|
|
# this needs to match workspaces in Cargo.toml
|
|
COPY lib/libpk /build/lib/libpk
|
|
COPY services/api/ /build/services/api
|
|
|
|
RUN cargo build --bin api --release --target x86_64-unknown-linux-musl
|
|
|
|
FROM scratch
|
|
|
|
COPY --from=binary-builder /build/target/x86_64-unknown-linux-musl/release/api /api
|