Switched to alpine-based Docker build

master
Jef Roosens 2021-03-13 11:53:33 +01:00
parent 9db9b5be78
commit 825fec349b
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
1 changed files with 23 additions and 7 deletions

View File

@ -1,17 +1,33 @@
# syntax=docker/dockerfile:1.2
FROM rustlang/rust:nightly AS builder
FROM rust:alpine AS builder
# Switch to the nightly build
RUN rustup default nightly
WORKDIR /usr/src/app
# Build the app
COPY . .
RUN --mount=type=cache,target=/usr/src/app/target cargo install --path .
# 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 .
FROM debian:buster-slim
# Now, we create the actual image
FROM alpine:latest
# Install dependencies
RUN apt update && apt install -y openssl
RUN apk update && apk add --no-cache openssl
COPY --from=builder /usr/local/cargo/bin/rust-api /usr/local/bin/rust-api