Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reduce image by 1GB+ by using multiple stages #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions sitl_debian.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"