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