2021-03-22 16:36:01 +01:00
|
|
|
FROM alpine:latest AS builder
|
2021-03-13 11:53:33 +01:00
|
|
|
|
2021-03-22 16:36:01 +01:00
|
|
|
ENV PATH "$PATH:/root/.cargo/bin"
|
2021-03-05 20:40:49 +01:00
|
|
|
|
2021-03-22 16:36:01 +01:00
|
|
|
# Switch to the nightly build
|
2021-03-05 20:40:49 +01:00
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
2021-03-22 16:36:01 +01:00
|
|
|
# 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
|
2021-03-13 11:53:33 +01:00
|
|
|
|
|
|
|
# Build the dependencies
|
|
|
|
# This is done separately to reduce average compile time
|
|
|
|
# Afterwards, we remove the dummy src directory
|
|
|
|
# Now, we build our own source code
|
2021-03-22 16:36:01 +01:00
|
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
COPY src/ ./src/
|
|
|
|
RUN cargo build --release --target x86_64-unknown-linux-musl
|
2021-03-05 20:40:49 +01:00
|
|
|
|
|
|
|
|
2021-03-13 11:53:33 +01:00
|
|
|
# Now, we create the actual image
|
2021-03-22 16:36:01 +01:00
|
|
|
FROM scratch
|
2021-03-05 20:40:49 +01:00
|
|
|
|
2021-03-13 10:41:44 +01:00
|
|
|
# Install dependencies
|
2021-03-22 16:36:01 +01:00
|
|
|
COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/rust-api /rust-api
|
2021-03-05 20:40:49 +01:00
|
|
|
|
2021-03-22 16:36:01 +01:00
|
|
|
CMD ["/rust-api"]
|