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