1 # lib_apt.sh - Docker build script apt library.
4 # Copyright (c) 2024 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 DIND_FROM_IMAGE="cruizba/ubuntu-dind:jammy-26.1.3-r2"
24 HST_FROM_IMAGE="ubuntu:22.04"
26 export CIMAN_DOCKER_SCRIPTS=${CIMAN_DOCKER_SCRIPTS:-"$(dirname $BASH_SOURCE)"}
27 . "$CIMAN_DOCKER_SCRIPTS/lib_common.sh"
28 . "$CIMAN_DOCKER_SCRIPTS/lib_csit.sh"
30 dump_apt_package_list() {
31 branchname="$(echo $branch | sed -e 's,/,_,')"
33 "$DOCKER_BUILD_LOG_DIR/$FDIOTOOLS_IMAGENAME-$branchname-apt-packages.log"
36 apt_install_packages() {
37 apt-get install -y --allow-downgrades --allow-remove-essential \
38 --allow-change-held-packages $@
41 generate_apt_dockerfile_common() {
42 local executor_class="$1"
43 local executor_image="$2"
44 local dpkg_arch="$(dpkg --print-architecture)"
46 cat <<EOF >>"$DOCKERFILE"
48 # Create download dir to cache external tarballs
49 WORKDIR $DOCKER_DOWNLOADS_DIR
51 # Copy-in temporary build tree containing
52 # ci-management, vpp, & csit git repos
53 WORKDIR $DOCKER_BUILD_DIR
56 # Build Environment Variables
57 ENV DEBIAN_FRONTEND="noninteractive"
58 ENV FDIOTOOLS_IMAGE="$executor_image"
59 ENV FDIOTOOLS_EXECUTOR_CLASS="$executor_class"
60 ENV CIMAN_ROOT="$DOCKER_CIMAN_ROOT"
61 ENV PATH="\$PATH:$DOCKER_CIMAN_ROOT/docker/scripts"
64 RUN apt-get update -qq \\
65 && apt-get install -y \\
68 && sed -i 's/# \(en_US\.UTF-8 .*\)/\1/' /etc/locale.gen \\
69 && locale-gen en_US.UTF-8 \\
70 && dpkg-reconfigure --frontend=noninteractive locales \\
71 && update-locale LANG=en_US.UTF-8 \\
72 && TZ=Etc/UTC && ln -snf /usr/share/zoneinfo/\$TZ /etc/localtime && echo \$TZ > /etc/timezone \\
73 && rm -r /var/lib/apt/lists/*
74 ENV LANG="en_US.UTF-8" LANGUAGE="en_US" LC_ALL="en_US.UTF-8"
76 # Install baseline packages (minimum build & utils).
78 # ci-management global-jjb requirements:
86 # from packer/provision/baseline.sh:
98 # Python build from source requirements:
101 # TODO: Fix broken project requirement install targets
102 # graphviz for doxygen (HICN)
103 # doxygen for doxygen (HICN)
104 # libffi-dev for python cffi install (Ubuntu20.04/VPP/aarch64)
105 # liblapack-dev for python numpy/scipy (CSIT/aarch64)
106 # libopenblas-dev for python numpy/scipy (CSIT/aarch64)
107 # libpcap-dev for python pypcap install (CSIT)
108 # sshpass for CSIT jobs
110 RUN apt-get update -qq \\
111 && apt-get install -y \\
112 apt-transport-https \\
141 python3-virtualenv \\
144 software-properties-common \\
154 && curl -L https://packagecloud.io/fdio/master/gpgkey | apt-key add - \\
155 && curl -s https://packagecloud.io/install/repositories/fdio/master/script.deb.sh | bash \\
156 && rm -r /var/lib/apt/lists/*
158 # Install terraform for CSIT
160 RUN wget https://releases.hashicorp.com/terraform/1.7.3/terraform_1.7.3_linux_$dpkg_arch.zip \\
161 && unzip terraform_1.7.3_linux_$dpkg_arch.zip \\
162 && mv terraform /usr/bin \\
163 && rm -f terraform_1.7.3_linux_$dpkg_arch.zip
166 generate_apt_dockerfile_install_golang
168 cat <<EOF >>"$DOCKERFILE"
170 # Install packages for all project branches
172 RUN apt-get update -qq \\
173 && dbld_vpp_install_packages.sh \\
174 && dbld_csit_install_packages.sh \\
175 && apt-get install -y pkg-config \\
176 && rm -r /var/lib/apt/lists/*
180 generate_apt_dockerfile_clean() {
181 cat <<EOF >>"$DOCKERFILE"
183 # Clean up copy-in build tree
184 RUN dbld_dump_build_logs.sh \\
185 && apt-get -y autoremove \\
186 && rm -rf "/tmp/*" "$DOCKER_BUILD_FILES_DIR" "/root/.ccache"
190 generate_apt_dockerfile_install_golang() {
191 local go_tarball_arch="amd64"
193 if [ "$OS_ARCH" = "aarch64" ] ; then
194 go_tarball_arch="arm64"
197 cat <<EOF >>"$DOCKERFILE"
199 # Install golang for HostStack Test (HST) jobs
202 ENV GOROOT /usr/local/go
203 ENV PATH \$GOPATH/bin:/usr/local/go/bin:\$PATH
204 RUN rm -rf /usr/local/go /usr/bin/go \\
205 && wget -P /tmp "https://go.dev/dl/go${DOCKER_GOLANG_VERSION}.linux-${go_tarball_arch}.tar.gz" \\
206 && tar -C /usr/local -xzf "/tmp/go${DOCKER_GOLANG_VERSION}.linux-${go_tarball_arch}.tar.gz" \\
207 && rm "/tmp/go${DOCKER_GOLANG_VERSION}.linux-${go_tarball_arch}.tar.gz" \\
208 && ln -s /usr/local/go/bin/go /usr/bin/go \\
209 && echo -n "\nGOPATH=\$GOPATH\nGOROOT=\$GOROOT" | tee -a /etc/environment \\
210 && mkdir -p "\$GOPATH/src" "\$GOPATH/bin" && chmod -R 777 "\$GOPATH"
214 # Generate 'builder' class apt dockerfile
215 builder_generate_apt_dockerfile() {
216 local executor_class="$1"
217 local executor_os_name="$2"
218 local executor_image="$3"
219 local vpp_install_skip_sysctl_envvar="";
221 generate_apt_dockerfile_common "$executor_class" "$executor_image"
222 csit_builder_generate_docker_build_files
223 cat <<EOF >>"$DOCKERFILE"
225 # Install LF-IT requirements
226 ENV LF_VENV="/root/lf-venv"
227 RUN apt-get update -qq \\
228 && dbld_lfit_requirements.sh \\
229 && rm -r /var/lib/apt/lists/*
231 # Install packagecloud requirements
232 RUN gem install rake package_cloud \\
233 && curl -s https://packagecloud.io/install/repositories/fdio/master/script.deb.sh | bash
235 # Install CSIT ssh requirements
236 # TODO: Verify why badkey is required & figure out how to avoid it.
237 COPY files/badkey /root/.ssh/id_rsa
238 COPY files/sshconfig /root/.ssh/config
240 # CI Runtime Environment
242 $vpp_install_skip_sysctl_envvar
243 ENV VPP_ZOMBIE_NOCHECK="1"
244 ENV CCACHE_DIR="/scratch/ccache"
245 ENV CCACHE_MAXSIZE="10G"
247 generate_apt_dockerfile_clean
250 # Generate 'csit_dut' class apt dockerfile
251 csit_dut_generate_apt_dockerfile() {
252 local executor_class="$1"
253 local executor_os_name="$2"
254 local executor_image="$3"
256 csit_dut_generate_docker_build_files
257 generate_apt_dockerfile_common "$executor_class" "$executor_image"
258 cat <<EOF >>"$DOCKERFILE"
260 # Install csit_dut specific packages
261 RUN apt-get update -qq \\
262 && apt-get install -y \\
268 && rm -r /var/lib/apt/lists/*
271 RUN chown root:syslog /var/log \\
272 && chmod 755 /etc/default
274 # Create directory structure
275 RUN mkdir -p /var/run/sshd
278 RUN echo 'root:Csit1234' | chpasswd \\
279 && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \\
280 && sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
284 COPY files/supervisord.conf /etc/supervisor/supervisord.conf
286 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"]
288 generate_apt_dockerfile_clean
291 # Generate 'csit_shim' class apt dockerfile
292 csit_shim_generate_apt_dockerfile() {
293 local executor_class="$1"
294 local executor_os_name="$2"
295 local executor_image="$3"
297 csit_shim_generate_docker_build_files
298 cat <<EOF >>"$DOCKERFILE"
300 # Copy-in temporary build tree containing
301 # ci-management, vpp, & csit git repos
302 WORKDIR $DOCKER_BUILD_DIR
305 # Build Environment Variables
306 ENV DEBIAN_FRONTEND="noninteractive"
307 ENV FDIOTOOLS_IMAGE="$executor_image"
308 ENV FDIOTOOLS_EXECUTOR_CLASS="$executor_class"
309 ENV CIMAN_ROOT="$DOCKER_CIMAN_ROOT"
310 ENV PATH="\$PATH:$DOCKER_CIMAN_ROOT/docker/scripts"
312 # Configure locales & timezone
313 RUN apt-get update -qq \\
314 && apt-get install -y \\
317 && sed -i 's/# \(en_US\.UTF-8 .*\)/\1/' /etc/locale.gen \\
318 && locale-gen en_US.UTF-8 \\
319 && dpkg-reconfigure --frontend=noninteractive locales \\
320 && update-locale LANG=en_US.UTF-8 \\
321 && TZ=Etc/UTC && ln -snf /usr/share/zoneinfo/\$TZ /etc/localtime && echo \$TZ > /etc/timezone \\
322 && rm -r /var/lib/apt/lists/*
323 ENV LANG=en_US.UTF-8 LANGUAGE=en_US LC_ALL=en_US.UTF-8
325 COPY files/wrapdocker /usr/local/bin/wrapdocker
326 RUN chmod +x /usr/local/bin/wrapdocker
328 # Install packages and Docker
329 RUN apt-get update -qq \\
330 && apt-get install -y \\
339 && curl -fsSL https://get.docker.com | sh \\
340 && rm -rf /var/lib/apt/lists/*
342 RUN mkdir /var/run/sshd
343 RUN echo 'root:Csit1234' | chpasswd
344 RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
346 # SSH login fix. Otherwise user is kicked off after login
347 RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
349 # Need volume for sidecar docker launches
350 VOLUME /var/lib/docker
352 # SSH to listen on port 6022 in shim
353 RUN echo 'Port 6022' >>/etc/ssh/sshd_config
354 RUN echo 'Port 6023' >>/etc/ssh/sshd_config
356 # TODO: Verify why badkeypub is required & figure out how to avoid it.
357 COPY files/badkeypub /root/.ssh/authorized_keys
358 COPY files/sshconfig /root/.ssh/config
360 # Clean up copy-in build tree
361 RUN rm -rf /tmp/* $DOCKER_BUILD_FILES_DIR
363 # Start sshd by default
365 CMD ["/usr/sbin/sshd", "-D"]
369 generate_apt_dockerfile() {
370 local executor_class="$1"
371 local executor_os_name="$2"
372 local from_image="$3"
373 local executor_image="$4"
374 local is_dind_image="false"
376 # TODO: Enable HST on AARCH64 when supported in vpp/extras/hs-test
377 if [ "$from_image" = "$HST_FROM_IMAGE" ] ; then
378 from_image="$DIND_FROM_IMAGE"
382 cat <<EOF >"$DOCKERIGNOREFILE"
386 cat <<EOF >"$DOCKERFILE"
387 FROM $from_image AS ${executor_class}-executor-image
388 LABEL Description="FD.io CI '$executor_class' executor docker image for $executor_os_name/$OS_ARCH"
390 LABEL Version="$DOCKER_TAG"
392 if [ "$is_dind_image" = "true" ] ; then
393 cat <<EOF >>"$DOCKERFILE"
394 # Remove extraneous environment variable(s) created in "$from_image"
399 "${executor_class}"_generate_apt_dockerfile "$executor_class" \
400 "$executor_os_name" "$executor_image"