-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathbuild_utils.sh
More file actions
executable file
·1862 lines (1650 loc) · 56.7 KB
/
build_utils.sh
File metadata and controls
executable file
·1862 lines (1650 loc) · 56.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# vim: ts=4 sw=4 expandtab
set -ex
function create_venv_dir() {
local venv_dir
venv_dir=$(mktemp -td venv.XXXXXXXXXX)
trap "rm -rf ${venv_dir}" EXIT
echo "${venv_dir}"
}
function release_from_version() {
local ver=$1
case $ver in
20.*)
rel="tentacle"
;;
19.*)
rel="squid"
;;
18.*)
rel="reef"
;;
17.*)
rel="quincy"
;;
16.*)
rel="pacific"
;;
15.*)
rel="octopus"
;;
14.*)
rel="nautilus"
;;
13.*)
rel="mimic"
;;
12.*)
rel="luminous"
;;
11.*)
rel="kraken"
;;
10.*)
rel="jewel"
;;
9.*)
rel="infernalis"
;;
0.94.*)
rel="hammer"
;;
0.87.*)
rel="giant"
;;
0.80.*)
rel="firefly"
;;
0.72.*)
rel="emperor"
;;
0.67.*)
rel="dumpling"
;;
*)
rel="unknown"
echo "ERROR: Unknown release for version '$ver'" > /dev/stderr
echo $rel
exit 1
;;
esac
echo $rel
}
branch_slash_filter() {
# The build system relies on an HTTP binary store that uses branches/refs
# as URL parts. A literal extra slash in the branch name is considered
# illegal, so this function performs a check *and* prunes the common
# `origin/branch-name` scenario (which is OK to have).
RAW_BRANCH=$1
branch_slashes=$(grep -o "/" <<< ${RAW_BRANCH} | wc -l)
FILTERED_BRANCH=`echo ${RAW_BRANCH} | rev | cut -d '/' -f 1 | rev`
# Prevent building branches that have slashes in their name
if [ "$((branch_slashes))" -gt 1 ] ; then
echo "Will refuse to build branch: ${RAW_BRANCH}"
echo "Invalid branch name (contains slashes): ${FILTERED_BRANCH}"
exit 1
fi
echo $FILTERED_BRANCH
}
pip_download() {
local venv=$1
shift
local package=$1
shift
local options=$@
if ! $venv/pip download $options --dest="$PIP_SDIST_INDEX" $package; then
# pip <8.0.0 does not have "download" command
$venv/pip install $options \
--upgrade --exists-action=i --cache-dir="$PIP_SDIST_INDEX" \
$package
fi
}
create_virtualenv () {
local path=$1
if [ -d $path ]; then
echo "Will reuse existing virtual env: $path"
else
if command -v python3 > /dev/null; then
python3 -m venv $path
elif command -v python2.7 > /dev/null; then
virtualenv -p python2.7 $path
else
virtualenv -p python $path
fi
fi
}
install_python_packages_no_binary () {
local venv_dir=$1
shift
local venv="$venv_dir/bin"
# Use this function to create a virtualenv and install python packages
# without compiling (or using wheels). Pass a list of package names. If
# the virtualenv exists it will get re-used since this function can be used
# along with install_python_packages
#
# Usage (with pip==24.0 [the default]):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages_no_binary $TEMPVENV "to_install[@]"
#
# Usage (with pip<X.X.X [can also do ==X.X.X or !=X.X.X]):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages_no_binary $TEMPVENV "to_install[@]" "pip<X.X.X"
#
# Usage (with latest pip):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages_no_binary $TEMPVENV "to_install[@]" latest
create_virtualenv $venv_dir
# Define and ensure the PIP cache
PIP_SDIST_INDEX="$HOME/.cache/pip"
mkdir -p $PIP_SDIST_INDEX
if [ "$2" == "latest" ]; then
echo "Ensuring latest pip is installed"
$venv/pip install -U pip
elif [[ -n $2 && "$2" != "latest" ]]; then
echo "Installing $2"
$venv/pip install "$2"
else
# This is the default for most jobs.
# See ff01d2c5 and fea10f52
echo "Installing pip 24.0"
$venv/pip install "pip==24.0"
fi
echo "Ensuring latest wheel is installed"
$venv/pip install -U wheel
echo "Updating setuptools"
pip_download $VENV setuptools
pkgs=("${!1}")
for package in "${pkgs[@]}"; do
echo $package
# download packages to the local pip cache
pip_download $VENV $package --no-binary=:all:
# install packages from the local pip cache, ignoring pypi
$venv/pip install --no-binary=:all: --upgrade --exists-action=i --find-links="file://$PIP_SDIST_INDEX" --no-index $package
done
}
install_python_packages () {
local venv_dir=$1
shift
local venv="$venv_dir/bin"
# Use this function to create a virtualenv and install
# python packages. Pass a list of package names.
#
# Usage (with pip 24.0 [the default]):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages $TEMPVENV "to_install[@]"
#
# Usage (with pip<X.X.X [can also do ==X.X.X or !=X.X.X]):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages_no_binary $TEMPVENV "to_install[@]" "pip<X.X.X"
#
# Usage (with latest pip):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages $TEMPVENV "to_install[@]" latest
create_virtualenv $venv_dir
# Define and ensure the PIP cache
PIP_SDIST_INDEX="$HOME/.cache/pip"
mkdir -p $PIP_SDIST_INDEX
# Avoid UnicodeErrors when installing packages.
# See https://github.com/ceph/ceph/pull/42811
export LC_ALL=en_US.UTF-8
if [ "$2" == "latest" ]; then
echo "Ensuring latest pip is installed"
$venv/pip install -U pip
elif [[ -n $2 && "$2" != "latest" ]]; then
echo "Installing $2"
$venv/pip install "$2"
else
# This is the default for most jobs.
# See ff01d2c5 and fea10f52
echo "Installing pip 24.0"
$venv/pip install "pip==24.0"
fi
echo "Ensuring latest wheel is installed"
$venv/pip install -U wheel
echo "Updating setuptools"
pip_download $venv setuptools
pkgs=("${!1}")
for package in "${pkgs[@]}"; do
echo $package
# download packages to the local pip cache
pip_download $venv $package
# install packages from the local pip cache, ignoring pypi
$venv/pip install --upgrade --exists-action=i --find-links="file://$PIP_SDIST_INDEX" --no-index $package
done
# See https://tracker.ceph.com/issues/59652
echo "Pinning urllib3 and requests"
$venv/pip install "urllib3<2.0.0"
$venv/pip install "requests<2.30.0"
}
make_chacractl_config () {
# create the .chacractl config file
if [ -z "$1" ] # Is parameter #1 zero length?
then
url=$CHACRACTL_URL
else
url=$1
fi
cat > $HOME/.chacractl << EOF
url = "$url"
user = "$CHACRACTL_USER"
key = "$CHACRACTL_KEY"
ssl_verify = True
EOF
}
get_rpm_dist() {
# creates a DISTRO_VERSION and DISTRO global variable for
# use in constructing chacra urls for rpm distros
source /etc/os-release
RELEASE=$VERSION_ID
DISTRO=$ID
case $ID in
rhel)
DIST=rhel$RELEASE
;;
centos)
DIST=el$RELEASE
;;
fedora)
DIST=fc$RELEASE
;;
sles)
DIST=sles$RELEASE
;;
opensuse-leap)
DIST=opensuse$RELEASE
DISTRO=opensuse
;;
*)
DIST=unknown
DISTRO=unknown
;;
esac
DISTRO_VERSION=$RELEASE
echo $DIST
}
check_binary_existence () {
local venv=$1
shift
local url=$1
shift
# we have to use ! here so thet -e will ignore the error code for the command
# because of this, the exit code is also reversed
! $venv/chacractl exists binaries/${url} ; exists=$?
# if the binary already exists in chacra, do not rebuild
if [ $exists -eq 1 ] && [ "$FORCE" = false ] ; then
echo "The endpoint at ${chacra_endpoint} already exists and FORCE was not set, Exiting..."
exit 0
fi
}
submit_build_status() {
# A helper script to post (create) the status of a build in shaman
# 'state' can be either 'failed' or 'started'
# 'project' is used to post to the right url in shaman
http_method=$1
state=$2
project=$3
distro=$4
distro_version=$5
distro_arch=$6
cat > $WORKSPACE/build_status.json << EOF
{
"extra":{
"version":"$vers",
"root_build_cause":"$ROOT_BUILD_CAUSE",
"node_name":"$NODE_NAME",
"job_name":"$JOB_NAME",
"build_user":"$BUILD_USER"
},
"url":"$BUILD_URL",
"log_url":"$BUILD_URL/consoleFull",
"status":"$state",
"distro":"$distro",
"distro_version":"$distro_version",
"distro_arch":"$distro_arch",
"ref":"$BRANCH",
"sha1":"$SHA1",
"flavor":"$FLAVOR"
}
EOF
# these variables are saved in this jenkins
# properties file so that other scripts
# in the same job can inject them
cat > $WORKSPACE/build_info << EOF
NORMAL_DISTRO=$distro
NORMAL_DISTRO_VERSION=$distro_version
NORMAL_ARCH=$distro_arch
SHA1=$SHA1
EOF
SHAMAN_URL="https://shaman.ceph.com/api/builds/$project/"
# post the build information as JSON to shaman
curl -X $http_method -H "Content-Type:application/json" --data "@$WORKSPACE/build_status.json" -u $SHAMAN_API_USER:$SHAMAN_API_KEY ${SHAMAN_URL}
}
update_build_status() {
# A proxy script to PUT (create or update) the status of a build
# in shaman for a normal/initial build
# 'state' can be either of: 'started', 'completed', or 'failed'
# 'project' is used to post to the right url in shaman
# required
state=$1
project=$2
# optional
distro=$3
distro_version=$4
distro_arch=$5
submit_build_status "POST" $state $project $distro $distro_version $distro_arch
}
failed_build_status() {
# A helper script to POST (create) the status of a build in shaman as
# a failed build. The only required argument is the 'project', so that it
# can be used post to the right url in shaman
# required
project=$1
state="failed"
# optional
distro=$2
distro_version=$3
distro_arch=$4
submit_build_status "POST" $state $project $distro $distro_version $distro_arch
}
get_distro_and_target() {
# Get distro from DIST for chacra uploads
DISTRO=""
case $DIST in
bookworm*)
DIST=bookworm
DISTRO="debian"
;;
bullseye*)
DIST=bullseye
DISTRO="debian"
;;
buster*)
DIST=buster
DISTRO="debian"
;;
stretch*)
DIST=stretch
DISTRO="debian"
;;
jessie*)
DIST=jessie
DISTRO="debian"
;;
wheezy*)
DIST=wheezy
DISTRO="debian"
;;
noble*)
DIST=noble
DISTRO="ubuntu"
;;
jammy*)
DIST=jammy
DISTRO="ubuntu"
;;
focal*)
DIST=focal
DISTRO="ubuntu"
;;
bionic*)
DIST=bionic
DISTRO="ubuntu"
;;
xenial*)
DIST=xenial
DISTRO="ubuntu"
;;
precise*)
DIST=precise
DISTRO="ubuntu"
;;
trusty*)
DIST=trusty
DISTRO="ubuntu"
;;
centos*)
source /etc/os-release
if [ $VERSION -ge 8 ]; then
MOCK_TARGET="centos-stream+epel"
else
MOCK_TARGET="epel"
fi
DISTRO="centos"
;;
rhel*)
DISTRO="rhel"
MOCK_TARGET="epel"
;;
fedora*)
DISTRO="fedora"
MOCK_TARGET="fedora"
;;
*)
DISTRO="unknown"
;;
esac
}
setup_updates_repo() {
local hookdir=$1
if [[ $NORMAL_DISTRO != ubuntu ]]; then
return
fi
if [[ "$ARCH" == "x86_64" ]]; then
cat > $hookdir/D04install-updates-repo <<EOF
echo "deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu/ $DIST-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu/ $DIST-backports main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb [arch=amd64] http://security.ubuntu.com/ubuntu $DIST-security main restricted universe multiverse" >> /etc/apt/sources.list
env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true
env DEBIAN_FRONTEND=noninteractive apt-get install -y gnupg
EOF
elif [[ "$ARCH" == "arm64" ]]; then
cat > $hookdir/D04install-updates-repo <<EOF
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ $DIST-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ $DIST-backports main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ $DIST-security main restricted universe multiverse" >> /etc/apt/sources.list
env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true
env DEBIAN_FRONTEND=noninteractive apt-get install -y gnupg
EOF
fi
chmod +x $hookdir/D04install-updates-repo
}
recreate_hookdir() {
local hookdir
if use_ppa; then
hookdir=$HOME/.pbuilder/hook.d
else
hookdir=$HOME/.pbuilder/hook-old-gcc.d
fi
rm -rf $hookdir
mkdir -p $hookdir
echo $hookdir
}
setup_pbuilder() {
local use_gcc=$1
# This function will set the tgz images needed for pbuilder on a given host. It has
# some hard-coded values like `/srv/debian-base` because it gets built every
# time this file is executed - completely ephemeral. If a Debian host will use
# pbuilder, then it will need this. Since it is not idempotent it makes
# everything a bit slower. ## FIXME ##
basedir="/srv/debian-base"
# Ensure that the basedir directory exists
sudo mkdir -p "$basedir"
# This used to live in a *file* on /srv/ceph-build as
# /srv/ceph-build/update_pbuilder.sh Now it lives here because it doesn't make
# sense to have a file that lives in /srv/ that we then concatenate to get its
# contents. what.
# By using $DIST we are narrowing down to updating only the distro image we
# need, unlike before where we updated everything on every server on every
# build.
os="debian"
[ "$DIST" = "precise" ] && os="ubuntu"
[ "$DIST" = "saucy" ] && os="ubuntu"
[ "$DIST" = "trusty" ] && os="ubuntu"
[ "$DIST" = "xenial" ] && os="ubuntu"
[ "$DIST" = "bionic" ] && os="ubuntu"
[ "$DIST" = "focal" ] && os="ubuntu"
[ "$DIST" = "jammy" ] && os="ubuntu"
[ "$DIST" = "noble" ] && os="ubuntu"
if [ $os = "debian" ]; then
# this mirror seems to have been decommissioned.
# mirror="http://www.gtlib.gatech.edu/pub/debian"
mirror="http://ftp.us.debian.org/debian"
if [ "$DIST" = "jessie" ]; then
# despite the fact we're building for jessie, pbuilder was failing due to
# missing wheezy key 8B48AD6246925553. Pointing pbuilder at the archive
# keyring takes care of it.
debootstrapopts='DEBOOTSTRAPOPTS=( "--keyring" "/usr/share/keyrings/debian-archive-keyring.gpg" )'
else
# this assumes that newer Debian releases are being added to
# /etc/apt/trusted.gpg that is also the default location for Ubuntu trusted
# keys. The Jenkins builder should ensure that the needed keys are added accordingly
# to this location.
debootstrapopts='DEBOOTSTRAPOPTS=( "--keyring" "/etc/apt/trusted.gpg" )'
fi
components='COMPONENTS="main contrib"'
elif [ "$ARCH" = "arm64" ]; then
mirror="http://ports.ubuntu.com/ubuntu-ports"
debootstrapopts=""
components='COMPONENTS="main universe"'
else
mirror="http://us.archive.ubuntu.com/ubuntu"
debootstrapopts=""
components='COMPONENTS="main universe"'
fi
# ensure that the tgz is valid, otherwise remove it so that it can be recreated
# again
pbuild_tar="$basedir/$DIST.tgz"
is_not_tar=`python3 -c $'try: import tarfile;print(int(not int(tarfile.is_tarfile(\"$pbuild_tar\"))))\nexcept IOError: print(1)'`
file_size_kb=`test -f $pbuild_tar && du -k "$pbuild_tar" | cut -f1 || echo 0`
if [ "$is_not_tar" = "1" ]; then
sudo rm -f "$pbuild_tar"
fi
if [ $file_size_kb -lt 1 ]; then
sudo rm -f "$pbuild_tar"
fi
# Ordinarily pbuilder only pulls packages from "main". ceph depends on
# packages like python-virtualenv which are in "universe". We have to configure
# pbuilder to look in "universe". Otherwise the build would fail with a message similar
# to:
# The following packages have unmet dependencies:
# pbuilder-satisfydepends-dummy : Depends: python-virtualenv which is a virtual package.
# Depends: xmlstarlet which is a virtual package.
# Unable to resolve dependencies! Giving up...
echo "$components" > ~/.pbuilderrc
echo "$debootstrapopts" >> ~/.pbuilderrc
# gcc 7.4.0 will come from bionic-updates, those need to be added as well
if [ $DIST = "bionic" ]; then
other_mirror="OTHERMIRROR=\"deb $mirror $DIST-updates main universe\""
echo "$other_mirror" >> ~/.pbuilderrc
fi
#in case it needs to update/add repo, the following packages should installed.
extrapackages="software-properties-common curl"
echo "EXTRAPACKAGES=\"${extrapackages}\"" >> ~/.pbuilderrc
local opts
opts+=" --basetgz $basedir/$DIST.tgz"
opts+=" --distribution $DIST"
if [ -n "$mirror" ] ; then
opts+=" --mirror $mirror"
fi
if [ -n "$use_gcc" ]; then
# Newer pbuilder versions set $HOME to /nonexistent which breaks all kinds of
# things that rely on a proper (writable) path. Setting this to the system user's $HOME is not enough
# because of how pbuilder uses a chroot environment for builds, using a temporary directory here ensures
# that writes will be successful.
echo "BUILD_HOME=`mktemp -d`" >> ~/.pbuilderrc
# Some Ceph components will want to use cached wheels that may have older versions of buggy executables
# like: /usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl which causes errors that are already fixed
# in newer versions. This ticket solves the specific issue in 8.1.1 (which vendors urllib3):
# https://github.com/shazow/urllib3/issues/567
echo "USENETWORK=yes" >> ~/.pbuilderrc
local hookdir
hookdir=$(recreate_hookdir)
if [[ "$NORMAL_DISTRO" = ubuntu ]]; then
setup_updates_repo $hookdir
setup_pbuilder_for_ppa $hookdir
fi
echo "HOOKDIR=$hookdir" >> ~/.pbuilderrc
fi
# As of this writing, Ceph needs about 100GB of space to build the binaries.
# If the Jenkins builder has 150% that amount in RAM available, let's build
# on a tmpfs
available_mem=$(cat /proc/meminfo | grep MemAvailable | awk '{ print $2 }')
if [ $available_mem -gt 157286400 ]; then
echo "Will be building in a tmpfs"
sudo mkdir -p /var/cache/pbuilder/build
sudo mount -t tmpfs -o size=150G tmpfs /var/cache/pbuilder/build
echo "APTCACHEHARDLINK=no" >> ~/.pbuilderrc
PBUILDER_IN_TMPFS=true
else
echo "$available_mem kB is not enough space to build Ceph in a tmpfs. Will use the Jenkins workspace instead"
PBUILDER_IN_TMPFS=false
fi
sudo cp ~/.pbuilderrc /root/.pbuilderrc
if [ -e $basedir/$DIST.tgz ]; then
echo updating $DIST base.tgz
sudo pbuilder update $opts \
--override-config
else
echo building $DIST base.tgz
sudo pbuilder create $opts
fi
}
use_ppa() {
# only use ppa on focal for reef+
case $vers in
15.*) # o
use_ppa=false;;
16.*) # p
use_ppa=false;;
17.2*) # q
use_ppa=false;;
*)
case $DIST in
focal)
use_ppa=true;;
*)
use_ppa=false;;
esac
;;
esac
$use_ppa
}
setup_gcc_hook() {
new=$1
cat <<EOF
old=\$(gcc -dumpversion)
if dpkg --compare-versions \$old eq $new; then
return
fi
case \$old in
4*)
old=4.8;;
5*)
old=5;;
7*)
old=7;;
8*)
old=8;;
esac
update-alternatives --remove-all gcc
update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-${new} 20 \
--slave /usr/bin/g++ g++ /usr/bin/g++-${new}
update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-\${old} 10 \
--slave /usr/bin/g++ g++ /usr/bin/g++-\${old}
update-alternatives --auto gcc
# cmake uses the latter by default
ln -nsf /usr/bin/gcc /usr/bin/\$(arch)-linux-gnu-gcc
ln -nsf /usr/bin/g++ /usr/bin/\$(arch)-linux-gnu-g++
EOF
}
setup_pbuilder_for_new_gcc() {
# point gcc,g++ to the newly installed ones
local hookdir=$1
shift
local version=$1
shift
# need to add the test repo and install new gcc after
# `pbuilder create|update` finishes apt-get instead of using "extrapackages".
# otherwise installing gcc will leave us a half-configured build-essential
# and gcc, and `pbuilder` command will fail. because the `build-essential`
# depends on a certain version of gcc which is upgraded already by the one
# in test repo.
if [ "$ARCH" = "arm64" ]; then
cat > $hookdir/D05install-new-gcc <<EOF
echo "deb [lang=none] http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $DIST main" >> \
/etc/apt/sources.list.d/ubuntu-toolchain-r.list
echo "deb [lang=none] http://ports.ubuntu.com/ubuntu-ports $DIST-updates main" >> \
/etc/apt/sources.list.d/ubuntu-toolchain-r.list
EOF
elif [ "$ARCH" = "x86_64" ]; then
cat > $hookdir/D05install-new-gcc <<EOF
echo "deb [lang=none] http://security.ubuntu.com/ubuntu $DIST-security main" >> \
/etc/apt/sources.list.d/ubuntu-toolchain-r.list
echo "deb [lang=none] http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $DIST main" >> \
/etc/apt/sources.list.d/ubuntu-toolchain-r.list
echo "deb [arch=amd64 lang=none] http://mirror.nullivex.com/ppa/ubuntu-toolchain-r-test $DIST main" >> \
/etc/apt/sources.list.d/ubuntu-toolchain-r.list
echo "deb [arch=amd64 lang=none] http://deb.rug.nl/ppa/mirror/ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $DIST main" >> \
/etc/apt/sources.list.d/ubuntu-toolchain-r.list
EOF
else
echo "unsupported arch: $ARCH"
exit 1
fi
cat >> $hookdir/D05install-new-gcc <<EOF
env DEBIAN_FRONTEND=noninteractive apt-get install -y gnupg
cat << ENDOFKEY | apt-key add -
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SKS 1.1.6
Comment: Hostname: keyserver.ubuntu.com
mI0ESuBvRwEEAMi4cDba7xlKaaoXjO1n1HX8RKrkW+HEIl79nSOSJyvzysajs7zUow/OzCQp
9NswqrDmNuH1+lPTTRNAGtK8r2ouq2rnXT1mTl23dpgHZ9spseR73s4ZBGw/ag4bpU5dNUSt
vfmHhIjVCuiSpNn7cyy1JSSvSs3N2mxteKjXLBf7ABEBAAG0GkxhdW5jaHBhZCBUb29sY2hh
aW4gYnVpbGRziLYEEwECACAFAkrgb0cCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRAe
k3eiup7yfzGKA/4xzUqNACSlB+k+DxFFHqkwKa/ziFiAlkLQyyhm+iqz80htRZr7Ls/ZRYZl
0aSU56/hLe0V+TviJ1s8qdN2lamkKdXIAFfavA04nOnTzyIBJ82EAUT3Nh45skMxo4z4iZMN
msyaQpNl/m/lNtOLhR64v5ZybofB2EWkMxUzX8D/FQ==
=LcUQ
-----END PGP PUBLIC KEY BLOCK-----
ENDOFKEY
# import PPA's signing key into APT's keyring
env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true
env DEBIAN_FRONTEND=noninteractive apt-get install -y g++-$version
EOF
chmod +x $hookdir/D05install-new-gcc
setup_gcc_hook $version > $hookdir/D10update-gcc-alternatives
chmod +x $hookdir/D10update-gcc-alternatives
}
setup_pbuilder_for_old_gcc() {
# point gcc,g++ to the ones shipped by distro
local hookdir=$1
case $DIST in
trusty)
old=4.8;;
xenial)
old=5;;
bionic)
old=8;;
focal)
old=9;;
jammy)
old=11;;
noble)
old=14;;
esac
# make sure the requested version is installed. this isn't the case by default on noble
cat > $hookdir/D05install-old-gcc <<EOF
env DEBIAN_FRONTEND=noninteractive apt-get install -y g++-$old
EOF
chmod +x $hookdir/D05install-old-gcc
setup_gcc_hook $old > $hookdir/D10update-gcc-alternatives
chmod +x $hookdir/D10update-gcc-alternatives
}
setup_pbuilder_for_ppa() {
local hookdir=$1
if use_ppa; then
local gcc_ver=11
setup_pbuilder_for_new_gcc $hookdir $gcc_ver
else
setup_pbuilder_for_old_gcc $hookdir
fi
}
get_bptag() {
dist=$1
[ "$dist" = "sid" ] && dver=""
[ "$dist" = "bookworm" ] && dver="~bpo12+1"
[ "$dist" = "bullseye" ] && dver="~bpo11+1"
[ "$dist" = "buster" ] && dver="~bpo10+1"
[ "$dist" = "stretch" ] && dver="~bpo90+1"
[ "$dist" = "jessie" ] && dver="~bpo80+1"
[ "$dist" = "wheezy" ] && dver="~bpo70+1"
[ "$dist" = "squeeze" ] && dver="~bpo60+1"
[ "$dist" = "lenny" ] && dver="~bpo50+1"
[ "$dist" = "noble" ] && dver="$dist"
[ "$dist" = "jammy" ] && dver="$dist"
[ "$dist" = "focal" ] && dver="$dist"
[ "$dist" = "bionic" ] && dver="$dist"
[ "$dist" = "xenial" ] && dver="$dist"
[ "$dist" = "trusty" ] && dver="$dist"
[ "$dist" = "saucy" ] && dver="$dist"
[ "$dist" = "precise" ] && dver="$dist"
[ "$dist" = "oneiric" ] && dver="$dist"
[ "$dist" = "natty" ] && dver="$dist"
[ "$dist" = "maverick" ] && dver="$dist"
[ "$dist" = "lucid" ] && dver="$dist"
[ "$dist" = "karmic" ] && dver="$dist"
echo $dver
}
gen_debian_version() {
local raw=$1
local dist=$2
local bptag
bptag=$(get_bptag $dist)
echo "${raw}${bptag}"
}
# Flavor Builds support
# - CEPH_EXTRA_RPMBUILD_ARGS is consumed by build_rpms()
# - CEPH_EXTRA_CMAKE_ARGS is consumed by debian/rules and ceph.spec directly
# - PROFILES is consumed by build_debs()
ceph_build_args_from_flavor() {
local flavor=$1
shift
# shellcheck disable=SC2034
CEPH_EXTRA_RPMBUILD_ARGS="--with tcmalloc"
CEPH_EXTRA_CMAKE_ARGS+=" -DALLOCATOR=tcmalloc"
# build boost with valgrind=on for https://tracker.ceph.com/issues/56500
CEPH_EXTRA_CMAKE_ARGS+=" -DWITH_SYSTEM_BOOST=OFF -DWITH_BOOST_VALGRIND=ON"
DEB_BUILD_PROFILES=""
if [[ "$flavor" == "debug" ]]; then
CEPH_EXTRA_CMAKE_ARGS+=" -DCMAKE_BUILD_TYPE=Debug -DWITH_CEPH_DEBUG_MUTEX=ON"
fi
if [[ "$flavor" != "default" && "$flavor" != "debug" ]]; then
echo "unknown FLAVOR: ${FLAVOR}" >&2
exit 1
fi
write_dist_files()
{
cat > dist/sha1 << EOF
SHA1=${GIT_COMMIT}
EOF
cat > dist/branch << EOF
BRANCH=${BRANCH}
EOF
# - CEPH_EXTRA_RPMBUILD_ARGS are consumed by build_rpm before
# the switch to cmake;
# - CEPH_EXTRA_CMAKE_ARGS is for after cmake
# - DEB_BUILD_PROFILES is consumed by build_debs()
cat > dist/other_envvars << EOF
CEPH_EXTRA_RPMBUILD_ARGS=${CEPH_EXTRA_RPMBUILD_ARGS}
CEPH_EXTRA_CMAKE_ARGS=${CEPH_EXTRA_CMAKE_ARGS}
DEB_BUILD_PROFILES=${DEB_BUILD_PROFILES}
EOF
}
build_debs() {
local venv=$1
shift
local vers=$1
shift
local debian_version=$1
shift
# create a release directory for ceph-build tools
mkdir -p release
cp -a dist release/${vers}
echo $DIST > release/${vers}/debian_dists
echo "${debian_version}" > release/${vers}/debian_version
cd release/$vers
# unpack sources
dpkg-source -x ceph_${vers}-1.dsc
( cd ceph-${vers}
DEB_VERSION=$(dpkg-parsechangelog | sed -rne 's,^Version: (.*),\1, p')
BP_VERSION=${DEB_VERSION}${BPTAG}
dch -D $DIST --force-distribution -b -v "$BP_VERSION" "$comment"
)
dpkg-source -b ceph-${vers}
echo "Building Debian"
cd "$WORKSPACE"
# Before, at this point, this script called the below contents that
# was part of /srv/ceph-buid/build_debs.sh. Now everything is in here, in one
# place, no need to checkout/clone anything. WYSIWYG::
#
# sudo $bindir/build_debs.sh ./release /srv/debian-base $vers
releasedir="./release"
pbuilddir="/srv/debian-base"
cephver=$vers
if $PBUILDER_IN_TMPFS; then
pbuild_build_dir="/var/cache/pbuilder/build"
else
mkdir -p $WORKSPACE/build
pbuild_build_dir="$WORKSPACE/build"
fi
echo version $cephver
echo deb vers $bpvers
echo building debs for $DIST
CEPH_EXTRA_CMAKE_ARGS="$CEPH_EXTRA_CMAKE_ARGS $(extra_cmake_args)"
DEB_BUILD_OPTIONS="parallel=$(get_nr_build_jobs)"
# pass only those env vars specifically noted
sudo \
CEPH_EXTRA_CMAKE_ARGS="$CEPH_EXTRA_CMAKE_ARGS" \
DEB_BUILD_OPTIONS="$DEB_BUILD_OPTIONS" \
DEB_BUILD_PROFILES="$DEB_BUILD_PROFILES" \
pbuilder build \
--distribution $DIST \
--basetgz $pbuilddir/$DIST.tgz \
--buildresult $releasedir/$cephver \
--use-network yes \
--buildplace $pbuild_build_dir \
$releasedir/$cephver/ceph_$bpvers.dsc
if $PBUILDER_IN_TMPFS; then
sudo umount $pbuild_build_dir
fi
# do lintian checks
echo lintian checks for $bpvers
echo lintian --allow-root $releasedir/$cephver/*$bpvers*.deb
[ "$FORCE" = true ] && chacra_flags="--force" || chacra_flags=""
if [ "$THROWAWAY" = false ] ; then
# push binaries to chacra
find release/$vers/ | \
egrep "*(\.changes|\.deb|\.ddeb|\.dsc|ceph[^/]*\.gz)$" | \
egrep -v "(Packages|Sources|Contents)" | \
$venv/chacractl binary ${chacra_flags} create ${chacra_endpoint}