35 lines
801 B
Docker
35 lines
801 B
Docker
FROM rust:alpine AS builder
|
|
|
|
# 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
|
|
|
|
# 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 .
|
|
|
|
|
|
# Now, we create the actual image
|
|
FROM alpine:latest
|
|
|
|
# Install dependencies
|
|
RUN apk update && apk add --no-cache openssl
|
|
|
|
COPY --from=builder /usr/local/cargo/bin/rust-api /usr/local/bin/rust-api
|
|
|
|
CMD ["rust-api"]
|