From 35fc9be5dafa4cc8bf9ec9a988754bed3625283e Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 22 Mar 2021 16:36:01 +0100 Subject: [PATCH] Failed attempt at fixing docker build --- Dockerfile | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index a5148fe..9de43f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,28 @@ -FROM rust:alpine AS builder +FROM alpine:latest AS builder + +ENV PATH "$PATH:/root/.cargo/bin" # Switch to the nightly build -RUN rustup default nightly - WORKDIR /usr/src/app -# Install build dependencies & create a new dummy project -# that we use as a build cache -RUN apk update && \ - apk add --no-cache openssl openssl-dev musl-dev && \ - cargo init --bin +# Install build dependencies, install rustup & create dummy project +RUN apk update && apk add --no-cache openssl-dev build-base curl && \ + { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; } && \ + rustup target add x86_64-unknown-linux-musl # Build the dependencies # This is done separately to reduce average compile time # Afterwards, we remove the dummy src directory -COPY Cargo.toml Cargo.lock ./ -RUN cargo build --release && \ - rm src/*.rs - # Now, we build our own source code -COPY src/ ./src -RUN cargo install --path . +COPY Cargo.toml Cargo.lock ./ +COPY src/ ./src/ +RUN cargo build --release --target x86_64-unknown-linux-musl # Now, we create the actual image -FROM alpine:latest +FROM scratch # Install dependencies -RUN apk update && apk add --no-cache openssl +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/rust-api /rust-api -COPY --from=builder /usr/local/cargo/bin/rust-api /usr/local/bin/rust-api - -CMD ["rust-api"] +CMD ["/rust-api"]