639e7f073d0a51ee00b55e1d7e2dedd6d5703f52
[ci-management.git] / docker / scripts / lib_dnf.sh
1 # lib_dnf.sh - Docker build script dnf library.
2 #              For import only.
3
4 # Copyright (c) 2020 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:
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17 # Don't import more than once.
18 if [ -n "$(alias lib_dnf_imported 2> /dev/null)" ] ; then
19     return 0
20 fi
21 alias lib_dnf_imported=true
22
23 export CIMAN_DOCKER_SCRIPTS=${CIMAN_DOCKER_SCRIPTS:-"$(dirname $BASH_SOURCE)"}
24 . $CIMAN_DOCKER_SCRIPTS/lib_common.sh
25
26 dump_dnf_package_list() {
27     branchname="$(echo $branch | sed -e 's,/,_,')"
28     dnf list installed > \
29         "$DOCKER_BUILD_LOG_DIR/$FDIOTOOLS_IMAGENAME-$branchname-dnf-packages.log"
30 }
31
32 dnf_install_packages() {
33     dnf install -y $@
34 }
35
36 dnf_install_docker_os_package_dependancies() {
37     dnf_install_packages dnf-utils
38 }
39
40 dnf_install_docker() {
41     # Note: Support for docker has been removed starting with centos-8, so the
42     #       only recourse is to pin the latest version by what's in the download dir.
43     # Browse the base URL to see what is available & update accordingly.
44
45     if [ "$OS_NAME" = "centos-8" ] ; then
46         dnf install -y https://download.docker.com/linux/$OS_ID/$OS_VERSION_ID/$OS_ARCH/stable/Packages/containerd.io-1.3.7-3.1.el8.$OS_ARCH.rpm
47         dnf install -y https://download.docker.com/linux/$OS_ID/$OS_VERSION_ID/$OS_ARCH/stable/Packages/docker-ce-cli-19.03.13-3.el8.$OS_ARCH.rpm
48         dnf install -y https://download.docker.com/linux/$OS_ID/$OS_VERSION_ID/$OS_ARCH/stable/Packages/docker-ce-19.03.13-3.el8.$OS_ARCH.rpm
49     else
50         echo_log "WARNING: Docker Image unknown for $OS_NAME!"
51     fi
52 }
53
54 generate_dnf_dockerfile() {
55     local executor_os_name=$1
56     local from_image=$2
57     local executor_image=$3
58     local from_image_os_id="$(echo $from_image | cut -d: -f2)"
59
60     cat <<EOF >$DOCKERFILE
61 FROM $from_image AS executor-image
62 LABEL Description="FD.io CI executor docker image for $executor_os_name/$OS_ARCH"
63 LABEL Vendor="fd.io"
64 LABEL Version="$DOCKER_TAG"
65
66 # Build Environment Variables
67 ENV FDIOTOOLS_IMAGE=$executor_image
68 ENV LC_ALL=C.UTF-8
69 ENV CIMAN_ROOT="$DOCKER_CIMAN_ROOT"
70 ENV PATH=$PATH:$DOCKER_CIMAN_ROOT/docker/scripts
71
72 # Copy-in build tree containing
73 # ci-management, vpp, & csit git repos
74 WORKDIR $DOCKER_BUILD_DIR
75 COPY . .
76
77 # Install baseline packages (minimum build & utils).
78 #
79 # ci-management global-jjb requirements:
80 #   for lftools:
81 #       libxml2-devel
82 #       xmlstarlet
83 #   for lf-env.sh:
84 #       facter
85 #   from global-jjb/packer/provision/baseline.sh:
86 #       deltarpm
87 #       unzip
88 #       xz
89 #       puppet
90 #       python3-pip
91 #       git
92 #       git-review
93 #       perl-XML-XPath
94 #       make
95 #       wget
96 #
97 # TODO: Fix broken project requirement install targets
98 #
99 #   graphviz           for 'make bootstrap-doxygen' (VPP)
100 #   doxygen            for 'make doxygen' (VPP)
101 #   enchant            for 'make docs' (VPP)
102 #   libffi-devel       for python cffi install (Ubuntu20.04/VPP/aarch64)
103 #   libpcap-devel      for python pypcap install (CSIT)
104 #   lapack-devel    for python numpy/scipy (CSIT/aarch64)
105 #   openblas-devel  for python numpy/scipy (CSIT/aarch64)
106 #
107 RUN export LC_ALL=C.UTF8 \\
108     && dnf update -y \\
109     && dnf install -y \\
110         dnf-plugins-core \\
111         epel-release \\
112     && dnf config-manager --set-enabled \$(dnf repolist all 2> /dev/null | grep -i powertools | cut -d' ' -f1) --set-enabled epel \\
113     && dnf repolist all \\
114     && dnf clean all
115 RUN export LC_ALL=C.UTF8 \\
116     && dnf update -y \\
117     && dnf install -y \\
118         dnf-utils \\
119         doxygen \\
120         enchant \\
121         emacs \\
122         facter \\
123         git \\
124         git-review \\
125         graphviz \\
126         iproute \\
127         java-1.8.0-openjdk \\
128         java-1.8.0-openjdk-devel \\
129         jq \\
130         lapack-devel \\
131         libffi-devel \\
132         libpcap-devel \\
133         libxml2-devel \\
134         make \\
135         mawk \\
136         mock \\
137         openblas-devel \\
138         perl \\
139         perl-XML-XPath \\
140         python3-pip \\
141         puppet \\
142         rake \\
143         rsync \\
144         ruby-devel \\
145         sudo \\
146         tree \\
147         unzip \\
148         vim \\
149         wget \\
150         xmlstarlet \\
151         xz \\
152     && dnf clean all
153
154 # Install OS packages for project branches
155 #
156 RUN dbld_vpp_install_packages.sh \\
157     && dbld_install_docker.sh \\
158     && dbld_csit_install_packages.sh \\
159     && dbld_lfit_requirements.sh \\
160     && dnf clean all
161
162 # CI Runtime Environment
163 WORKDIR /
164 ENV VPP_ZOMBIE_NOCHECK=1
165 RUN gem install package_cloud \\
166     && curl -s https://packagecloud.io/install/repositories/fdio/master/script.rpm.sh | sudo bash
167
168 # Clean up
169 RUN dbld_dump_build_logs.sh \\
170     && rm -rf /tmp/*
171 EOF
172 }