build_inf_prepare_jenkins: fix for lighttpd config
[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 export TOOLS_DIR="${WORKSPACE}/tools"
97
98 mkdir -p ${LOCALDISK}/loadbuild/mock-cache
99 mkdir -p ${LOCALDISK}/loadbuild/mock
100 mkdir -p ${LOCALDISK}/designer
101 mkdir -p ${LOCALDISK}/loadbuild
102
103 #sudo mkdir -p ${MIRROR_DIR}/CentOS
104 get_mirror
105
106 sudo chmod 775 ${LOCALDISK}/loadbuild/mock
107 sudo chown root:mock ${LOCALDISK}/loadbuild/mock
108 sudo chmod 775 ${LOCALDISK}/loadbuild/mock-cache
109 sudo chown root:mock ${LOCALDISK}/loadbuild/mock-cache
110
111 # Download required dependencies by mirror/build processes.
112 sudo yum install -y \
113     anaconda \
114     anaconda-runtime \
115     autoconf-archive \
116     autogen \
117     automake \
118     bc \
119     bind \
120     bind-utils \
121     bison \
122     cpanminus \
123     createrepo \
124     createrepo_c \
125     deltarpm \
126     expat-devel \
127     flex \
128     isomd5sum \
129     gcc \
130     gettext \
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 ${WORKSPACE}
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 groupadd -g 9001 mockbuild
178 sudo useradd -s /sbin/nologin -u 9001 -g 9001 mockbuild
179 sudo rmdir /var/lib/mock
180 sudo ln -s ${LOCALDISK}/loadbuild/mock /var/lib/mock
181 sudo mv /var/cache/mock/* ${LOCALDISK}/loadbuild/mock-cache/
182 sudo rmdir /var/cache/mock
183 sudo ln -s ${LOCALDISK}/loadbuild/mock-cache /var/cache/mock
184 echo "config_opts['use_nspawn'] = False" | sudo tee -a /etc/mock/site-defaults.cfg
185 echo "config_opts['rpmbuild_networking'] = True" | sudo tee -a /etc/mock/site-defaults.cfg
186 echo | sudo tee -a /etc/mock/site-defaults.cfg
187
188 # cpan modules, installing with cpanminus to avoid stupid questions since cpan is whack
189 sudo cpanm --notest Fatal
190 sudo cpanm --notest XML::SAX
191 sudo cpanm --notest XML::SAX::Expat
192 sudo cpanm --notest XML::Parser
193 sudo cpanm --notest XML::Simple
194
195 # Install repo tool
196 sudo wget https://storage.googleapis.com/git-repo-downloads/repo -O /usr/local/bin/repo
197 sudo chmod a+x /usr/local/bin/repo
198
199 # installing go and setting paths
200 export GOPATH="/usr/local/go"
201 export PATH="${GOPATH}/bin:${PATH}"
202 sudo yum install -y golang
203 sudo mkdir -p ${GOPATH}/bin
204 curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sudo -E sh
205
206 # pip installs
207 # Install required python modules globally; versions are in the constraints file.
208 # Be careful not to replace modules provided by RPMs as it may break
209 # other system packages. Look for warnings similar to "Uninstalling a
210 # distutils installed project has been deprecated" from pip.
211 sudo pip install -c ${TOOLS_DIR}/toCOPY/builder-constraints.txt \
212     testrepository \
213     fixtures \
214     pbr \
215     git-review \
216     python-subunit \
217     junitxml \
218     testtools
219
220
221
222 # Inherited  tools for mock stuff
223 # we at least need the mock_cache_unlock tool
224 # they install into /usr/bin
225 mkdir -p ${WORKSPACE}/opt
226 cp -rf ${TOOLS_DIR}/toCOPY/mock_overlay ${WORKSPACE}/opt/mock_overlay
227 cd ${WORKSPACE}/opt/mock_overlay
228 make
229 sudo make install
230
231 # This image requires a set of scripts and helpers
232 # for working correctly, in this section they are
233 # copied inside the image.
234 sudo cp ${TOOLS_DIR}/toCOPY/finishSetup.sh /usr/local/bin
235 sudo cp ${TOOLS_DIR}/toCOPY/populate_downloads.sh /usr/local/bin
236 sudo cp ${TOOLS_DIR}/toCOPY/generate-local-repo.sh /usr/local/bin
237 sudo cp ${TOOLS_DIR}/toCOPY/generate-centos-repo.sh /usr/local/bin
238 sudo cp ${TOOLS_DIR}/toCOPY/lst_utils.sh /usr/local/bin
239
240 # centos locales are broken. this needs to be run after the last yum install/update
241 sudo localedef -i en_US -f UTF-8 en_US.UTF-8
242
243 # setup
244 sudo mkdir -p /www/run
245 sudo mkdir -p /www/logs
246 sudo mkdir -p /www/home
247 sudo mkdir -p /www/root/htdocs/localdisk
248 sudo mkdir -p /www/root/htdocs/$(dirname ${WORKSPACE})
249 sudo ln -s ${LOCALDISK}/loadbuild /www/root/htdocs/localdisk/loadbuild
250 sudo ln -s ${LOCALDISK}/designer /www/root/htdocs/localdisk/designer
251 sudo ln -s ${MIRROR_DIR}/CentOS /www/root/htdocs/CentOS
252 sudo ln -s ${WORKSPACE} /www/root/htdocs/${WORKSPACE}
253
254 # lighthttpd setup
255 # chmod for /var/log/lighttpd fixes a centos issue
256 # in place sed for server root since it's expanded soon thereafter
257 #     echo "server.bind = \"localhost\"" >> /etc/lighttpd/lighttpd.conf && \
258 sudo mkdir -p  /var/log/lighttpd
259 sudo chmod a+rwx /var/log/lighttpd/
260 sudo sed -i -e 's%^var\.log_root.*$%var.log_root = "/www/logs"%g' \
261     -e 's%^var\.server_root.*$%var.server_root = "/www/root"%g' \
262     -e 's%^var\.home_dir.*$%var.home_dir = "/www/home"%g' \
263     -e 's%^var\.state_dir.*$%var.state_dir = "/www/run"%g' \
264     -e "s/server.port/#server.port/g" \
265     -e "s/server.use-ipv6/#server.use-ipv6/g" \
266     -e "s/server.username/#server.username/g" \
267     -e "s/server.groupname/#server.groupname/g" \
268     -e "s/server.bind/#server.bind/g" \
269     -e "s/server.document-root/#server.document-root/g" \
270     -e "s/server.dirlisting/#server.dirlisting/g" \
271     /etc/lighttpd/lighttpd.conf
272
273 echo "server.port = 8088" | sudo tee -a /etc/lighttpd/lighttpd.conf 
274 echo "server.use-ipv6 = \"disable\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
275 echo "server.username = \"$USER\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
276 echo "server.groupname = \"$BUILD_GROUP\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
277 echo "server.bind = \"localhost\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
278 echo "server.document-root   = \"/www/root/htdocs\"" | sudo tee -a /etc/lighttpd/lighttpd.conf 
279
280 sudo sed -i "s/dir-listing.activate/#dir-listing.activate/g" \
281     /etc/lighttpd/conf.d/dirlisting.conf
282
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 ps -ef|grep lighttpd || true
288 curl 127.0.0.1:8088${WORKSPACE} || true
289
290 sudo chmod a+x /usr/local/bin/*
291
292 # Customizations for mirror creation
293 sudo rm -f /etc/yum.repos.d/*
294 sudo cp -f ${TOOLS_DIR}/centos-mirror-tools/yum.repos.d/* /etc/yum.repos.d/
295 sudo cp -f ${TOOLS_DIR}/centos-mirror-tools/rpm-gpg-keys/* /etc/pki/rpm-gpg/
296
297 # Import GPG keys
298 sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
299
300 # Try to continue a yum command even if a StarlingX repo is unavailable.
301 sudo yum-config-manager --setopt=StarlingX\*.skip_if_unavailable=1 --save
302
303 # Create a sane py27 virtualenv
304 virtualenv ${WORKSPACE}/opt/py27
305 source ${WORKSPACE}/opt/py27/bin/activate
306 pip install -c ${TOOLS_DIR}/toCOPY/builder-opt-py27-constraints.txt tox
307 sudo ln -s ${WORKSPACE}/opt/py27/bin/tox /usr/bin
308
309 echo_step_end