From ce74b238541c74700bc23ffdd6659e089f887c8a Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 18 Jan 2023 19:59:05 +0200 Subject: [PATCH] feat: dockerius filius --- Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6ab7063 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +## 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"] -- 2.44.1