-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
281 lines (232 loc) · 8.29 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# parameters
ARG ARCH
ARG DISTRO
ARG DOCKER_REGISTRY
ARG BASE_REPOSITORY
ARG BASE_ORGANIZATION=duckietown
ARG BASE_TAG=${DISTRO}-${ARCH}
ARG LAUNCHER=default
ARG OS_FAMILY=ubuntu
ARG OS_DISTRO=focal
# ---
ARG PROJECT_NAME
ARG PROJECT_MAINTAINER
ARG PROJECT_DESCRIPTION
ARG PROJECT_ICON="square"
ARG PROJECT_FORMAT_VERSION
# duckietown environment image
FROM ${DOCKER_REGISTRY}/${BASE_ORGANIZATION}/${BASE_REPOSITORY}:${BASE_TAG} as duckietown
# base image
FROM docker.io/${ARCH}/${OS_FAMILY}:${OS_DISTRO}
# configure pip
ARG PIP_INDEX_URL="https://pypi.org/simple"
ENV PIP_INDEX_URL=${PIP_INDEX_URL}
#
# =====> Replicate the configuration from dt-base-environment ==============================
# recall arguments
ARG OS_FAMILY
ARG OS_DISTRO
# - buildkit
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
# setup environment
ENV INITSYSTEM="off" \
TERM="xterm" \
LANG="C.UTF-8" \
LC_ALL="C.UTF-8" \
READTHEDOCS="True" \
PYTHONIOENCODING="UTF-8" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED="1" \
DEBIAN_FRONTEND="noninteractive" \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
DISABLE_CONTRACTS=1 \
QEMU_EXECVE=1 \
PIP_NO_CACHE_DIR=1 \
PYTHON_VERSION=3.8 \
PIP_ROOT_USER_ACTION=ignore
# nvidia runtime configuration
ENV NVIDIA_VISIBLE_DEVICES="all" \
NVIDIA_DRIVER_CAPABILITIES="all"
# OS info
ENV OS_FAMILY="${OS_FAMILY}" \
OS_DISTRO="${OS_DISTRO}"
# code environment
ENV SOURCE_DIR="/code/src" \
LAUNCHERS_DIR="/launch" \
USER_WS_DIR="/user_ws" \
MINIMUM_DTPROJECT_FORMAT_VERSION="4"
# start inside the course code directory
WORKDIR "${SOURCE_DIR}"
# copy entire project
COPY --from=duckietown "${SOURCE_DIR}/dt-base-environment" "${SOURCE_DIR}/dt-base-environment"
# remove packages that are not supported by catkin
RUN rm -rf "${SOURCE_DIR}/dt-base-environment/packages"
# copy assets
RUN cp ${SOURCE_DIR}/dt-base-environment/assets/qemu/${TARGETPLATFORM}/* /usr/bin/ && \
cp ${SOURCE_DIR}/dt-base-environment/assets/bin/* /usr/local/bin/
# Install gnupg required for apt-key (not in base image since Focal)
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
gnupg \
python3-dev \
python3-pip \
make \
cmake \
gcc \
sudo \
&& rm -rf /var/lib/apt/lists/*
# upgrade PIP
RUN python3 -m pip install pip==22.2 && \
ln -s $(which python3.8) /usr/bin/pip3.8
# install dependencies (PIP3), exclude computed lists because of the difference in base image
RUN rm -f "${SOURCE_DIR}/dt-base-environment/dependencies-py3.computed.txt" && \
dt-pip3-install "${SOURCE_DIR}/dt-base-environment/dependencies-py3.*"
# configure terminal size in docker: https://docs.python.org/3/library/shutil.html#shutil.get_terminal_size
ENV COLUMNS 160
# install launcher scripts
COPY --from=duckietown "${LAUNCHERS_DIR}/dt-base-environment" "${LAUNCHERS_DIR}/dt-base-environment"
RUN dt-install-launchers "${LAUNCHERS_DIR}/dt-base-environment"
# <===== Replicate the configuration from dt-base-environment ==============================
#
#
# =====> Replicate the configuration from dt-commons =======================================
# copy entire project
COPY --from=duckietown "${SOURCE_DIR}/dt-commons" "${SOURCE_DIR}/dt-commons"
# duckie user
ENV DT_USER_NAME="duckie" \
DT_USER_UID=2222 \
DT_GROUP_NAME="duckie" \
DT_GROUP_GID=2222 \
DT_USER_HOME="/home/duckie"
# install dependencies (PIP3), exclude computed lists because of the difference in base image
RUN rm -f "${SOURCE_DIR}/dt-commons/dependencies-py3.computed.txt" && \
dt-pip3-install "${SOURCE_DIR}/dt-commons/dependencies-py3.*"
# create `duckie` user
RUN addgroup --gid ${DT_GROUP_GID} "${DT_GROUP_NAME}" && \
useradd \
--create-home \
--home-dir "${DT_USER_HOME}" \
--comment "Duckietown User" \
--shell "/bin/bash" \
--password "aa26uhROPk6sA" \
--uid ${DT_USER_UID} \
--gid ${DT_GROUP_GID} \
"${DT_USER_NAME}"
# copy image root
RUN cp -R ${SOURCE_DIR}/dt-commons/assets/root/. /
# configure arch-specific environment
RUN ${SOURCE_DIR}/dt-commons/assets/setup/${TARGETPLATFORM}/setup.sh
# install assets
RUN ${SOURCE_DIR}/dt-commons/assets/setup/install-binaries.sh
# source environment on every bash session
RUN echo "source /environment.sh" >> /etc/bash.bashrc
# configure entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# install launcher scripts
COPY --from=duckietown "${LAUNCHERS_DIR}/dt-commons" "${LAUNCHERS_DIR}/dt-commons"
RUN dt-install-launchers "${LAUNCHERS_DIR}/dt-commons"
# create health file
RUN echo ND > /health && \
chmod 777 /health && \
sudo -u ${DT_USER_NAME} touch /health
# define healthcheck
HEALTHCHECK \
--interval=30s \
CMD cat /health && grep -q '^healthy\|ND$' /health
# <===== Replicate the configuration from dt-commons =======================================
#
#
# =====> This DTProject ====================================================================
# recall arguments
ARG ARCH
ARG DISTRO
ARG DOCKER_REGISTRY
ARG PROJECT_NAME
ARG PROJECT_DESCRIPTION
ARG PROJECT_MAINTAINER
ARG PROJECT_ICON
ARG PROJECT_FORMAT_VERSION
ARG BASE_TAG
ARG BASE_REPOSITORY
ARG BASE_ORGANIZATION
ARG LAUNCHER
# check build arguments
RUN dt-args-check \
"PROJECT_NAME" "${PROJECT_NAME}" \
"PROJECT_DESCRIPTION" "${PROJECT_DESCRIPTION}" \
"PROJECT_MAINTAINER" "${PROJECT_MAINTAINER}" \
"PROJECT_ICON" "${PROJECT_ICON}" \
"PROJECT_FORMAT_VERSION" "${PROJECT_FORMAT_VERSION}" \
"ARCH" "${ARCH}" \
"DISTRO" "${DISTRO}" \
"DOCKER_REGISTRY" "${DOCKER_REGISTRY}" \
"BASE_REPOSITORY" "${BASE_REPOSITORY}" \
&& dt-check-project-format "${PROJECT_FORMAT_VERSION}"
# define/create repository path
ARG PROJECT_PATH="${SOURCE_DIR}/${PROJECT_NAME}"
ARG PROJECT_LAUNCHERS_PATH="${LAUNCHERS_DIR}/${PROJECT_NAME}"
RUN mkdir -p "${PROJECT_PATH}" "${PROJECT_LAUNCHERS_PATH}"
WORKDIR "${PROJECT_PATH}"
# keep some arguments as environment variables
ENV DT_PROJECT_NAME="${PROJECT_NAME}" \
DT_PROJECT_DESCRIPTION="${PROJECT_DESCRIPTION}" \
DT_PROJECT_MAINTAINER="${PROJECT_MAINTAINER}" \
DT_PROJECT_ICON="${PROJECT_ICON}" \
DT_PROJECT_PATH="${PROJECT_PATH}" \
DT_PROJECT_LAUNCHERS_PATH="${PROJECT_LAUNCHERS_PATH}" \
DT_LAUNCHER="${LAUNCHER}"
# install dependencies (APT)
COPY ./dependencies-apt.txt "${PROJECT_PATH}/"
RUN dt-apt-install "${PROJECT_PATH}/dependencies-apt.txt"
# install dependencies (PIP3)
COPY ./dependencies-py3.* "${PROJECT_PATH}/"
RUN dt-pip3-install "${PROJECT_PATH}/dependencies-py3.*"
# install LCM
ENV LCM_VERSION="1.5.0"
RUN cd /tmp/ \
&& git clone -b "v${LCM_VERSION}" https://github.com/lcm-proj/lcm \
&& mkdir -p lcm/build \
&& cd lcm/build \
&& cmake .. \
&& make \
&& make install \
&& cd ~ \
&& rm -rf /tmp/lcm
# copy the source code
COPY ./packages "${PROJECT_PATH}/packages"
# install launcher scripts
COPY ./launchers/. "${PROJECT_LAUNCHERS_PATH}/"
RUN dt-install-launchers "${PROJECT_LAUNCHERS_PATH}"
# install scripts
COPY ./assets/entrypoint.d "${PROJECT_PATH}/assets/entrypoint.d"
COPY ./assets/environment.d "${PROJECT_PATH}/assets/environment.d"
# define default command
CMD ["bash", "-c", "dt-launcher-${DT_LAUNCHER}"]
# store module metadata
LABEL \
# module info
org.duckietown.label.project.name="${PROJECT_NAME}" \
org.duckietown.label.project.description="${PROJECT_DESCRIPTION}" \
org.duckietown.label.project.maintainer="${PROJECT_MAINTAINER}" \
org.duckietown.label.project.icon="${PROJECT_ICON}" \
org.duckietown.label.project.path="${PROJECT_PATH}" \
org.duckietown.label.project.launchers.path="${PROJECT_LAUNCHERS_PATH}" \
# format
org.duckietown.label.format.version="${PROJECT_FORMAT_VERSION}" \
# platform info
org.duckietown.label.platform.os="${TARGETOS}" \
org.duckietown.label.platform.architecture="${TARGETARCH}" \
org.duckietown.label.platform.variant="${TARGETVARIANT}" \
# code info
org.duckietown.label.code.distro="${DISTRO}" \
org.duckietown.label.code.launcher="${LAUNCHER}" \
org.duckietown.label.code.python.registry="${PIP_INDEX_URL}" \
# base info
org.duckietown.label.base.organization="${BASE_ORGANIZATION}" \
org.duckietown.label.base.repository="${BASE_REPOSITORY}" \
org.duckietown.label.base.tag="${BASE_TAG}"
# make all containers down the tree run as root
ENV DT_SUPERUSER=1