build_inf_prepare_jenkins: remove installation of docker
[pti/rtp.git] / scripts / build_inf_centos / build_inf_prepare_jenkins.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2022 Wind River Systems, Inc.
4 #
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
18 # Ensure we fail the job if any steps fail.
19 set -e -o pipefail
20
21 #########################################################################
22 # Variables
23 #########################################################################
24 WORKSPACE=""
25 MIRROR_VER=stx-6.0
26 MIRROR_CONTAINER_IMG=infbuilder/inf-centos-mirror:2022.05-${MIRROR_VER}
27
28 #########################################################################
29 # Common Functions
30 #########################################################################
31
32 help_info () {
33 cat << ENDHELP
34 Usage:
35 $(basename $0) [-w WORKSPACE_DIR] [-h]
36 where:
37     -w WORKSPACE_DIR is the path for the builds
38     -h this help info
39 examples:
40 $0
41 $0 -w workspace_1234
42 ENDHELP
43 }
44
45 echo_step_start() {
46     [ -n "$1" ] && msg_step=$1
47     echo "#########################################################################################"
48     echo "## STEP START: ${msg_step}"
49     echo "#########################################################################################"
50 }
51
52 echo_step_end() {
53     [ -n "$1" ] && msg_step=$1
54     echo "#########################################################################################"
55     echo "## STEP END: ${msg_step}"
56     echo "#########################################################################################"
57     echo
58 }
59
60
61 while getopts "w:h" OPTION; do
62     case ${OPTION} in
63         w)
64             WORKSPACE=`readlink -f ${OPTARG}`
65             ;;
66         h)
67             help_info
68             exit
69             ;;
70     esac
71 done
72
73 get_mirror () {
74     msg_step="Get rpm mirror from dockerhub image"
75     echo_step_start
76
77     docker pull ${MIRROR_CONTAINER_IMG}
78     docker create -ti --name inf-centos-mirror ${MIRROR_CONTAINER_IMG} sh
79     docker cp inf-centos-mirror:/mirror_${MIRROR_VER} ${MIRROR_DIR}
80     docker rm inf-centos-mirror
81
82     echo_step_end
83 }
84
85
86 #########################################################################
87 # Main process
88 #########################################################################
89 msg_step="Prepare for jenkins build"
90
91 set -x
92 export BUILD_GROUP="jenkins"
93 export WGET_OPENDEV="wget --no-check-certificate"
94 export LOCALDISK="${WORKSPACE}/localdisk"
95 export MIRROR_DIR="${WORKSPACE}/mirror"
96
97 mkdir -p ${LOCALDISK}/loadbuild/mock-cache
98 mkdir -p ${LOCALDISK}/loadbuild/mock
99 mkdir -p ${LOCALDISK}/designer
100 mkdir -p ${LOCALDISK}/loadbuild
101
102 #sudo mkdir -p ${MIRROR_DIR}/CentOS
103 get_mirror
104
105 sudo chmod 775 ${LOCALDISK}/loadbuild/mock
106 sudo chown root:mock ${LOCALDISK}/loadbuild/mock
107 sudo chmod 775 ${LOCALDISK}/loadbuild/mock-cache
108 sudo chown root:mock ${LOCALDISK}/loadbuild/mock-cache
109
110 # Download required dependencies by mirror/build processes.
111 sudo yum install -y \
112     anaconda \
113     anaconda-runtime \
114     autoconf-archive \
115     autogen \
116     automake \
117     bc \
118     bind \
119     bind-utils \
120     bison \
121     cpanminus \
122     createrepo \
123     createrepo_c \
124     deltarpm \
125     expat-devel \
126     flex \
127     isomd5sum \
128     gcc \
129     gettext \
130     libguestfs-tools \
131     libtool \
132     libxml2 \
133     lighttpd \
134     lighttpd-fastcgi \
135     lighttpd-mod_geoip \
136     net-tools \
137     mkisofs \
138     mongodb \
139     mongodb-server \
140     pax \
141     perl-CPAN \
142     python-deltarpm \
143     python-pep8 \
144     python-pip \
145     python-psutil \
146     python2-psutil \
147     python36-psutil \
148     python36-requests \
149     python3-devel \
150     python-sphinx \
151     python-subunit \
152     python-virtualenv \
153     python-yaml \
154     python2-ruamel-yaml \
155     postgresql \
156     qemu-kvm \
157     quilt \
158     rpm-build \
159     rpm-sign \
160     rpm-python \
161     squashfs-tools \
162     sudo \
163     systemd \
164     syslinux \
165     udisks2 \
166     vim-enhanced \
167     wget
168
169 # clone the tools repo
170 cd ~
171 git clone https://opendev.org/starlingx/tools.git
172
173 # mock custumizations
174 # forcing chroots since a couple of packages naughtily insist on network access and
175 # we dont have nspawn and networks happy together.
176 sudo useradd -s /sbin/nologin -u 9001 -g 9001 mockbuild
177 sudo rmdir /var/lib/mock
178 sudo ln -s ${LOCALDISK}/loadbuild/mock /var/lib/mock
179 sudo rmdir /var/cache/mock
180 sudo ln -s ${LOCALDISK}/loadbuild/mock-cache /var/cache/mock
181 echo "config_opts['use_nspawn'] = False" | sudo tee -a /etc/mock/site-defaults.cfg
182 echo "config_opts['rpmbuild_networking'] = True" | sudo tee -a /etc/mock/site-defaults.cfg
183 echo | sudo tee -a /etc/mock/site-defaults.cfg
184
185 # cpan modules, installing with cpanminus to avoid stupid questions since cpan is whack
186 sudo cpanm --notest Fatal
187 sudo cpanm --notest XML::SAX
188 sudo cpanm --notest XML::SAX::Expat
189 sudo cpanm --notest XML::Parser
190 sudo cpanm --notest XML::Simple
191
192 # Install repo tool
193 sudo wget https://storage.googleapis.com/git-repo-downloads/repo -O /usr/local/bin/repo
194 sudo chmod a+x /usr/local/bin/repo
195
196 # installing go and setting paths
197 export GOPATH="/usr/local/go"
198 export PATH="${GOPATH}/bin:${PATH}"
199 sudo yum install -y golang
200 sudo mkdir -p ${GOPATH}/bin
201 curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sudo sh
202
203 # pip installs
204 # Install required python modules globally; versions are in the constraints file.
205 # Be careful not to replace modules provided by RPMs as it may break
206 # other system packages. Look for warnings similar to "Uninstalling a
207 # distutils installed project has been deprecated" from pip.
208 sudo pip install -c ~/tools/toCOPY/builder-constraints.txt \
209     testrepository \
210     fixtures \
211     pbr \
212     git-review \
213     python-subunit \
214     junitxml \
215     testtools
216
217 # Create a sane py27 virtualenv
218 virtualenv /opt/py27 && \
219     source /opt/py27/bin/activate && \
220     sudo pip install -c ~/tools/toCOPY/builder-opt-py27-constraints.txt \
221             tox \
222         && \
223     for prog in tox ; do \
224         ln -s /opt/py27/bin/$prog /usr/bin ; \
225     done
226
227 # Inherited  tools for mock stuff
228 # we at least need the mock_cache_unlock tool
229 # they install into /usr/bin
230 sudo cp -rf ~/tools/toCOPY/mock_overlay /opt/mock_overlay
231 cd /opt/mock_overlay
232 make
233 sudo make install
234
235 # This image requires a set of scripts and helpers
236 # for working correctly, in this section they are
237 # copied inside the image.
238 sudo cp ~/tools/toCOPY/finishSetup.sh /usr/local/bin
239 sudo cp ~/tools/toCOPY/populate_downloads.sh /usr/local/bin
240 sudo cp ~/tools/toCOPY/generate-local-repo.sh /usr/local/bin
241 sudo cp ~/tools/toCOPY/generate-centos-repo.sh /usr/local/bin
242 sudo cp ~/tools/toCOPY/lst_utils.sh /usr/local/bin
243
244 # centos locales are broken. this needs to be run after the last yum install/update
245 sudo localedef -i en_US -f UTF-8 en_US.UTF-8
246
247 # setup
248 sudo mkdir -p /www/run
249 sudo mkdir -p /www/logs
250 sudo mkdir -p /www/home
251 sudo mkdir -p /www/root/htdocs/localdisk
252 sudo ln -s ${LOCALDISK}/loadbuild /www/root/htdocs/localdisk/loadbuild
253 sudo ln -s ${MIRROR_DIR}/CentOS /www/root/htdocs/CentOS
254 sudo ln -s ${LOCALDISK}/designer /www/root/htdocs/localdisk/designer
255 sudo ln -s ${WORKSPACE} /www/root/htdocs/workspace
256
257 # lighthttpd setup
258 # chmod for /var/log/lighttpd fixes a centos issue
259 # in place sed for server root since it's expanded soon thereafter
260 #     echo "server.bind = \"localhost\"" >> /etc/lighttpd/lighttpd.conf && \
261 sudo mkdir -p  /var/log/lighttpd
262 sudo chmod a+rwx /var/log/lighttpd/
263 sudo sed -i -e 's%^var\.log_root.*$%var.log_root = "/www/logs"%g' \
264     -e 's%^var\.server_root.*$%var.server_root = "/www/root"%g' \
265     -e 's%^var\.home_dir.*$%var.home_dir = "/www/home"%g' \
266     -e 's%^var\.state_dir.*$%var.state_dir = "/www/run"%g' \
267     -e "s/server.port/#server.port/g" \
268     -e "s/server.use-ipv6/#server.use-ipv6/g" \
269     -e "s/server.username/#server.username/g" \
270     -e "s/server.groupname/#server.groupname/g" \
271     -e "s/server.bind/#server.bind/g" \
272     -e "s/server.document-root/#server.document-root/g" \
273     -e "s/server.dirlisting/#server.dirlisting/g" \
274     -e "s/dir-listing.activate/#dir-listing.activate/g" \
275     /etc/lighttpd/lighttpd.conf
276
277 echo "server.port = 8088" | sudo tee -a /etc/lighttpd/lighttpd.conf 
278 echo "server.use-ipv6 = \"disable\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
279 echo "server.username = \"$USER\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
280 echo "server.groupname = \"$BUILD_GROUP\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
281 echo "server.bind = \"localhost\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
282 echo "server.document-root   = \"/www/root/htdocs\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
283 echo "dir-listing.activate = \"enable\"" | sudo tee -a /etc/lighttpd/conf.d/dirlisting.conf
284
285 sudo /usr/sbin/lighttpd  -f /etc/lighttpd/lighttpd.conf
286
287 sudo chmod a+x /usr/local/bin/*
288
289 # Customizations for mirror creation
290 sudo rm -f /etc/yum.repos.d/*
291 sudo cp -f ~/tools/centos-mirror-tools/yum.repos.d/* /etc/yum.repos.d/
292 sudo cp -f ~/tools/centos-mirror-tools/rpm-gpg-keys/* /etc/pki/rpm-gpg/
293
294 # Import GPG keys
295 sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
296
297 # Try to continue a yum command even if a StarlingX repo is unavailable.
298 sudo yum-config-manager --setopt=StarlingX\*.skip_if_unavailable=1 --save
299
300 echo_step_end