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

added dependency caching for faster builds using buildkit #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 21 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,40 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV HEADLESS=false
ARG DEVELOPMENT=false

# Enable BuildKit caching for apt packages
RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache

# Install linux packages
RUN apt-get update && apt-get install -y \
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
apt-get update && apt-get install -y --no-install-recommends \
ros-$(rosversion -d)-turtlesim \
locales \
xvfb \
python3.9 \
python3-pip
python3-pip \
libgl1-mesa-glx && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install Python packages with pip caching
RUN --mount=type=cache,target=/root/.cache/pip \
python3 -m pip install -U python-dotenv catkin_tools

# RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN python3 -m pip install -U python-dotenv catkin_tools
# Set up ROS environment
RUN rosdep update && \
echo "source /opt/ros/noetic/setup.bash" >> /root/.bashrc && \
echo "alias start='catkin build && source devel/setup.bash && roslaunch turtle_agent agent.launch'" >> /root/.bashrc && \
echo "export ROSLAUNCH_SSH_UNKNOWN=1" >> /root/.bashrc

# Copy application code
COPY . /app/
WORKDIR /app/

# Modify the RUN command to use ARG
RUN /bin/bash -c 'if [ "$DEVELOPMENT" = "true" ]; then \
# Install application dependencies with pip caching
RUN --mount=type=cache,target=/root/.cache/pip \
/bin/bash -c 'if [ "$DEVELOPMENT" = "true" ]; then \
python3.9 -m pip install --user -e .; \
else \
python3.9 -m pip install -U jpl-rosa>=1.0.7; \
Expand All @@ -41,3 +55,4 @@ CMD ["/bin/bash", "-c", "source /opt/ros/noetic/setup.bash && \
sleep 5 && \
echo \"Run \\`start\\` to build and launch the ROSA-TurtleSim demo.\" && \
/bin/bash"]

6 changes: 4 additions & 2 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ fi
HEADLESS=${HEADLESS:-false}
DEVELOPMENT=${DEVELOPMENT:-false}

export DOCKER_BUILDKIT=1

# Enable X11 forwarding based on OS
case "$(uname)" in
Linux*|Darwin*)
Expand All @@ -33,7 +35,7 @@ case "$(uname)" in
if grep -q "WSL" /proc/version; then
export DISPLAY=:0
else
export DISPLAY=host.docker.internal:0
export DISPLAY=:1
fi
xhost +
;;
Expand All @@ -56,7 +58,7 @@ fi
# Build and run the Docker container
CONTAINER_NAME="rosa-turtlesim-demo"
echo "Building the $CONTAINER_NAME Docker image..."
docker build --build-arg DEVELOPMENT=$DEVELOPMENT -t $CONTAINER_NAME -f Dockerfile . || { echo "Error: Docker build failed"; exit 1; }
docker build --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg DEVELOPMENT=$DEVELOPMENT -t $CONTAINER_NAME -f Dockerfile . || { echo "Error: Docker build failed"; exit 1; }

echo "Running the Docker container..."
docker run -it --rm --name $CONTAINER_NAME \
Expand Down