Skip to content

Commit 61d78ae

Browse files
committed
services/nomad/build/build-rsyncd,buildbot: improve sync/index of packages
* to prevent re-syncing packages between each package build, use --remove-source-files * 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 59c2d3e commit 61d78ae

4 files changed

Lines changed: 99 additions & 58 deletions

File tree

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: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ from pathlib import Path
1010
from twisted.internet import defer
1111
from twisted.python import log
1212

13-
from buildbot.process.results import SUCCESS
1413
from buildbot.plugins import util, secrets, reporters, worker, schedulers
1514
from buildbot.plugins import steps
1615

@@ -222,20 +221,45 @@ def make_rsync_cmd(props):
222221
return ['bash', '-e', '-c',
223222
util.Interpolate("""
224223
echo "=> Syncing packages to the shadow repository..."
225-
rsync -vurk --delete-after \
224+
rsync -vurk --delete-after --remove-source-files \
226225
--filter='+ */' --filter='+ *.%(prop:target)s.xbps' \
227226
--filter='- .*' --filter='- *' \
228227
--password-file=/secrets/rsync/password /hostdir/binpkgs/ \
229228
{{ range nomadService 1 $allocID "build-rsyncd" -}}
230229
rsync://buildsync@{{ .Address }}:{{ .Port }}/incoming-%(prop:target)s
231230
{{ end -}}
232-
case "$?" in
231+
RSYNC_EXIT="$?"
232+
echo "=> Cleaning repodatas..."
233+
find /hostdir/binpkgs -name '%(prop:target)s-repodata' -print -delete
234+
case "$RSYNC_EXIT" in
233235
0|23|24) exit 0 ;;
234236
*) exit 1 ;;
235237
esac
236238
""")]
237239

238240

241+
@util.renderer
242+
def make_update_repo_cmd(props):
243+
return ['bash', '-e', '-c',
244+
util.Interpolate(f"""
245+
echo "=> Moving packages to the shadow repository..."
246+
rsync -vurk --delete-after --password-file=/secrets/rsync/password \
247+
{{ range nomadService 1 $allocID "build-rsyncd" -}}
248+
rsync://buildsync@{{ .Address }}:{{ .Port }}/updaterepo-%(prop:target)s/update-repo.log ./update-repo.log
249+
{{ end -}}
250+
case "$?" in
251+
0|23|24)
252+
cat ./update-repo.log
253+
exit 0
254+
;;
255+
*)
256+
cat ./update-repo.log
257+
exit 1
258+
;;
259+
esac
260+
""")]
261+
262+
239263
@util.renderer
240264
def make_clean_cmd(props):
241265
return [
@@ -259,6 +283,11 @@ def build_packages(props):
259283
logname=f'sync:{p}',
260284
haltOnFailure=True,
261285
))
286+
cmds.append(util.ShellArg(
287+
command=make_update_repo_cmd,
288+
logname=f'update-repo:{p}',
289+
haltOnFailure=True,
290+
))
262291
if cmds:
263292
cmds.append(util.ShellArg(
264293
command=['make', 'clean'],

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)