forked from rcbops/jenkins-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins-deb-common
executable file
·841 lines (665 loc) · 23.8 KB
/
jenkins-deb-common
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
#!/bin/bash
function jenkins_init() {
if [ ! -z "${__JENKINS_INITIALIZED-}" ]; then
return
fi
__JENKINS_INIALIZED=1
log "Initializing"
set -x
set -e
set -u
exec 2>&1
jenkins_set_vars
}
# see if we want to be involved in doing a thing
# if jenkins could do matrix build filters on component, that would win
function jenkins_am_interested() {
# $1 - distrelease (ubuntu-maverick)
# $2 - packageset (diablo-d5)
local release=${DISTRELEASE##*-}
case $2 in
diablo-d5)
[[ ${release} > "oneiric" ]] && return 1
return 0
;;
diablo-final)
[[ ${release} > "oneiric" ]] && return 1
return 0
;;
essex-e3)
return 0
;;
*)
return 0
esac
return 0
}
# set default values for all the configuration options
function jenkins_set_vars() {
if [ ! -z "${__JENKINS_INITIALIZED-}" ]; then
return
fi
unset STRATEGY
[ -e /etc/jenkins-deb/jenkins-deb.conf ] && . /etc/jenkins-deb/jenkins-deb.conf
# needs the base_dir so it can find virt templates
BASE_DIR=${BASE_DIR:=~/jenkins-build}
DEBEMAIL=${DEBEMAIL-'RCB Builder <[email protected]>'}
GIT_BRANCH=${GIT_BRANCH-master}
SOURCE_BUILD_DIST=${SOURCE_BUILD_DIST-ubuntu}
SOURCE_BUILD_RELEASE=${SOURCE_BUILD_RELEASE-natty}
PACKAGE_HOST=${PACKAGE_HOST-build.monkeypuppetlabs.com}
IMAGE_CACHE=${IMAGE_CACHE:-build.monkeypuppetlabs.com}
# DIST_CACHE=${DIST_CACHE:-cache.monkeypuppetlabs.com:3142}
DIST_CACHE=${DIST_CACHE:-`grep "cache.monkeypuppetlabs.com" /etc/hosts | awk '{print $1}'`:3142}
SQUID_CACHE=${SQUID_CACHE:-`grep "cache.monkeypuppetlabs.com" /etc/hosts | awk '{print $1}'`:3128}
# this should get overridden by the branch config
if [ "${COMPONENT-}" != "" ]; then
NOVA_RELEASE=${COMPONENT%%-*}
MILESTONE=${COMPONENT##*-}
else
NOVA_RELEASE=${NOVA_RELEASE-essex}
MILESTONE=${MILESTONE-e3}
fi
MAJOR_VERSION=${MAJOR_VERSION-2012.1}
ARCH=${ARCH-amd64}
STRATEGY=${STRATEGY-lvm}
SIGNING_KEY=${SIGNING_KEY-F87CBDE0}
# we only see this on source builds
if [ -e debian/changelog ]; then
PACKAGE_VERSION=$(grep "urgency=" debian/changelog | sed -e 's/.*(\(.*\)).*/\1/' | head -n1)
fi
JOB_NAME=${JOB_NAME-tty}
PACKAGE=$(echo ${JOB_NAME} | cut -d '/' -f 1 | sed -r -e "s/-(source|binaries)$//")
# distrelease set in arch matrix on binary build
if [ "${DISTRELEASE:-}" != "" ]; then
BINARY_BUILD_DIST=${DISTRELEASE%%-*}
BINARY_BUILD_RELEASE=${DISTRELEASE##*-}
fi
# figure out if this is a debian-ish or redhat-ish dist
if [ "${BINARY_BUILD_DIST:-}" != "" ]; then
declare -A variantmaps
variantmaps=(
[ubuntu]="debian"
[debian]="debian"
[fedora]="redhat"
[centos]="redhat"
[redhat]="redhat"
)
BINARY_BUILD_VARIANT=${variantmaps[${BINARY_BUILD_DIST}]}
fi
LVM_ROOT=${LVM_ROOT-/dev/vg0}
INCOMING_PACKAGES=${INCOMING_PACKAGES-/srv/incoming-packages}
PROPOSED_REPO=${PROPOSED_REPO-/srv/proposed-packages}
}
function acquire_lock() {
# $1 - lock name
# $2 - file handle - default 254
name=${1-}
fh=${2-9}
[ "${name}" != "" ] || die "Must specify lock name"
log "$(date +%Y%m%d): acquiring lock"
eval "exec ${fh}>/tmp/${name}"
flock -x ${fh}
log "$(date +%Y%m%d): acquired lock"
}
function release_lock() {
# $1 - file handle
fh=${1-9}
flock -u ${fh}
eval "${fh}>&-"
log "$(date +%Y%m%d): released lock"
}
function die() {
echo $0
exit 1
}
function log() {
echo $*
}
function run_chef_solo() {
# $1 - IP
# $2 - cookbook tarball URL
# $3 - dna.json
ip=$1
tarball=$2
dna=$3
log "Running chef solo using:"
log " ip: ${ip}"
log " tarball: ${tarball}"
log " dna file: ${dna}"
scp ${dna} root@${ip}:/root/dna.json
# ruby ssl on maverick defaults to verify certs, and chef can't download recipies from https
if [[ ${tarball} =~ "http" ]]; then
tarball_file=$(mktemp)
wget ${tarball} -O ${tarball_file}
tarball=$(basename ${tarball})
scp ${tarball_file} root@${ip}:~/${tarball}
rm ${tarball_file}
fi
ssh root@${ip} "DEBIAN_FRONTEND=noninteractive apt-get install -y chef"
ssh root@${ip} "LANG=C chef-solo -r ${tarball} -j /root/dna.json -l debug"
}
function maybe_make_kvm_instance() {
# $1 - name
# $2 - size in G (optional)
gigs=${2-8}
base_instance=${LVM_ROOT}/${BINARY_BUILD_RELEASE}
new_instance=${1}
if [ -e ${LVM_ROOT}/${new_instance} ]; then
sudo lvremove -f ${LVM_ROOT}/${new_instance}
fi
if [ ! -e ${LVM_ROOT}/${new_instance} ]; then
sudo lvcreate ${LVM_ROOT}/${BINARY_BUILD_RELEASE} --size=${gigs}G --name=${new_instance} --snapshot
else
echo "Logical volume ${LVM_ROOT}/${new_instance} already exists"
return 1
fi
}
function start_kvm_instance() {
# $1 - name
# $2 - IP
# $3 - openstack url
# $4 - openstack release
# $5 - openstack component
new_instance=${1}
my_ip=${2}
openstack_url=${3}
openstack_release=${4}
openstack_component=${5}
MEMORY=${MEMORY-524288}
# fix up the apt sources....
sudo mkdir -p /mnt/$$
sudo mount ${LVM_ROOT}/${new_instance} /mnt/$$
function start_kvm_instance_cleanup() {
sudo umount /mnt/$$
sudo rm -rf /mnt/$$
return 1
}
trap "start_kvm_instance_cleanup; return 1" SIGINT SIGTERM ERR
# Setup apt sources
if [ ${BINARY_BUILD_VARIANT} = "debian" ]; then
cat <<EOF | sudo tee /mnt/$$/etc/apt/sources.list
deb http://${DIST_CACHE}/ubuntu ${BINARY_BUILD_RELEASE} main universe
deb http://${DIST_CACHE}/ubuntu ${BINARY_BUILD_RELEASE}-updates main universe
#deb ${openstack_url}/${openstack_component} ${openstack_release} main
deb ${openstack_url} ${openstack_release} ${openstack_component}
EOF
else
echo "current directory: `pwd`"
cat $BASE_DIR/files/fedora.repo | sudo tee /mnt/$$/etc/yum.repos.d/fedora.repo
cat $BASE_DIR/files/fedora-updates.repo | sudo tee /mnt/$$/etc/yum.repos.d/fedora-updates.repo
cat $BASE_DIR/files/fedora-updates-testing.repo | sudo tee /mnt/$$/etc/yum.repos.d/fedora-updates-testing.repo
# Fishstick01 is running a squid cache for YUM
cat <<EOF | sudo tee /mnt/$$/etc/yum.conf
[main]
cachedir=/var/cache/yum/\$basearch/\$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
proxy=http://${SQUID_CACHE}
EOF
fi
# Configure /etc/hosts
if [ ${BINARY_BUILD_VARIANT} = "debian" ]; then
cat <<EOF | sudo tee /mnt/$$/etc/hosts
127.0.0.1 localhost
127.0.1.1 ${new_instance}
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
else
cat <<EOF | sudo tee /mnt/$$/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.1.1 ${new_instance}
192.168.1.1 jenkins-host.localhost.localdomain jenkins-host
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
EOF
fi
# Configure networking
if [ ${BINARY_BUILD_VARIANT} = "debian" ]; then
cat <<EOF | sudo tee /mnt/$$/etc/network/interfaces
auto eth0
iface eth0 inet static
address ${my_ip}
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
EOF
else
cat <<EOF | sudo tee /mnt/$$/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
IPADDR=${my_ip}
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT="yes"
TYPE=Ethernet
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
EOF
sudo rm -f /mnt/$$/etc/sysconfig/network-scripts/ifcfg-p2p1
fi
# Setup hostame
if [ ${BINARY_BUILD_VARIANT} = "debian" ]; then
echo ${new_instance} | sudo tee /mnt/$$/etc/hostname
else
cat <<EOF | sudo tee /mnt/$$/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=${new_instance}
EOF
fi
echo "nameserver 192.168.1.1" | sudo tee /mnt/$$/etc/resolv.conf
sudo mkdir -p /mnt/$$/root/.ssh
sudo cp ${HOME}/.ssh/id_rsa.pub /mnt/$$/root/.ssh/authorized_keys
sudo chmod -R og-rwx /mnt/$$/root/.ssh
if [ ${BINARY_BUILD_VARIANT} = "debian" ]; then
# hackity hack hack hack
sudo mkdir -p /mnt/$$/lib/modules
sudo cp -a /lib/modules/`uname -r` /mnt/$$/lib/modules
if [ ! -e /mnt/$$/usr/sbin/sshd ]; then
sudo chroot /mnt/$$ apt-get update
cat <<EOF | sudo tee /mnt/$$/usr/sbin/policy-rc.d
#!/bin/sh
exit 101
EOF
sudo chmod 755 /mnt/$$/usr/sbin/policy-rc.d
sudo chroot /mnt/$$ apt-get install -y openssh-server
sudo rm -f /mnt/$$/usr/sbin/policy-rc.d
fi
sudo cp /etc/ssh/*key* /mnt/$$/etc/ssh
fi
sudo umount ${LVM_ROOT}/${new_instance}
sudo rm -rf /mnt/$$
# See if we have a virsh definition for this
if ! $( sudo virsh list | grep -q "${new_instance}" ); then
# make a new virsh definition
# Varibles that get substituted in this template
# are $MEMORY, $INSTANCE_NAME, and ${LVM_ROOT}
INSTANCE_NAME=${new_instance}
virt_template=${BASE_DIR}/virt-templates/default
if [ -e ${BASE_DIR}/virt-templates/$(hostname) ]; then
virt_template=${BASE_DIR}/virt-templates/$(hostname)
fi
if [ -e ${BASE_DIR}/virt-templates/$(hostname)-$BINARY_BUILD_DIST-$BINARY_BUILD_RELEASE ]; then
virt_template=${BASE_DIR}/virt-templates/$(hostname)-$BINARY_BUILD_DIST-$BINARY_BUILD_RELEASE
fi
if [ -e ${BASE_DIR}/virt-templates/$INSTANCE_NAME ]; then
virt_template=${BASE_DIR}/virt-templates/$INSTANCE_NAME
fi
if [ -e ${BASE_DIR}/virt-templates/$(hostname)-$INSTANCE_NAME ]; then
virt_template=${BASE_DIR}/virt-templates/$(hostname)-$INSTANCE_NAME
fi
eval "echo \"$(< ${virt_template})\"" > /tmp/newxml-${new_instance}
sudo virsh create /tmp/newxml-${new_instance}
rm /tmp/newxml-${new_instance}
else
sudo virsh start ${new_instance}
fi
# wait for the box to come up
count=1
while [ $count -lt 20 ]; do
# wait for port 22 to open
count=$(( count + 1 ))
sleep 5
if ( nc ${my_ip} 22 -w 1 -q 0 < /dev/null ); then
break
fi
done
sleep 5
[ -e ${HOME}/.ssh ] && ssh-keyscan ${my_ip} >> ${HOME}/.ssh/known_hosts
}
# reset the "proposed repo" to the current upstream
function reset_repo() {
acquire_lock "repo"
[ -e ${PROPOSED_REPO} ] || die "No ${PROPOSED_REPO}"
rm -rf ${PROPOSED_REPO}/*
cp -a /srv/packages/* ${PROPOSED_REPO}
release_lock
}
# promote the "proposed repo" to the current repo
function promote_repo() {
# $1 - repo to promote (optional)
acquire_lock "repo"
[ -e ${PROPOSED_REPO} ] || die "No ${PROPOSED_REPO}"
if [ "${1-}" != "" ]; then
subrepo=$1
if [ ! -d ${PROPOSED_REPO}/${subrepo} ]; then
release_lock
echo "Bad repo"
return 1
fi
rm -rf /srv/packages/${subrepo}/*
cp -a ${PROPOSED_REPO}/${subrepo} /srv/packages
else
rm -rf /srv/packages/*
cp -a ${PROPOSED_REPO}/* /srv/packages
fi
release_lock
}
# builder a new schroot for pbuilder
function verify_pbuilder() {
# $1 - schroot template
# $2 - pbuilder name
distro_chroot=${1}
pbuilder=${2}
lockfile-create /tmp/build-${pbuilder}
lockfile-touch -o /tmp/build-${pbuilder}
trap "lockfile-remove /tmp/build-${pbuilder}" SIGINT SIGTERM EXIT ERR
if ! (schroot --list --all-session | grep -q ${pbuilder}); then
log "Building pbuilder for ${pbuilder}"
schroot -c ${distro_chroot} -n ${pbuilder} -b
log "Updating pbuilder"
schroot -c ${pbuilder} -r -u root -- apt-get update
log "Installing pbuilder..."
schroot -c ${pbuilder} -r -u root -- /bin/bash -c 'DEBIAN_FRONTEND=noninteractive apt-get --force-yes -y install pbuilder aptitude git-buildpackage'
log "Cleanup"
schroot -c ${pbuilder} -r -u root -- /etc/init.d/atd stop
else
log "pbuilder schroot exists... skipping"
fi
lockfile-remove /tmp/build-${pbuilder}
trap - SIGINT SIGTERM EXIT ERR
}
function build_source_package {
# $1 - optional, build dir
local build_args=""
local relative_build_dir=".."
if [ "${1-}" != "" ]; then
build_args="--git-export-dir=${1}"
relative_build_dir=${1}
fi
if [ -e debian/control ]; then
# kind of cheesy
set_component_from_dsc debian/control
fi
distro_chroot=${SOURCE_BUILD_RELEASE}-${NOVA_RELEASE}-${MILESTONE}
pbuilder=${USER}-${distro_chroot}-pbuilder
acquire_lock ${pbuilder}
verify_pbuilder $distro_chroot $pbuilder
# apply patches before dpkg-buildpackage
if [ -s debian/patches/series ]; then
quilt push -a
fi
schroot -c ${pbuilder} -r -u root -- apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 765C5E49F87CBDE0
schroot -c ${pbuilder} -r -u root -- apt-get update -y
schroot -c ${pbuilder} -r -u root -- /usr/lib/pbuilder/pbuilder-satisfydepends
if [[ ${APPEND_BUILD_NUMBER_TO_PACKAGE} = "1" ]]; then
schroot -c jenkins-precise-rcb-utils-pbuilder -r -- git-dch -a -N ${PACKAGE_VERSION}-${BUILD_NUMBER} --debian-branch=${GIT_BRANCH} -S --id-length=10
schroot -c jenkins-precise-rcb-utils-pbuilder -r -- git-buildpackage '-i.*' -tc -S --git-ignore-new --git-ignore-branch --git-upstream-tag=${GIT_BRANCH}
schroot -c jenkins-precise-rcb-utils-pbuilder -r -- git reset --hard HEAD
else
schroot -c ${pbuilder} -r -- git-buildpackage --git-pristine-tar -i.* -tc -S --git-ignore-new --git-ignore-branch ${build_args}
fi
release_lock
# hrm... we have packages, but now they are setting in the .. directory
mv ${relative_build_dir}/*.gz .
mv ${relative_build_dir}/*changes .
mv ${relative_build_dir}/*dsc .
mv ${relative_build_dir}/*build .
# for the jenkins post-deploy job
if [ "" != "${JENKINS_HOME-}" ] && [ "" != "${JOB_NAME-}" ] && [ "" != "${BUILD_NUMBER-}" ]; then
mkdir -p ${JENKINS_HOME}/userContent/${JOB_NAME}/${BUILD_NUMBER}
fi
}
function set_component_from_dsc() {
# $1 - dsc
dsc=${1}
RCB_COMPONENT=$(grep -i "rcb-component" "${dsc}" | awk '{ print $2 }')
if [ "${RCB_COMPONENT-}" != "" ]; then
NOVA_RELEASE=${RCB_COMPONENT%%-*}
MILESTONE=${RCB_COMPONENT##*-}
fi
}
function build_binary_packages() {
dsc=${1}
# we need to figure out the nova_release and milestone from the .dch
set_component_from_dsc ${dsc}
log "Attempting packaging for ${NOVA_RELEASE}-${MILESTONE} on ${DISTRELEASE}"
if ( ! jenkins_am_interested ${DISTRELEASE} ${NOVA_RELEASE}-${MILESTONE} ); then
log "Not interested in this package"
return 0
fi
distro_chroot=${BINARY_BUILD_RELEASE}-${NOVA_RELEASE}-${MILESTONE}
DEB_BUILD_OPTIONS="nodocs nocheck" sbuild \
-n -A -d ${NOVA_RELEASE}-${MILESTONE} \
--append-to-version=~${BINARY_BUILD_RELEASE} \
-m "${DEBEMAIL}" -k ${SIGNING_KEY} \
-c ${distro_chroot} ${dsc}
# drop a java properties file with the NOVA_RELEASE and MILESTONE, so
# we can kick off the right package and kong tests...
[ "${WORKSPACE-}" != "" ] && echo "COMPONENT=${NOVA_RELEASE}-${MILESTONE}" > ${JENKINS_HOME}/jobs/${PACKAGE}-binaries/lastbuild.properties
}
function upload_to_incoming() {
# $1 - dsc file
set_component_from_dsc ${dsc}
if ( ! jenkins_am_interested ${DISTRELEASE} ${NOVA_RELEASE}-${MILESTONE} ); then
return 0
fi
# dump the packages into proposed packages. The repotest will
# merge outstanding packages.
acquire_lock "incoming"
mkdir -p ${INCOMING_PACKAGES}/${NOVA_RELEASE}/${MILESTONE}/${BINARY_BUILD_RELEASE}
mv *.{gz,dsc,changes} ${INCOMING_PACKAGES}/${NOVA_RELEASE}/${MILESTONE}/${BINARY_BUILD_RELEASE}
cp *.deb ${INCOMING_PACKAGES}/${NOVA_RELEASE}/${MILESTONE}/${BINARY_BUILD_RELEASE}
release_lock
}
function import_proposed_packages() {
acquire_lock "repo" 9
acquire_lock "incoming" 8
~/jenkins-build/scripts/merge.py ${PROPOSED_REPO}
source_packages=$(find ${INCOMING_PACKAGES} -name "*dsc")
binary_packages=$(find ${INCOMING_PACKAGES} -name "*deb")
for pkg in $source_packages; do
base_pkg=$(echo $pkg | sed -e s#${INCOMING_PACKAGES}##)
base_name=$(basename $base_pkg)
details=(${base_pkg//\// })
nova_release=${details[0]}
milestone=${details[1]}
release=${details[2]}
# see if this .dsc has already been imported
# if ( ! find ${PROPOSED_REPO} -name "${base_name}" ); then
# reprepro -b ${PROPOSED_REPO} -S ${nova_release}-${milestone} \
# includedsc ${release} ${pkg}
# else
# log "Skipping ${base_name} -- exists in repo"
# fi
# naw, on second though, just try and blindly stick it in
package_name=${base_name%%_*}
# for dist in ${PROPOSED_REPO}/dists; do
# if ( reprepro -b ${PROPOSED_REPO} -C ${nova_release}-${milestone} removesrc ${dist} ${package_name} ); then
# log "Removed ${package_name}"
# fi
# done
if ( reprepro -b ${PROPOSED_REPO}/${nova_release}-${milestone} -C ${nova_release}-${milestone} \
includedsc ${release} ${pkg} ); then
log "Uploaded ${pkg}"
fi
done
for pkg in $binary_packages; do
base_pkg=$(echo $pkg | sed -e s#${INCOMING_PACKAGES}##)
base_name=$(basename $base_pkg)
details=(${base_pkg//\// })
nova_release=${details[0]}
milestone=${details[1]}
release=${details[2]}
# pkg_file=${PROPOSED_REPO}/dists/${release}/${nova_release}-${milestone}/binary-${ARCH}/Packages
#
# if ( ! grep -q "$base_name" ${pkg_file} ); then
# reprepro -b ${PROPOSED_REPO} -S ${nova_release}-${milestone} \
# includedeb ${release} ${pkg}
# else
# log "Skipping ${base_name} - package exists in ${release} repo for ${nova_release}-${milestone}"
# fi
package_name=${base_name%%_*}
if ( reprepro -b ${PROPOSED_REPO}/${nova_release}-${milestone} -C ${nova_release}-${milestone} remove ${release} ${package_name} ); then
log "Removed package ${package_name}"
fi
if ( reprepro -b ${PROPOSED_REPO}/${nova_release}-${milestone} -C ${nova_release}-${milestone} \
includedeb ${release} ${pkg} ); then
log "Uploaded ${pkg}"
fi
done
# for source_pkg in ${INCOMING_PACKAGES}/*dsc; do
# reprepro -b ${PROPOSED_REPO} -S ${NOVA_RELEASE}-${MILESTONE} \
# includedsc ${BINARY_BUILD_RELEASE} ${source_pkg}
# done
# for source_pkg in ${INCOMING_PACKAGES}/*deb; do
# reprepro -b /src/proposed-packages -S ${NOVA_RELEASE}-${MILESTONE} \
# includedeb ${BINARY_BUILD_RELEASE} ${source_pkg}
# done
rm -rf ${INCOMING_PACKAGES}/*
~/jenkins-build/scripts/merge.py ${PROPOSED_REPO}
release_lock 8
release_lock 9
}
function get_ip {
# $1 - what to get IP for, from range in /etc/jenkins-deb/jenkins-deb-ip.conf
# poor-man's IPAM
#
# /etc/jenkins-deb/jenkins-deb-ip.conf should look like this:
# 192.168.1.10 unallocated
# 192.168.1.11 unallocated
# ---
#
# allocation will be first-come, first-served allocated by name. Once an
# ip has been allocated for a name, it will always be allocated to that
# name. There is no cleanup, no ping tests, etc.
#
# clean it up yourself.
#
# first, load in the whole list
acquire_lock "index" # trap handler already set
# declares in functions are by default local (without -x)
declare -A ip_list
declare -A host_list
local ip
local host
ip_list=()
host_list=()
while read line; do
ip=${line%% *}
host=${line##* }
ip_list[${ip}]=${host}
host_list[${host}]=${ip}
done < <(cat /etc/jenkins-deb/jenkins-deb-ip.conf)
# set the host to the passed-in host name
host=${1}
if [ "${host_list[${host}]-}" != "" ]; then
# already have an ip allocated for this host
IP=${host_list[${host}]}
else
# need to allocate and write the file back out. Pick
# the last unallocated
IP=${host_list[unallocated]}
ip_list[${IP}]=${host}
# Now, write out the file
local tmpfile=$(mktemp)
for ip in ${!ip_list[@]}; do
echo "Writing ${ip}"
echo "${ip} ${ip_list[${ip}]}" >> ${tmpfile}
done
sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n ${tmpfile} > /etc/jenkins-deb/jenkins-deb-ip.conf
rm ${tmpfile}
fi
release_lock
}
function aquire_ip {
# $1 - what to get IP for, from range in /etc/jenkins-deb/jenkins-deb-ip.conf
# poor-man's IPAM
#
# /etc/jenkins-deb/jenkins-deb-ip.conf should look like this:
# 192.168.1.10 unallocated
# 192.168.1.11 unallocated
# ---
#
# allocation will be first-come, first-served allocated by name. Once an
# ip has been allocated for a name, it will always be allocated to that
# name. There is no cleanup, no ping tests, etc.
#
# clean it up yourself.
#
# first, load in the whole list
acquire_lock "index" # trap handler already set
# declares in functions are by default local (without -x)
declare -A ip_list
declare -A host_list
local ip
local host
local ret
ip_list=()
host_list=()
while read line; do
ip=${line%% *}
host=${line##* }
ip_list[${ip}]=${host}
host_list[${host}]=${ip}
done < <(cat /etc/jenkins-deb/jenkins-deb-ip.conf)
# set the host to the passed-in host name
host=${1}
if [ "${host_list[${host}]-}" != "" ]; then
# already have an ip allocated for this host
ret=${host_list[${host}]}
else
# need to allocate and write the file back out. Pick
# the last unallocated
ret=${host_list[unallocated]}
ip_list[${IP}]=${host}
# Now, write out the file
local tmpfile=$(mktemp)
for ip in ${!ip_list[@]}; do
echo "Writing ${ip}"
echo "${ip} ${ip_list[${ip}]}" >> ${tmpfile}
done
sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n ${tmpfile} > /etc/jenkins-deb/jenkins-deb-ip.conf
rm ${tmpfile}
fi
release_lock
return $ret
}
function increment_counter {
# $1 - counter to increment
# $2 - variable to return the result in
acquire_lock "index"
# increment the global build number
. /etc/jenkins-deb/jenkins-deb-counters.conf
# hackity hack hack hack
eval ${1}="$(( ${1} + 1 ))"
eval ${2}=${!1}
# cat > /etc/jenkins-deb/jenkins-deb-counters.conf <<EOF
cat <<EOF
GLOBAL_REVNO=${GLOBAL_REVNO}
EOF
release_lock
}
function lv_remove() {
local lvm_name=${1}
local mapper_name=/dev/mapper/$(basename ${LVM_ROOT})-$(echo ${lvm_name} | sed -e 's/-/--/g')
# remove a lvm volume. On natty this is easy. On
# debian, the mapper devices probably have to get whacked first
#
if (! sudo lvremove -f ${LVM_ROOT}/${lvm_name}); then
# try and remove the mapper entries
if [ -e ${mapper_name}-cow ]; then
sudo dmsetup remove ${mapper_name}-cow
fi
if [ -e ${mapper_name} ]; then
sudo dmsetup remove ${mapper_name}
fi
fi
sudo lvremove -f ${LVM_ROOT}/${lvm_name}
}
if [ "${IMPORTED_JENKINS-}" = "" ]; then
jenkins_init
jenkins_set_vars
fi
export IMPORTED_JENKINS=1
jenkins_init