Skip to content

Commit ad37504

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 ad37504

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
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: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,17 @@ def make_xbps_bulk_cmd(props):
218218

219219
@util.renderer
220220
def make_rsync_cmd(props):
221+
target = props.getProperty('target')
222+
if target.startswith("aarch64"):
223+
final_dest = "/mirror/current/aarch64"
224+
elif target.endswith("musl"):
225+
final_dest = "/mirror/current/musl"
226+
else:
227+
final_dest = "/mirror/current"
221228
return ['bash', '-e', '-c',
222-
util.Interpolate("""
229+
util.Interpolate(f"""
223230
echo "=> Syncing packages to the shadow repository..."
224-
rsync -vurk --delete-after \
231+
rsync -vurk --delete-after --compare-dest={final_dest} \
225232
--filter='+ */' --filter='+ *.%(prop:target)s.xbps' \
226233
--filter='- .*' --filter='- *' \
227234
--password-file=/secrets/rsync/password /hostdir/binpkgs/ \
@@ -235,6 +242,28 @@ esac
235242
""")]
236243

237244

245+
@util.renderer
246+
def make_update_repo_cmd(props):
247+
return ['bash', '-e', '-c',
248+
util.Interpolate(f"""
249+
echo "=> Moving packages to the shadow repository..."
250+
rsync -vurk --delete-after --password-file=/secrets/rsync/password \
251+
{{ range nomadService 1 $allocID "build-rsyncd" -}}
252+
rsync://buildsync@{{ .Address }}:{{ .Port }}/updaterepo-%(prop:target)s/update-repo.log ./update-repo.log
253+
{{ end -}}
254+
case "$?" in
255+
0|23|24)
256+
cat ./update-repo.log
257+
exit 0
258+
;;
259+
*)
260+
cat ./update-repo.log
261+
exit 1
262+
;;
263+
esac
264+
""")]
265+
266+
238267
@util.renderer
239268
def make_clean_cmd(props):
240269
return [
@@ -258,6 +287,11 @@ def build_packages(props):
258287
logname=f'sync:{p}',
259288
haltOnFailure=True,
260289
))
290+
cmds.append(util.ShellArg(
291+
command=make_update_repo_cmd,
292+
logname=f'update-repo:{p}',
293+
haltOnFailure=True,
294+
))
261295
if cmds:
262296
cmds.append(util.ShellArg(
263297
command=['make', 'clean'],
@@ -372,6 +406,18 @@ factory.addStep(steps.ShellCommand(
372406
timeout=14400,
373407
))
374408

409+
factory.addStep(steps.ShellCommand(
410+
command=make_update_repo_cmd,
411+
name='sync_packages',
412+
description='updating shadow repository with built packages',
413+
descriptionDone='updated shadow repository with built packages',
414+
alwaysRun=True,
415+
logEnviron=False,
416+
usePTY=True,
417+
workdir=builddir(),
418+
timeout=14400,
419+
))
420+
375421
factory.addStep(steps.ShellCommand(
376422
command=make_clean_cmd,
377423
name='clean_packages',
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

3-
set -e
3+
set -ex
4+
5+
exec >"$RSYNC_MODULE_PATH"/update-repo.log 2>&1
46

57
TGT_BASE="/mirror/current"
68

@@ -16,9 +18,6 @@ process_repo() {
1618
XBPS_TARGET_ARCH="$ARCH" xbps-rindex -c "$TGT_BASE/$TGT/$repo"
1719
# remove old packages
1820
XBPS_TARGET_ARCH="$ARCH" xbps-rindex -r "$TGT_BASE/$TGT/$repo"
19-
# Remove signatures that don't have a corresponding package
20-
find "$TGT_BASE/$TGT/$repo" -maxdepth 1 \( -name '*.xbps.sig' -o -name '*.xbps.sig2' \) \
21-
-exec sh -c 'for x in "$@"; do [ -e "${x%.sig*}" ] || rm -- $x; done' _ {} +
2221
}
2322

2423
ARCH="${RSYNC_MODULE_NAME#*-}"
@@ -46,6 +45,6 @@ case "$ARCH" in
4645
esac
4746

4847
# clean up incoming
49-
rm -r "${RSYNC_MODULE_PATH:?}"/*
48+
rm -r "${RSYNC_MODULE_PATH:?}"/*.xbps
5049

5150
exit 0

0 commit comments

Comments
 (0)