## builder FROM rust:1.66.1-slim as builder WORKDIR /usr/src # weewoo deps for cross-compiling to musl RUN apt-get update RUN apt-get install musl-tools libssl-dev build-essential -y # create blank proj RUN USER=root cargo new wallhavenapirandom # copy deps COPY Cargo.toml Cargo.lock /usr/src/wallhavenapirandom/ WORKDIR /usr/src/wallhavenapirandom # install cross-compile target (alpine) RUN rustup target add x86_64-unknown-linux-musl # build deps so they're cached RUN cargo build --target x86_64-unknown-linux-musl --release # copy shit sauce COPY src /usr/src/wallhavenapirandom/src/ # touch the file inappropriately to prevent a cached build, because apparently this is an issue sometimes, haven't verified, too tired RUN touch /usr/src/wallhavenapirandom/src/main.rs # build RUN cargo build --target x86_64-unknown-linux-musl --release ## runtime FROM alpine:3.17.1 AS runtime COPY --from=builder /usr/src/wallhavenapirandom/target/x86_64-unknown-linux-musl/release/wallhavenapirandom /usr/local/bin EXPOSE 3000 CMD ["/usr/local/bin/wallhavenapirandom"]