Failed attempt at fixing docker build

master
Jef Roosens 2021-03-22 16:36:01 +01:00
parent 59dfc33e8f
commit 35fc9be5da
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
1 changed files with 13 additions and 19 deletions

View File

@ -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"]