optimised Dockerfile in a alpine image #18

Open
fredix wants to merge 1 commit from fredix/tricot:main into main
Showing only changes of commit ea6287ad39 - Show all commits

View file

@ -1,23 +1,28 @@
FROM rust:1.68-buster as builder FROM rust:alpine AS builder
RUN apk add --no-cache openssl-dev musl-dev
RUN apt-get update && \ RUN rustup target add x86_64-unknown-linux-musl
apt-get install -y libssl-dev pkg-config
WORKDIR /srv WORKDIR /srv
# Build dependencies and cache them # Build dependencies and cache them
COPY Cargo.* ./ COPY Cargo.* ./
RUN mkdir -p src && \
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
cargo build --release && \
rm -r src && \
rm target/release/deps/tricot*
# Build final app # Build final app
COPY ./src ./src COPY ./src ./src
RUN cargo build --release RUN RUSTFLAGS=-Ctarget-feature=-crt-static \
cargo build \
--release \
--target=x86_64-unknown-linux-musl
FROM debian:bullseye-slim RUN objcopy \
RUN apt-get update && apt-get install -y libssl1.1 iptables ca-certificates --compress-debug-sections \
COPY --from=builder /srv/target/release/tricot /usr/local/sbin/tricot target/x86_64-unknown-linux-musl/release/tricot \
CMD ["/usr/local/sbin/tricot"] target/x86_64-unknown-linux-musl/release/tricot.compressed
FROM alpine
RUN apk add -U --no-cache ca-certificates libgcc
Review

Is libgcc needed since this is a static musl build?

Is `libgcc` needed since this is a static musl build?
Review

exactly ! And I had to build a static binary because of openssl lib (rust failed to link to ssl lib, I don't know why, I'm not a rust developer :/ )
Anyway if you give me a link to your public docker image I could use it instead of mine ?

exactly ! And I had to build a static binary because of openssl lib (rust failed to link to ssl lib, I don't know why, I'm not a rust developer :/ ) Anyway if you give me a link to your public docker image I could use it instead of mine ?
COPY --from=builder \
/srv/target/x86_64-unknown-linux-musl/release/tricot.compressed \
/usr/local/bin/tricot
CMD ["/usr/local/bin/tricot"]