3 # Copyright (C) 2022 Wind River Systems, Inc.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # Ensure we fail the job if any steps fail.
21 #########################################################################
23 #########################################################################
26 MIRROR_CONTAINER_IMG=infbuilder/inf-centos-mirror:2022.05-${MIRROR_VER}
28 SCRIPTS_NAME=$(basename $0)
30 #########################################################################
32 #########################################################################
37 ${SCRIPTS_NAME} [-w WORKSPACE_DIR] [-h]
39 -w WORKSPACE_DIR is the path for the builds
48 [ -n "$1" ] && msg_step=$1
49 echo "#########################################################################################"
50 echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}"
51 echo "#########################################################################################"
55 [ -n "$1" ] && msg_step=$1
56 echo "#########################################################################################"
57 echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}"
58 echo "#########################################################################################"
66 while getopts "w:h" OPTION; do
69 WORKSPACE=`readlink -f ${OPTARG}`
79 msg_step="Get rpm mirror from dockerhub image"
82 docker pull ${MIRROR_CONTAINER_IMG}
83 docker create -ti --name inf-centos-mirror ${MIRROR_CONTAINER_IMG} sh
84 docker cp inf-centos-mirror:/mirror_${MIRROR_VER} ${MIRROR_DIR}
85 docker rm inf-centos-mirror
91 #########################################################################
93 #########################################################################
94 msg_step="Prepare build directories"
98 export BUILD_GROUP="jenkins"
99 export WGET_OPENDEV="wget --no-check-certificate"
100 export LOCALDISK="${WORKSPACE}/localdisk"
101 export MIRROR_DIR="${WORKSPACE}/mirror"
102 export TOOLS_DIR="${WORKSPACE}/tools"
104 mkdir -p ${LOCALDISK}/loadbuild/mock-cache
105 mkdir -p ${LOCALDISK}/loadbuild/mock
106 mkdir -p ${LOCALDISK}/designer
107 mkdir -p ${LOCALDISK}/loadbuild
109 sudo chmod 775 ${LOCALDISK}/loadbuild/mock
110 sudo chown root:mock ${LOCALDISK}/loadbuild/mock
111 sudo chmod 775 ${LOCALDISK}/loadbuild/mock-cache
112 sudo chown root:mock ${LOCALDISK}/loadbuild/mock-cache
119 msg_step="Install/downlaod/config required dependencies by mirror/build processes."
122 echo_info "Install required packages"
123 sudo yum install -y \
166 python2-ruamel-yaml \
183 echo_info "Clone the tools repo"
185 git clone https://opendev.org/starlingx/tools.git
187 echo_info "mock custumizations"
188 # forcing chroots since a couple of packages naughtily insist on network access and
189 # we dont have nspawn and networks happy together.
191 sudo groupadd -g 9001 mockbuild
192 sudo useradd -s /sbin/nologin -u 9001 -g 9001 mockbuild
193 sudo rmdir /var/lib/mock
194 sudo ln -s ${LOCALDISK}/loadbuild/mock /var/lib/mock
195 sudo mv /var/cache/mock/* ${LOCALDISK}/loadbuild/mock-cache/
196 sudo rmdir /var/cache/mock
197 sudo ln -s ${LOCALDISK}/loadbuild/mock-cache /var/cache/mock
198 echo "config_opts['use_nspawn'] = False" | sudo tee -a /etc/mock/site-defaults.cfg
199 echo "config_opts['rpmbuild_networking'] = True" | sudo tee -a /etc/mock/site-defaults.cfg
200 echo | sudo tee -a /etc/mock/site-defaults.cfg
203 echo_info "Install required cpan modules"
204 # cpan modules, installing with cpanminus to avoid stupid questions since cpan is whack
205 sudo cpanm --notest Fatal
206 sudo cpanm --notest XML::SAX
207 sudo cpanm --notest XML::SAX::Expat
208 sudo cpanm --notest XML::Parser
209 sudo cpanm --notest XML::Simple
211 echo_info "Install repo tool"
212 sudo wget https://storage.googleapis.com/git-repo-downloads/repo -O /usr/local/bin/repo
213 sudo chmod a+x /usr/local/bin/repo
215 echo_info "Install go and setting paths"
216 export GOPATH="/usr/local/go"
217 export PATH="${GOPATH}/bin:${PATH}"
218 sudo yum install -y golang
219 sudo mkdir -p ${GOPATH}/bin
220 curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sudo -E sh
222 echo_info "Install pip packages"
223 # Install required python modules globally; versions are in the constraints file.
224 # Be careful not to replace modules provided by RPMs as it may break
225 # other system packages. Look for warnings similar to "Uninstalling a
226 # distutils installed project has been deprecated" from pip.
227 sudo pip install -c ${TOOLS_DIR}/toCOPY/builder-constraints.txt \
237 echo_info "Inherited tools for mock stuff"
238 # we at least need the mock_cache_unlock tool
239 # they install into /usr/bin
241 mkdir -p ${WORKSPACE}/opt
242 cp -rf ${TOOLS_DIR}/toCOPY/mock_overlay ${WORKSPACE}/opt/mock_overlay
243 cd ${WORKSPACE}/opt/mock_overlay
247 # This image requires a set of scripts and helpers
248 # for working correctly, in this section they are
249 # copied inside the image.
250 sudo cp ${TOOLS_DIR}/toCOPY/finishSetup.sh /usr/local/bin
251 sudo cp ${TOOLS_DIR}/toCOPY/populate_downloads.sh /usr/local/bin
252 sudo cp ${TOOLS_DIR}/toCOPY/generate-local-repo.sh /usr/local/bin
253 sudo cp ${TOOLS_DIR}/toCOPY/generate-centos-repo.sh /usr/local/bin
254 sudo cp ${TOOLS_DIR}/toCOPY/lst_utils.sh /usr/local/bin
256 # centos locales are broken. this needs to be run after the last yum install/update
257 sudo localedef -i en_US -f UTF-8 en_US.UTF-8
259 echo_info "Setup for lighttpd"
261 sudo chown ${USER}:${BUILD_GROUP} /www
265 mkdir -p /www/root/htdocs/localdisk
266 mkdir -p /www/root/htdocs/$(dirname ${WORKSPACE})
267 ln -s ${LOCALDISK}/loadbuild /www/root/htdocs/localdisk/loadbuild
268 ln -s ${LOCALDISK}/designer /www/root/htdocs/localdisk/designer
269 ln -s ${MIRROR_DIR}/CentOS /www/root/htdocs/CentOS
270 ln -s ${WORKSPACE} /www/root/htdocs/${WORKSPACE}
273 # chmod for /var/log/lighttpd fixes a centos issue
274 # in place sed for server root since it's expanded soon thereafter
275 # echo "server.bind = \"localhost\"" >> /etc/lighttpd/lighttpd.conf && \
276 sudo mkdir -p /var/log/lighttpd
277 sudo chmod a+rwx /var/log/lighttpd/
278 sudo sed -i -e 's%^var\.log_root.*$%var.log_root = "/www/logs"%g' \
279 -e 's%^var\.server_root.*$%var.server_root = "/www/root"%g' \
280 -e 's%^var\.home_dir.*$%var.home_dir = "/www/home"%g' \
281 -e 's%^var\.state_dir.*$%var.state_dir = "/www/run"%g' \
282 -e "s/server.port/#server.port/g" \
283 -e "s/server.use-ipv6/#server.use-ipv6/g" \
284 -e "s/server.username/#server.username/g" \
285 -e "s/server.groupname/#server.groupname/g" \
286 -e "s/server.bind/#server.bind/g" \
287 -e "s/server.document-root/#server.document-root/g" \
288 -e "s/server.dirlisting/#server.dirlisting/g" \
289 /etc/lighttpd/lighttpd.conf
291 echo "server.port = 8088" | sudo tee -a /etc/lighttpd/lighttpd.conf
292 echo "server.use-ipv6 = \"disable\"" | sudo tee -a /etc/lighttpd/lighttpd.conf
293 echo "server.username = \"$USER\"" | sudo tee -a /etc/lighttpd/lighttpd.conf
294 echo "server.groupname = \"$BUILD_GROUP\"" | sudo tee -a /etc/lighttpd/lighttpd.conf
295 echo "server.bind = \"localhost\"" | sudo tee -a /etc/lighttpd/lighttpd.conf
296 echo "server.document-root = \"/www/root/htdocs\"" | sudo tee -a /etc/lighttpd/lighttpd.conf
298 sudo sed -i "s/dir-listing.activate/#dir-listing.activate/g" \
299 /etc/lighttpd/conf.d/dirlisting.conf
301 echo "dir-listing.activate = \"enable\"" | sudo tee -a /etc/lighttpd/conf.d/dirlisting.conf
303 sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
305 sudo chmod a+x /usr/local/bin/*
307 # Customizations for mirror creation
308 sudo rm -f /etc/yum.repos.d/*
309 sudo cp -f ${TOOLS_DIR}/centos-mirror-tools/yum.repos.d/* /etc/yum.repos.d/
310 sudo cp -f ${TOOLS_DIR}/centos-mirror-tools/rpm-gpg-keys/* /etc/pki/rpm-gpg/
313 sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
315 # Try to continue a yum command even if a StarlingX repo is unavailable.
316 sudo yum-config-manager --setopt=StarlingX\*.skip_if_unavailable=1 --save
318 # Create a sane py27 virtualenv
319 virtualenv ${WORKSPACE}/opt/py27
320 source ${WORKSPACE}/opt/py27/bin/activate
321 pip install -c ${TOOLS_DIR}/toCOPY/builder-opt-py27-constraints.txt tox
322 sudo ln -s ${WORKSPACE}/opt/py27/bin/tox /usr/bin