-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
99 lines (79 loc) · 3.72 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Adapted from Allison Thackston (https://github.com/athackst/dockerfiles/blob/main/ros2/humble.Dockerfile)
FROM ubuntu:jammy-20231211.1
# Disable terminal interactivity
ENV DEBIAN_FRONTEND=noninteractive
# Install language
RUN apt-get update && apt-get install -y \
locales \
&& locale-gen en_US.UTF-8 \
&& update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 \
&& rm -rf /var/lib/apt/lists/*
ENV LANG en_US.UTF-8
# Install timezone
RUN ln -fs /usr/share/zoneinfo/UTC /etc/localtime \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y tzdata \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& rm -rf /var/lib/apt/lists/*
# Update and upgrade packages
RUN apt-get update && apt-get -y upgrade \
&& rm -rf /var/lib/apt/lists/*
# Install common programs
RUN apt-get update && apt-get install -y --no-install-recommends \
curl gnupg2 lsb-release sudo software-properties-common wget \
&& rm -rf /var/lib/apt/lists/*
# Install ROS2 Humble Base
RUN sudo add-apt-repository universe \
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null \
&& apt-get update && apt-get install -y --no-install-recommends \
ros-humble-ros-base \
python3-argcomplete \
&& rm -rf /var/lib/apt/lists/*
# Install ROS2 development tools
RUN apt-get update && apt-get install -y --no-install-recommends \
bash-completion build-essential cmake gdb git openssh-client \
python3-argcomplete python3-pip ros-dev-tools vim \
&& rm -rf /var/lib/apt/lists/*
RUN rosdep init || echo "rosdep already initialized"
# Set environment variables
ENV ROS_DISTRO=humble
ENV AMENT_PREFIX_PATH=/opt/ros/humble
ENV COLCON_PREFIX_PATH=/opt/ros/humble
ENV LD_LIBRARY_PATH=/opt/ros/humble/lib
ENV PATH=/opt/ros/humble/bin:$PATH
ENV PYTHONPATH=/opt/ros/humble/lib/python3.10/site-packages
ENV ROS_PYTHON_VERSION=3
ENV ROS_VERSION=2
ARG USERNAME=ros2
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Create a non-root user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# Add sudo support for the non-root user
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& rm -rf /var/lib/apt/lists/*
# Set up autocompletion for user
RUN apt-get update && apt-get install -y git-core bash-completion \
&& echo "if [ -f /opt/ros/${ROS_DISTRO}/setup.bash ]; then source /opt/ros/${ROS_DISTRO}/setup.bash; fi" >> /home/$USERNAME/.bashrc \
&& echo "if [ -f /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash ]; then source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash; fi" >> /home/$USERNAME/.bashrc \
&& rm -rf /var/lib/apt/lists/*
# Install i2c libraries
RUN apt-get update && apt-get install i2c-tools libi2c-dev libi2c0 -y \
&& rm -rf /var/lib/apt/lists/*
# Install smbus package (required by PCA9685 servo driver)
RUN apt-get update && apt-get install python3-pip -y \
&& pip3 install smbus \
&& rm -rf /var/lib/apt/lists/*
# Add the user to i2c group
RUN usermod -aG i2c $USERNAME
# Copy over some files
# Use new user name
USER $USERNAME
# Create a bound mount for the repo in case something happens, we won't lose our progress.
# Plus we might tweak the dockerfile when we want to add support for cuda, fashie for now. But refer to althacks dockerfiles