-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
104 lines (91 loc) · 3.22 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
100
101
102
103
104
# syntax=docker/dockerfile:1.2
ARG ROS_DISTRO="rolling"
FROM ros:${ROS_DISTRO}-ros-base AS upstream
# Restate for later use
ARG ROS_DISTRO
ARG REPO
# prevent interactive messages in apt install
ARG DEBIAN_FRONTEND=noninteractive
# install build dependencies
RUN --mount=type=cache,target=/var/cache/apt,id=apt \
apt-get update && apt-get upgrade -y \
&& apt-get install -q -y --no-install-recommends \
build-essential \
ccache \
cmake \
lcov \
lld \
python3-colcon-common-extensions \
python3-colcon-lcov-result \
python3-colcon-coveragepy-result \
python3-colcon-mixin \
&& rm -rf /var/lib/apt/lists/*
# build source dependencies
WORKDIR /opt/upstream
COPY upstream.repos .
RUN --mount=type=cache,target=/var/cache/apt,id=apt \
mkdir src \
&& vcs import src < upstream.repos \
&& . /opt/ros/${ROS_DISTRO}/setup.sh \
&& rosdep update && apt-get update \
&& rosdep install -q -y \
--from-paths src \
--ignore-src \
--rosdistro ${ROS_DISTRO} \
&& rm -rf /var/lib/apt/lists/* \
&& colcon build --mixin release lld \
&& rm -rf build log src upstream.repos
# copy source to install repo dependencies
WORKDIR /opt/ws
COPY . ./src/${REPO}
# install repo dependencies
RUN --mount=type=cache,target=/var/cache/apt,id=apt \
. /opt/upstream/install/setup.sh \
&& rosdep update && apt-get update \
&& rosdep install -q -y \
--from-paths src \
--ignore-src \
--rosdistro ${ROS_DISTRO} \
&& rm -rf /var/lib/apt/lists/*
FROM upstream AS development
ARG UID
ARG GID
ARG USER
# fail build if args are missing
# hadolint ignore=SC2028
RUN if [ -z "$UID" ]; then echo '\nERROR: UID not set. Run \n\n \texport UID=$(id -u) \n\n on host before building Dockerfile.\n'; exit 1; fi
# hadolint ignore=SC2028
RUN if [ -z "$GID" ]; then echo '\nERROR: GID not set. Run \n\n \texport GID=$(id -g) \n\n on host before building Dockerfile.\n'; exit 1; fi
# hadolint ignore=SC2028
RUN if [ -z "$USER" ]; then echo '\nERROR: USER not set. Run \n\n \texport USER=$(whoami) \n\n on host before building Dockerfile.\n'; exit 1; fi
RUN --mount=type=cache,target=/var/cache/apt,id=apt \
apt-get update && apt-get upgrade -y \
&& apt-get install -q -y --no-install-recommends \
clang-14 \
clang-format-14 \
clang-tidy-14 \
git \
openssh-client \
python3-pip \
vim \
wget \
&& rm -rf /var/lib/apt/lists/*
# install developer tools
RUN python3 -m pip install --no-cache-dir \
pre-commit==3.0.4
# Setup user home directory
# --no-log-init helps with excessively long UIDs
RUN groupadd --gid $GID $USER \
&& useradd --no-log-init --uid $GID --gid $UID -m $USER --groups sudo \
&& echo $USER ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER \
&& chmod 0440 /etc/sudoers.d/$USER \
&& echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/${USER}/.profile \
&& touch /home/${USER}/.bashrc \
&& chown -R ${GID}:${UID} /home/${USER}
USER $USER
ENV SHELL /bin/bash
ENTRYPOINT []
# Setup mixin
WORKDIR /home/${USER}/ws
RUN colcon mixin add default https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml \
&& colcon mixin update default