Skip to content

Commit

Permalink
refactor(Dockerfile): better practices and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ElioDiNino committed May 5, 2024
1 parent 591db8a commit fcd5a8b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 35 deletions.
50 changes: 31 additions & 19 deletions arm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### SITL DOWNLOAD IMAGE ###
# Run the downloader in a pre-image so SSH keys are dropped from the image
FROM ubuntu:focal AS SITLDOWNLOADER
FROM ubuntu:22.04 AS SITLDOWNLOADER

# Need Git to checkout our sources
RUN apt-get update && apt-get install -y git
Expand Down Expand Up @@ -49,35 +49,47 @@ RUN git clone $ARDUPILOT_REPO ardupilot
WORKDIR /ardupilot

# Checkout the latest Copter/Plane release
RUN git checkout $ARDUPILOT_REF

# Pull submodule dependencies
RUN git submodule update --init --recursive
RUN git checkout $ARDUPILOT_REF \
# Pull submodule dependencies
&& git submodule update --init --recursive


### SITL BUILD IMAGE ###
FROM ubuntu:focal AS SITLBUILD
FROM ubuntu:22.04 AS SITLBUILD

# Trick to get apt-get to not prompt for timezone in tzdata
ENV DEBIAN_FRONTEND=noninteractive

# Create a non-root user for the build
ARG USER_NAME=vehicle
ARG USER_UID=1000
ARG USER_GID=1000
RUN groupadd ${USER_NAME} --gid ${USER_GID}\
&& useradd -l -m ${USER_NAME} -u ${USER_UID} -g ${USER_GID} -s /bin/bash

# Need sudo and lsb-release for the installation prerequisites
RUN apt-get update && apt-get install -y sudo lsb-release tzdata bc screen
RUN apt-get update && apt-get install --no-install-recommends -y sudo lsb-release tzdata bc screen
RUN cp /etc/apt/sources.list /etc/apt/sources.list~ && \
sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list && \
apt-get update
RUN apt-get build-dep -y python-pygame
RUN apt-get build-dep -y python3-pygame

# Pull in ardupilot and build the vehicle
COPY --from=SITLDOWNLOADER /ardupilot /vehicle
WORKDIR /vehicle

# Need USER set so usermod does not fail...
# Create non root user for pip
ENV USER=${USER_NAME}

RUN echo "vehicle ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USER_NAME} \
&& chmod 0440 /etc/sudoers.d/${USER_NAME} \
&& chown -R ${USER_NAME}:${USER_NAME} /vehicle

USER ${USER_NAME}

ENV SKIP_AP_EXT_ENV=1 SKIP_AP_GRAPHIC_ENV=1 SKIP_AP_COV_ENV=1 SKIP_AP_GIT_CHECK=1
# Install all prerequisites now
COPY install-prereqs-arm.sh /
# Give execute permissions
RUN chmod +x /install-prereqs-arm.sh
RUN USER=nobody /install-prereqs-arm.sh -y
RUN Tools/environment_install/install-prereqs-ubuntu.sh -y

# Take in a parameter for the vehicle type
ARG VEHICLE_TYPE
Expand All @@ -88,23 +100,23 @@ ENV WAF_VEHICLE=${VEHICLE_TYPE:+plane}
ENV WAF_VEHICLE=${WAF_VEHICLE:-copter}

# Continue build instructions from https://github.com/ArduPilot/ardupilot/blob/master/BUILD.md
RUN ./waf distclean
RUN ./waf configure --board sitl
RUN ./waf $WAF_VEHICLE
RUN ./waf distclean \
&& ./waf configure --board sitl \
&& ./waf $WAF_VEHICLE


### SITL RUN IMAGE ###
FROM ubuntu:focal AS SITLRUN
FROM ubuntu:22.04 AS SITLRUN

# Runtime dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python3 python3-pip python-is-python3 python-numpy bc screen
RUN apt-get update && apt-get install -y python3 python3-pip python-is-python3 python3-numpy bc screen
# Provide sources list for build dependencies
RUN cp /etc/apt/sources.list /etc/apt/sources.list~ && \
sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list && \
apt-get update
RUN apt-get build-dep python3-lxml -y
RUN pip install --user -U future lxml pymavlink MAVProxy pexpect
RUN pip install --no-cache-dir --user -U future lxml pymavlink MAVProxy pexpect

# Take in a parameter for the vehicle type
ARG VEHICLE_TYPE
Expand Down
32 changes: 16 additions & 16 deletions x86/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### SITL DOWNLOAD IMAGE ###
# Run the downloader in a pre-image so SSH keys are dropped from the image
FROM ubuntu:focal AS SITLDOWNLOADER
FROM ubuntu:22.04 AS SITLDOWNLOADER

# Need Git to checkout our sources
RUN apt-get update && apt-get install -y git
Expand Down Expand Up @@ -49,14 +49,13 @@ RUN git clone $ARDUPILOT_REPO ardupilot
WORKDIR /ardupilot

# Checkout the latest Copter/Plane release
RUN git checkout $ARDUPILOT_REF

# Pull submodule dependencies
RUN git submodule update --init --recursive
RUN git checkout $ARDUPILOT_REF \
# Pull submodule dependencies
&& git submodule update --init --recursive


### SITL BUILD IMAGE ###
FROM ubuntu:focal AS SITLBUILD
FROM ubuntu:22.04 AS SITLBUILD

# Trick to get apt-get to not prompt for timezone in tzdata
ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -82,10 +81,9 @@ WORKDIR /vehicle
# Create non root user for pip
ENV USER=${USER_NAME}

RUN echo "vehicle ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USER_NAME}
RUN chmod 0440 /etc/sudoers.d/${USER_NAME}

RUN chown -R ${USER_NAME}:${USER_NAME} /${USER_NAME}
RUN echo "vehicle ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USER_NAME} \
&& chmod 0440 /etc/sudoers.d/${USER_NAME} \
&& chown -R ${USER_NAME}:${USER_NAME} /vehicle

USER ${USER_NAME}

Expand All @@ -102,17 +100,19 @@ ENV WAF_VEHICLE=${VEHICLE_TYPE:+plane}
ENV WAF_VEHICLE=${WAF_VEHICLE:-copter}

# Continue build instructions from https://github.com/ArduPilot/ardupilot/blob/master/BUILD.md
RUN ./waf distclean
RUN ./waf configure --board sitl
RUN ./waf $WAF_VEHICLE
RUN ./waf distclean \
&& ./waf configure --board sitl \
&& ./waf $WAF_VEHICLE


### SITL RUN IMAGE ###
FROM ubuntu:focal AS SITLRUN
FROM ubuntu:22.04 AS SITLRUN

# Runtime dependencies
RUN apt-get update && apt-get install -y python3 python3-pip python-is-python3 python-numpy bc screen
RUN pip install --user -U future lxml pymavlink MAVProxy pexpect
RUN apt-get update && apt-get install --no-install-recommends -y python3 python3-pip python-is-python3 python3-numpy bc screen \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& pip install --no-cache-dir --user -U future lxml pymavlink MAVProxy pexpect

# Take in a parameter for the vehicle type
ARG VEHICLE_TYPE
Expand Down

0 comments on commit fcd5a8b

Please sign in to comment.