1 # lib_apt.sh - Docker build script apt library.
4 # Copyright (c) 2023 Cisco and/or its affiliates.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Don't import more than once.
18 if [ -n "$(alias lib_apt_imported 2> /dev/null)" ] ; then
21 alias lib_apt_imported=true
23 export CIMAN_DOCKER_SCRIPTS=${CIMAN_DOCKER_SCRIPTS:-"$(dirname $BASH_SOURCE)"}
24 . "$CIMAN_DOCKER_SCRIPTS/lib_common.sh"
25 . "$CIMAN_DOCKER_SCRIPTS/lib_csit.sh"
27 dump_apt_package_list() {
28 branchname="$(echo $branch | sed -e 's,/,_,')"
30 "$DOCKER_BUILD_LOG_DIR/$FDIOTOOLS_IMAGENAME-$branchname-apt-packages.log"
33 apt_install_packages() {
34 apt-get install -y --allow-downgrades --allow-remove-essential \
35 --allow-change-held-packages $@
38 generate_apt_dockerfile_common() {
39 local executor_class="$1"
40 local executor_image="$2"
41 local dpkg_arch="$(dpkg --print-architecture)"
43 cat <<EOF >>"$DOCKERFILE"
45 # Create download dir to cache external tarballs
46 WORKDIR $DOCKER_DOWNLOADS_DIR
48 # Copy-in temporary build tree containing
49 # ci-management, vpp, & csit git repos
50 WORKDIR $DOCKER_BUILD_DIR
53 # Build Environment Variables
54 ENV DEBIAN_FRONTEND="noninteractive"
55 ENV FDIOTOOLS_IMAGE="$executor_image"
56 ENV FDIOTOOLS_EXECUTOR_CLASS="$executor_class"
57 ENV CIMAN_ROOT="$DOCKER_CIMAN_ROOT"
58 ENV PATH="\$PATH:$DOCKER_CIMAN_ROOT/docker/scripts"
61 RUN apt-get update -qq \\
62 && apt-get install -y \\
65 && sed -i 's/# \(en_US\.UTF-8 .*\)/\1/' /etc/locale.gen \\
66 && locale-gen en_US.UTF-8 \\
67 && dpkg-reconfigure --frontend=noninteractive locales \\
68 && update-locale LANG=en_US.UTF-8 \\
69 && TZ=Etc/UTC && ln -snf /usr/share/zoneinfo/\$TZ /etc/localtime && echo \$TZ > /etc/timezone \\
70 && rm -r /var/lib/apt/lists/*
71 ENV LANG="en_US.UTF-8" LANGUAGE="en_US" LC_ALL="en_US.UTF-8"
73 # Install baseline packages (minimum build & utils).
75 # ci-management global-jjb requirements:
83 # from packer/provision/baseline.sh:
95 # Python build from source requirements:
98 # TODO: Fix broken project requirement install targets
99 # graphviz for doxygen (HICN)
100 # doxygen for doxygen (HICN)
101 # libffi-dev for python cffi install (Ubuntu20.04/VPP/aarch64)
102 # liblapack-dev for python numpy/scipy (CSIT/aarch64)
103 # libopenblas-dev for python numpy/scipy (CSIT/aarch64)
104 # libpcap-dev for python pypcap install (CSIT)
105 # sshpass for CSIT jobs
107 RUN apt-get update -qq \\
108 && apt-get install -y \\
109 apt-transport-https \\
140 software-properties-common \\
150 && curl -L https://packagecloud.io/fdio/master/gpgkey | apt-key add - \\
151 && curl -s https://packagecloud.io/install/repositories/fdio/master/script.deb.sh | bash \\
152 && rm -r /var/lib/apt/lists/*
154 # Install terraform for CSIT
156 RUN wget https://releases.hashicorp.com/terraform/1.7.3/terraform_1.7.3_linux_$dpkg_arch.zip \\
157 && unzip terraform_1.7.3_linux_$dpkg_arch.zip \\
158 && mv terraform /usr/bin \\
159 && rm -f terraform_1.7.3_linux_$dpkg_arch.zip
161 # Install packages for all project branches
163 RUN apt-get update -qq \\
164 && dbld_vpp_install_packages.sh \\
165 && dbld_csit_install_packages.sh \\
166 && rm -r /var/lib/apt/lists/*
170 generate_apt_dockerfile_clean() {
171 cat <<EOF >>"$DOCKERFILE"
173 # Clean up copy-in build tree
174 RUN dbld_dump_build_logs.sh \\
175 && rm -rf "/tmp/*" "$DOCKER_BUILD_FILES_DIR" "/root/.ccache"
179 # Generate 'builder' class apt dockerfile
180 builder_generate_apt_dockerfile() {
181 local executor_class="$1"
182 local executor_os_name="$2"
183 local executor_image="$3"
184 local vpp_install_skip_sysctl_envvar="";
186 generate_apt_dockerfile_common $executor_class $executor_image
187 csit_builder_generate_docker_build_files
188 cat <<EOF >>"$DOCKERFILE"
190 # Install LF-IT requirements
191 ENV LF_VENV="/root/lf-venv"
192 RUN apt-get update -qq \\
193 && dbld_lfit_requirements.sh \\
194 && rm -r /var/lib/apt/lists/*
196 # Install packagecloud requirements
197 RUN gem install rake package_cloud \\
198 && curl -s https://packagecloud.io/install/repositories/fdio/master/script.deb.sh | bash
200 # Install CSIT ssh requirements
201 # TODO: Verify why badkey is required & figure out how to avoid it.
202 COPY files/badkey /root/.ssh/id_rsa
203 COPY files/sshconfig /root/.ssh/config
205 # CI Runtime Environment
207 $vpp_install_skip_sysctl_envvar
208 ENV VPP_ZOMBIE_NOCHECK="1"
209 ENV CCACHE_DIR="/scratch/ccache"
210 ENV CCACHE_MAXSIZE="10G"
212 generate_apt_dockerfile_clean
215 # Generate 'csit_dut' class apt dockerfile
216 csit_dut_generate_apt_dockerfile() {
217 local executor_class="$1"
218 local executor_os_name="$2"
219 local executor_image="$3"
221 csit_dut_generate_docker_build_files
222 generate_apt_dockerfile_common "$executor_class" "$executor_image"
223 cat <<EOF >>"$DOCKERFILE"
225 # Install csit_dut specific packages
226 RUN apt-get update -qq \\
227 && apt-get install -y \\
233 && rm -r /var/lib/apt/lists/*
236 RUN chown root:syslog /var/log \\
237 && chmod 755 /etc/default
239 # Create directory structure
240 RUN mkdir -p /var/run/sshd
243 RUN echo 'root:Csit1234' | chpasswd \\
244 && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \\
245 && sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
249 COPY files/supervisord.conf /etc/supervisor/supervisord.conf
251 CMD ["sh", "-c", "rm -f /dev/shm/db /dev/shm/global_vm /dev/shm/vpe-api; /usr/bin/supervisord -c /etc/supervisor/supervisord.conf; /usr/sbin/sshd -D -p 2222"]
253 generate_apt_dockerfile_clean
256 # Generate 'csit_shim' class apt dockerfile
257 csit_shim_generate_apt_dockerfile() {
258 local executor_class="$1"
259 local executor_os_name="$2"
260 local executor_image="$3"
262 csit_shim_generate_docker_build_files
263 cat <<EOF >>"$DOCKERFILE"
265 # Copy-in temporary build tree containing
266 # ci-management, vpp, & csit git repos
267 WORKDIR $DOCKER_BUILD_DIR
270 # Build Environment Variables
271 ENV DEBIAN_FRONTEND="noninteractive"
272 ENV FDIOTOOLS_IMAGE="$executor_image"
273 ENV FDIOTOOLS_EXECUTOR_CLASS="$executor_class"
274 ENV CIMAN_ROOT="$DOCKER_CIMAN_ROOT"
275 ENV PATH="\$PATH:$DOCKER_CIMAN_ROOT/docker/scripts"
277 # Configure locales & timezone
278 RUN apt-get update -qq \\
279 && apt-get install -y \\
282 && sed -i 's/# \(en_US\.UTF-8 .*\)/\1/' /etc/locale.gen \\
283 && locale-gen en_US.UTF-8 \\
284 && dpkg-reconfigure --frontend=noninteractive locales \\
285 && update-locale LANG=en_US.UTF-8 \\
286 && TZ=Etc/UTC && ln -snf /usr/share/zoneinfo/\$TZ /etc/localtime && echo \$TZ > /etc/timezone \\
287 && rm -r /var/lib/apt/lists/*
288 ENV LANG=en_US.UTF-8 LANGUAGE=en_US LC_ALL=en_US.UTF-8
290 COPY files/wrapdocker /usr/local/bin/wrapdocker
291 RUN chmod +x /usr/local/bin/wrapdocker
293 # Install packages and Docker
294 RUN apt-get update -qq \\
295 && apt-get install -y \\
304 && curl -fsSL https://get.docker.com | sh \\
305 && rm -rf /var/lib/apt/lists/*
307 RUN mkdir /var/run/sshd
308 RUN echo 'root:Csit1234' | chpasswd
309 RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
311 # SSH login fix. Otherwise user is kicked off after login
312 RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
314 # Need volume for sidecar docker launches
315 VOLUME /var/lib/docker
317 # SSH to listen on port 6022 in shim
318 RUN echo 'Port 6022' >>/etc/ssh/sshd_config
319 RUN echo 'Port 6023' >>/etc/ssh/sshd_config
321 # TODO: Verify why badkeypub is required & figure out how to avoid it.
322 COPY files/badkeypub /root/.ssh/authorized_keys
323 COPY files/sshconfig /root/.ssh/config
325 # Clean up copy-in build tree
326 RUN rm -rf /tmp/* $DOCKER_BUILD_FILES_DIR
328 # Start sshd by default
330 CMD ["/usr/sbin/sshd", "-D"]
334 generate_apt_dockerfile() {
335 local executor_class="$1"
336 local executor_os_name="$2"
337 local from_image="$3"
338 local executor_image="$4"
340 cat <<EOF >"$DOCKERIGNOREFILE"
344 cat <<EOF >"$DOCKERFILE"
345 FROM $from_image AS ${executor_class}-executor-image
346 LABEL Description="FD.io CI '$executor_class' executor docker image for $executor_os_name/$OS_ARCH"
348 LABEL Version="$DOCKER_TAG"
350 ${executor_class}_generate_apt_dockerfile "$executor_class" \
351 "$executor_os_name" "$executor_image"