From 8104c88ae17e06b4d096716530388fd414a61883 Mon Sep 17 00:00:00 2001 From: "Antoine R. Dumont (@ardumont)" <ardumont@softwareheritage.org> Date: Thu, 29 Aug 2024 16:08:54 +0200 Subject: [PATCH] graph: Decrease image size Build the swh-graph-grpc-serve binary and only copy the result into the destination image. This splits the final image size to ~500Mo instead of ~1Go. Refs. swh/infra/sysadm-environment#5382 --- apps/swh-graph/Dockerfile | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/apps/swh-graph/Dockerfile b/apps/swh-graph/Dockerfile index 5d974bdf..9477b254 100644 --- a/apps/swh-graph/Dockerfile +++ b/apps/swh-graph/Dockerfile @@ -1,14 +1,27 @@ -# Deeply inspired from the Dockerfile of the swh-graphql project -FROM rust:1.80-bookworm +FROM rust:1.80-bookworm AS rust_build +# ... build swh-graph rust deps +RUN apt-get -y update && \ + apt-get -y upgrade && \ + apt-get install -y build-essential libclang-dev \ + zstd protobuf-compiler default-jre && \ + apt clean + +# Install swh-graph feature swh-graph-grpc-serve +# TODO: Ensure the target-cpu is ok +RUN RUSTFLAGS="-C target-cpu=native" \ + cargo install \ + --features grpc-server \ + swh-graph + +FROM python:3.10-bookworm + ARG UID=1000 ARG GID=1000 RUN apt-get -y update && \ apt-get -y upgrade && \ - apt-get install -y python3 python3-pip \ - libcmph-dev librdkafka-dev \ - build-essential libclang-dev \ - zstd protobuf-compiler default-jre && \ + apt-get install -y python3-pip \ + libcmph-dev librdkafka-dev && \ apt clean && \ addgroup --gid $UID swh && \ useradd --gid $GID --uid $UID -m -d /opt/swh swh && \ @@ -25,13 +38,7 @@ ENV PATH=/opt/swh/.local/bin:$PATH RUN /usr/bin/python3 -m pip install --upgrade pip --break-system-packages && \ pip install --no-cache-dir -r requirements-frozen.txt --break-system-packages -# Install - -RUN RUSTFLAGS="-C target-cpu=native" \ - cargo install \ - --features grpc-server \ - swh-graph - +COPY --from=rust_build /usr/local/cargo/bin/swh-graph-* /usr/local/bin/ ENV SWH_CONFIG_FILENAME=/etc/swh/config.yml ENV PORT 5009 EXPOSE $PORT -- GitLab