Skip to content

Commit 804d6ed

Browse files
committed
services/nomad/build/build-rsyncd,buildbot: improve sync/index of packages
* to prevent re-syncing packages between each package build, use --compare-dest * to prevent races with syncing and signing, update the repo as a pre-xfer script and collect the log to show in the builder output
1 parent 06ca246 commit 804d6ed

File tree

4 files changed

+106
-55
lines changed

4 files changed

+106
-55
lines changed

services/nomad/build/build-rsyncd.nomad

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ job "build-rsyncd" {
6565
}
6666

6767
template {
68-
data = file("rsync-post-xfer")
69-
destination = "local/rsync-post-xfer"
68+
data = file("rsync-update-repo")
69+
destination = "local/rsync-update-repo"
7070
perms = "0755"
7171
}
7272

@@ -114,8 +114,13 @@ EOF
114114
[incoming-${template.value}]
115115
path = /incoming/${template.value}
116116
auth users = buildsync:rw
117-
filter = + */ + *.${template.value}.xbps - *.sig - *.sig2 - *-repodata* - .*
118-
post-xfer exec = /local/rsync-post-xfer
117+
filter = + */ + *.${template.value}.xbps - *.sig - *.sig2 - *-repodata* - .* - *.log
118+
119+
[updaterepo-${template.value}]
120+
path = /incoming/${template.value}
121+
auth users = buildsync:r
122+
filter = + update-repo.log - * - .*
123+
early exec = /local/rsync-update-repo
119124
EOF
120125
destination = "local/rsyncd.conf.d/${template.value}.conf.inc"
121126
}

services/nomad/build/buildbot.cfg

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,28 @@ esac
235235
""")]
236236

237237

238+
@util.renderer
239+
def make_update_repo_cmd(props):
240+
return ['bash', '-e', '-c',
241+
util.Interpolate(f"""
242+
echo "=> Moving packages to the shadow repository..."
243+
rsync -vurk --delete-after --password-file=/secrets/rsync/password \
244+
{{ range nomadService 1 $allocID "build-rsyncd" -}}
245+
rsync://buildsync@{{ .Address }}:{{ .Port }}/updaterepo-%(prop:target)s/update-repo.log ./update-repo.log
246+
{{ end -}}
247+
case "$?" in
248+
0|23|24)
249+
cat ./update-repo.log
250+
exit 0
251+
;;
252+
*)
253+
cat ./update-repo.log
254+
exit 1
255+
;;
256+
esac
257+
""")]
258+
259+
238260
@util.renderer
239261
def make_clean_cmd(props):
240262
return [
@@ -258,6 +280,11 @@ def build_packages(props):
258280
logname=f'sync:{p}',
259281
haltOnFailure=True,
260282
))
283+
cmds.append(util.ShellArg(
284+
command=make_update_repo_cmd,
285+
logname=f'update-repo:{p}',
286+
haltOnFailure=True,
287+
))
261288
if cmds:
262289
cmds.append(util.ShellArg(
263290
command=['make', 'clean'],
@@ -372,6 +399,18 @@ factory.addStep(steps.ShellCommand(
372399
timeout=14400,
373400
))
374401

402+
factory.addStep(steps.ShellCommand(
403+
command=make_update_repo_cmd,
404+
name='update_repository',
405+
description='updating shadow repository with built packages',
406+
descriptionDone='updated shadow repository with built packages',
407+
alwaysRun=True,
408+
logEnviron=False,
409+
usePTY=True,
410+
workdir=builddir(),
411+
timeout=14400,
412+
))
413+
375414
factory.addStep(steps.ShellCommand(
376415
command=make_clean_cmd,
377416
name='clean_packages',

services/nomad/build/rsync-post-xfer

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
3+
msg() {
4+
printf '\033[32m=> %s\033[0m\n' "$*"
5+
}
6+
7+
process_repo() {
8+
repo="$1"
9+
msg "Processing repository: $repo"
10+
if [ ! -d "$RSYNC_MODULE_PATH/$repo" ] || [ ! -d "$TGT_BASE/$TGT/$repo" ]; then
11+
msg "Nothing to do"
12+
return
13+
fi
14+
# add to repodata
15+
find "$RSYNC_MODULE_PATH"/"$repo" -mindepth 1 -maxdepth 1 -name '*.xbps' -printf "$TGT_BASE/$TGT/$repo/%f\0" | \
16+
xargs -r0 env XBPS_TARGET_ARCH="$ARCH" xbps-rindex -a
17+
# clean old packages from repodata
18+
XBPS_TARGET_ARCH="$ARCH" xbps-rindex -c "$TGT_BASE/$TGT/$repo"
19+
# remove old packages
20+
XBPS_TARGET_ARCH="$ARCH" xbps-rindex -r "$TGT_BASE/$TGT/$repo"
21+
}
22+
23+
run() {
24+
set -e
25+
TGT_BASE="/mirror/current"
26+
ARCH="${RSYNC_MODULE_NAME#*-}"
27+
28+
case "$ARCH" in
29+
aarch64*) TGT="aarch64" ;;
30+
*-musl) TGT="musl" ;;
31+
*) TGT="" ;;
32+
esac
33+
34+
# copy files to repo
35+
msg "Copying new packages to the shadow mirror"
36+
rsync -va "${RSYNC_MODULE_PATH:?}"/ "$TGT_BASE/$TGT/"
37+
38+
for repo in / /bootstrap /debug /nonfree; do
39+
process_repo "$repo"
40+
done
41+
42+
case "$ARCH" in
43+
x86_64|i686)
44+
ARCH=x86_64
45+
for repo in /multilib /multilib/bootstrap /multilib/nonfree; do
46+
process_repo "$repo"
47+
done
48+
;;
49+
esac
50+
51+
# clean up incoming
52+
msg "Cleaning up"
53+
rm -rvf "${RSYNC_MODULE_PATH:?}"/*.xbps
54+
set +e
55+
}
56+
57+
# if this exits non-zero, rsync will fail and the log will be lost
58+
run >"$RSYNC_MODULE_PATH"/update-repo.log 2>&1 || true

0 commit comments

Comments
 (0)