From 78b804e5b3ceb7e15762091bd035e1c66a1a0aad Mon Sep 17 00:00:00 2001 From: Ben Butterworth <24711048+ben-xD@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:01:00 +0000 Subject: [PATCH] feat: reduce image by 1GB+ by using multiple stages Not working because I haven't copied the cpython (python symlinks to cpython, but the folder is architecture dependent) --- sitl_debian.Dockerfile | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sitl_debian.Dockerfile b/sitl_debian.Dockerfile index 5a560c7..440222d 100644 --- a/sitl_debian.Dockerfile +++ b/sitl_debian.Dockerfile @@ -1,4 +1,4 @@ -FROM debian:12 +FROM debian:12 as build COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ ARG ARDUPILOT_VERSION @@ -19,10 +19,21 @@ RUN ./install_ardupilot_sitl_apt_dependencies.sh RUN git clone --branch ${ARDUPILOT_VERSION} --depth 1 --recurse-submodules https://github.com/ArduPilot/ardupilot.git $HOME/ardupilot WORKDIR $HOME/ardupilot -# Build Ardupilot +# Build Ardupilot. Collapsing this to one line made the image go from 3.9GB to 3.89GB. RUN ./waf distclean RUN ./waf configure --board sitl RUN ./waf copter RUN ./waf rover RUN ./waf plane RUN ./waf sub + +# This second stage allows us to reduce the image from 3.9GB to 2.5GB +FROM debian:12 as run +ENV HOME=/root +WORKDIR $HOME/ardupilot +COPY --from=build $HOME/ardupilot $HOME/ardupilot +ENV VENV=$HOME/venv-ardupilot +COPY --from=build $VENV $VENV +ENV PATH="$VENV/bin:$PATH" +# Add ~/.local/bin to PATH to allow mavproxy.py to be found after it's installed +ENV PATH="$PATH:$HOME/.local/bin"