-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
137 lines (115 loc) · 3.77 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
# parameters
ARG REPO_NAME="dt-commons"
ARG MAINTAINER="Andrea F. Daniele ([email protected])"
ARG DESCRIPTION="Base image containing common libraries and environment setup for non-ROS applications."
ARG ICON="square"
ARG ARCH
ARG DISTRO=daffy
ARG DOCKER_REGISTRY=docker.io
ARG BASE_IMAGE=dt-base-environment
ARG BASE_TAG=${DISTRO}-${ARCH}
ARG LAUNCHER=default
# define base image
FROM ${DOCKER_REGISTRY}/duckietown/${BASE_IMAGE}:${BASE_TAG} as base
# recall all arguments
ARG REPO_NAME
ARG DESCRIPTION
ARG MAINTAINER
ARG ICON
ARG DISTRO
ARG OS_DISTRO
ARG BASE_TAG
ARG BASE_IMAGE
ARG LAUNCHER
# - buildkit
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
# define and create repository path
ARG REPO_PATH="${SOURCE_DIR}/${REPO_NAME}"
ARG LAUNCH_PATH="${LAUNCH_DIR}/${REPO_NAME}"
RUN mkdir -p "${REPO_PATH}" "${LAUNCH_PATH}"
WORKDIR "${REPO_PATH}"
# keep some arguments as environment variables
ENV DT_MODULE_TYPE="${REPO_NAME}" \
DT_MODULE_DESCRIPTION="${DESCRIPTION}" \
DT_MODULE_ICON="${ICON}" \
DT_MAINTAINER="${MAINTAINER}" \
DT_REPO_PATH="${REPO_PATH}" \
DT_LAUNCH_PATH="${LAUNCH_PATH}" \
DT_LAUNCHER="${LAUNCHER}"
# 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 apt dependencies
COPY ./dependencies-apt.txt "${REPO_PATH}/"
RUN dt-apt-install "${REPO_PATH}/dependencies-apt.txt"
# install python dependencies
ARG PIP_INDEX_URL="https://pypi.org/simple/"
ENV PIP_INDEX_URL=${PIP_INDEX_URL}
RUN python3 -m pip install pip==24.0
# install dependencies (PIP3)
COPY ./dependencies-py3.* "${REPO_PATH}/"
RUN dt-pip3-install "${REPO_PATH}/dependencies-py3.*"
# install LCM
RUN cd /tmp/ \
&& git clone -b v1.4.0 https://github.com/lcm-proj/lcm \
&& mkdir -p lcm/build \
&& cd lcm/build \
&& cmake .. \
&& make \
&& make install \
&& cd ~ \
&& rm -rf /tmp/lcm
# configure arch-specific environment
COPY assets/setup/${TARGETPLATFORM}/setup.sh /tmp/setup-by-arch.sh
RUN /tmp/setup-by-arch.sh
# 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 the source code
COPY ./packages "${REPO_PATH}/packages"
# copy binaries
COPY ./assets/bin/. /usr/local/bin/
# copy environment / entrypoint
COPY assets/entrypoint.sh /entrypoint.sh
COPY assets/environment.sh /environment.sh
# copy code setup script
COPY assets/code/setup.bash /code/setup.bash
# source environment on every bash session
RUN echo "source /environment.sh" >> ~/.bashrc
# configure entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# install launcher scripts
COPY ./launchers/. "${LAUNCH_PATH}/"
RUN dt-install-launchers "${LAUNCH_PATH}"
# define default command
CMD ["bash", "-c", "dt-launcher-${DT_LAUNCHER}"]
# store module metadata
LABEL org.duckietown.label.module.type="${REPO_NAME}" \
org.duckietown.label.module.description="${DESCRIPTION}" \
org.duckietown.label.module.icon="${ICON}" \
org.duckietown.label.platform.os="${TARGETOS}" \
org.duckietown.label.platform.architecture="${TARGETARCH}" \
org.duckietown.label.platform.variant="${TARGETVARIANT}" \
org.duckietown.label.code.location="${REPO_PATH}" \
org.duckietown.label.code.version.distro="${DISTRO}" \
org.duckietown.label.base.image="${BASE_IMAGE}" \
org.duckietown.label.base.tag="${BASE_TAG}" \
org.duckietown.label.maintainer="${MAINTAINER}"
# relax healthcheck to include ND as healthy state
HEALTHCHECK \
--interval=30s \
CMD cat /health && grep -q '^healthy\|ND$' /health