1
- # Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble
2
- FROM arm64v8/ros:humble AS arm64
3
1
# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble
4
2
FROM osrf/ros:humble-desktop-full AS amd64
3
+ # Base Image : https://hub.docker.com/r/arm64v8/ros/tags?page=1&name=humble
4
+ FROM arm64v8/ros:humble AS arm64
5
5
6
6
# Use docker automatic platform args to select the base image.
7
7
# It may be `arm64` or `amd64` depending on the platform.
8
- # Reference:
9
- # - https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope
8
+ # Ref: https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope
10
9
FROM $TARGETARCH
11
10
12
11
LABEL org.opencontainers.image.authors="yuzhong1214@gmail.com"
13
12
14
- ARG TARGETARCH
13
+ # Arguments for the default user
15
14
ARG USERNAME=user
16
15
ARG USER_UID=1000
17
- ARG USER_GID=$USER_UID
18
16
19
- # Create the user
20
- RUN groupadd --gid $USER_GID $USERNAME \
21
- && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
22
- #
23
- # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
24
- && apt-get update \
25
- && apt-get install -y sudo \
26
- && echo $USERNAME ALL=\( root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
27
- && chmod 0440 /etc/sudoers.d/$USERNAME \
28
- && rm -rf /var/lib/apt/lists/*
29
- RUN apt-get update && apt-get upgrade -y \
30
- && rm -rf /var/lib/apt/lists/*
31
- RUN apt-get update && apt-get install -y python3-pip \
17
+ # Keep downloaded packages for caching purposes
18
+ # Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages
19
+ 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
20
+
21
+ # Upgrade packages
22
+ # Ref: https://pythonspeed.com/articles/security-updates-in-docker/
23
+ # Ref: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#example-cache-apt-packages
24
+ # Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1264502398
25
+ # Ref: https://github.com/moby/buildkit/issues/1673#issuecomment-1987107404
26
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
27
+ apt-get update && apt-get upgrade -y \
32
28
&& rm -rf /var/lib/apt/lists/*
33
- ENV SHELL /bin/bash
34
29
35
- # ********************************************************
36
- # * Anything else you want to do like clean up goes here *
37
- # ********************************************************
30
+ # Install sudo and create a user with sudo privileges
31
+ # Ref: https://stackoverflow.com/a/65434659
32
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
33
+ apt-get update && apt-get install -y sudo \
34
+ && useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \
35
+ && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
36
+ && rm -rf /var/lib/apt/lists/*
38
37
39
38
# Install common tools
40
- RUN apt-get update && apt-get install -y \
39
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
40
+ apt-get update && apt-get install -y \
41
41
curl \
42
42
git \
43
- git-extras \
44
43
htop \
44
+ iputils-ping \
45
+ nano \
45
46
net-tools \
46
47
tmux \
48
+ tree \
49
+ unzip \
47
50
vim \
48
51
wget \
52
+ zip \
53
+ && rm -rf /var/lib/apt/lists/*
54
+
55
+ # Install Python pip
56
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
57
+ apt-get update && apt-get install -y \
58
+ python3-pip \
59
+ && rm -rf /var/lib/apt/lists/*
60
+
61
+ # Install custom tools
62
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
63
+ apt-get update && apt-get install -y \
64
+ git-extras \
49
65
&& rm -rf /var/lib/apt/lists/*
50
66
51
- RUN if [ "$TARGETARCH" = "amd64" ]; then \
67
+ # Install ROS2 Gazebo packages for amd64
68
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
69
+ if [ "$TARGETARCH" = "amd64" ]; then \
52
70
apt-get update && apt-get install -y \
53
71
ros-$ROS_DISTRO-gazebo-ros-pkgs \
54
72
ros-$ROS_DISTRO-gazebo-ros2-control \
55
73
&& rm -rf /var/lib/apt/lists/*; \
56
74
fi
57
75
58
- # Install ROS2 packages
59
- RUN apt-get update && apt-get install -y \
76
+ # Install ROS2 RVIZ and other custom ROS2 packages
77
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
78
+ apt-get update && apt-get install -y \
60
79
ros-$ROS_DISTRO-rviz2 \
61
- #
80
+ && rm -rf /var/lib/apt/lists/*
81
+
82
+ # TODO: Add more commands here
83
+ # For example, to install additional packages, uncomment the following lines and add the package names
84
+ # RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
85
+ # apt-get update && apt-get install -y \
86
+ # $OTHER_PACKAGES \
87
+ # && rm -rf /var/lib/apt/lists/*
88
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
89
+ apt-get update && apt-get install -y \
62
90
# The packages below are used by the Husky repository.
63
91
ros-$ROS_DISTRO-controller-manager \
64
92
ros-$ROS_DISTRO-diff-drive-controller \
@@ -83,28 +111,34 @@ RUN apt-get update && apt-get install -y \
83
111
ros-$ROS_DISTRO-slam-toolbox \
84
112
ros-$ROS_DISTRO-imu-tools \
85
113
ros-$ROS_DISTRO-teleop-twist-keyboard \
86
- && sudo rm -rf /var/lib/apt/lists/*
87
-
88
- COPY .bashrc /home/$USERNAME/.bashrc
114
+ && rm -rf /var/lib/apt/lists/*
89
115
90
- # [Optional] Set the default user. Omit if you want to keep the default as root.
91
116
USER $USERNAME
92
- CMD ["/bin/bash" ]
117
+ # Create Gazebo cache directory with correct ownership to avoid permission issues after volume mount
118
+ RUN mkdir /home/$USERNAME/.gazebo
119
+ # TODO: Run additional commands as non-root user here
120
+ COPY .bashrc /home/$USERNAME/.bashrc
121
+ # TODO: Copy additional files here
93
122
94
123
# Setup husky controller by the script.
95
124
# Build certain packages from source for arm64.
96
125
COPY script /home/$USERNAME/script
97
- RUN sudo apt-get update \
126
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
127
+ sudo apt-get update \
98
128
&& bash -ie /home/$USERNAME/script/install-clearpath-robot.sh \
99
129
&& sudo rm -rf /var/lib/apt/lists/*
100
130
# Note: The script need to be run as user, not root.
101
131
# Reference: https://github.com/clearpathrobotics/clearpath_computer_installer/tree/main
102
132
COPY clearpath_computer_installer /home/$USERNAME/clearpath_computer_installer
103
- RUN sudo apt-get update \
133
+ RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
134
+ sudo apt-get update \
104
135
&& bash -ie /home/$USERNAME/clearpath_computer_installer/clearpath_computer_installer.sh \
105
136
&& sudo rm -rf /var/lib/apt/lists/*
106
137
# Setup udev rules.
107
138
COPY udev_rules /home/$USERNAME/udev_rules
108
139
RUN /home/$USERNAME/udev_rules/install_udev_rules.sh
109
140
# Generate robot configuration files.
110
141
RUN bash -ie /home/$USERNAME/script/husky-generate.sh
142
+
143
+ ENTRYPOINT []
144
+ CMD ["/bin/bash" ]
0 commit comments