[arch-projects] [devtools] [PATCH] Add new tool: offload-build
This tool is useful for running makechrootpkg on a remote build server, and is by default hooked up to send a PKGBUILD and initiate a build on our shiny new build server "dragon". Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- manpage documentation hopefully coming tonight. Makefile | 1 + offload-build | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100755 offload-build diff --git a/Makefile b/Makefile index ba2d3e4..2306a17 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ IN_PROGS = \ BINPROGS = \ $(IN_PROGS) \ + offload-build \ sogrep CONFIGFILES = \ diff --git a/offload-build b/offload-build new file mode 100755 index 0000000..66609c6 --- /dev/null +++ b/offload-build @@ -0,0 +1,100 @@ +#!/bin/bash +# +# offload-build - build a PKGBUILD on a remote server using makechrootpkg. +# +# Copyright (c) 2019 by Eli Schwartz <eschwartz@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# + + +# global defaults suitable for use by Arch staff +repo=extra +arch=x86_64 +server=dragon.archlinux.org + +die() { printf "error: $1\n" "${@:2}"; exit 1; } + +usage() { + cat <<- _EOF_ + Usage: ${BASH_SOURCE[0]##*/} [--repo REPO] [--arch ARCHITECTURE] [--server SERVER] + + Build a PKGBUILD on a remote server using makechrootpkg. Requires a remote user + that can run archbuild without password auth. + + OPTIONS + -r, --repo Build against a specific repository (current: $repo) + -a, --arch Build against a specific architecture (current: $arch) + -s, --server Offload to a specific build server (current: $server) + -h, --help Show this help text +_EOF_ +} + +# option checking +while (( $# )); do + case $1 in + -h|--help) + usage + exit 0 + ;; + -r|--repo) + repo=$2 + shift 2 + ;; + -a|--arch) + arch=$2 + shift 2 + ;; + -s|--server) + server=$2 + shift 2 + ;; + *) + die "invalid argument: %s" "$1" + ;; + esac +done + +# multilib must be handled specially +if [[ $repo = multilib* ]]; then + arch= +fi + +trap 'rm -rf $SRCPKGDEST' EXIT + +# Use a source-only tarball as an intermediate to transfer files. This +# guarantees the checksums are okay, and guarantees that all needed files are +# transferred, including local sources, install scripts, and changelogs. +export SRCPKGDEST=$(mktemp -d) +makepkg --source || die "unable to make source package" + +mapfile -t files < <( + # This is sort of bash golfing but it allows running a mildly complex + # command over ssh with a single connection. + cat "$SRCPKGDEST"/*.src.tar.gz | + ssh $server ' + temp="${XDG_CACHE_HOME:-$HOME/.cache}/offload-build" && + mkdir -p "$temp" && + temp=$(mktemp -d -p "$temp") && + cd "$temp" && + { + bsdtar --strip-components 1 -xvf - && + script -qfc '"${repo}${arch:+-$arch}-build"' /dev/null && + printf "%s\n" "" "-> build complete" && + printf "\t%s\n" "$temp"/* + } >&2 && + makepkg --packagelist +') + +(( ${#files[@]} )) && printf '%s\n' '' '-> copying files...' && scp "${files[@]/#/$server:}" . -- 2.21.0
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- Makefile | 1 + doc/offload-build.1.asciidoc | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 doc/offload-build.1.asciidoc diff --git a/Makefile b/Makefile index 2306a17..27cd90f 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ BASHCOMPLETION_LINKS = \ MANS = \ doc/lddd.1 \ doc/checkpkg.1 \ + doc/offload-build.1 \ doc/sogrep.1 \ doc/mkarchroot.1 \ doc/find-libdeps.1 \ diff --git a/doc/offload-build.1.asciidoc b/doc/offload-build.1.asciidoc new file mode 100644 index 0000000..555f761 --- /dev/null +++ b/doc/offload-build.1.asciidoc @@ -0,0 +1,38 @@ +offload-build(1) +================ + +Name +---- +offload-build - Build a PKGBUILD on a remote server using makechrootpkg + +Synopsis +-------- +sogrep [options] + +Description +----------- + +Build a PKGBUILD on a remote server using makechrootpkg. Requires a remote user +that can run archbuild in a non-interactive manner, e.g. must be able to +elevate permissions using passwordless sudo. + +Options +------- + +*-r, --repo* <reponame>:: + Build against a specific repository. The default is `extra`, to build packages using + the stable repositories via extra-x86_64-build. + +*-a, --arch* <architecture>:: + Build against a specific architecture. The default is `x86_64`, the only + architecture officially supported by Arch Linux. + +*-s, --server* <hostname>:: + Offload to a specific build server. The default is dragon.archlinux.org + which is used as part of the build toolchain for the official Arch Linux + repos. + +*-h, --help*:: + Show a help text. + +include::footer.asciidoc[] -- 2.21.0
This tool is useful for running makechrootpkg on a remote build server, and is by default hooked up to send a PKGBUILD and initiate a build on our shiny new build server "dragon". Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- v2: script -qfc does not preserve the exit status of the wrapped command. Add -e so that we can properly abort if makechrootpkg failed. Makefile | 1 + offload-build | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100755 offload-build diff --git a/Makefile b/Makefile index ba2d3e4..2306a17 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ IN_PROGS = \ BINPROGS = \ $(IN_PROGS) \ + offload-build \ sogrep CONFIGFILES = \ diff --git a/offload-build b/offload-build new file mode 100755 index 0000000..c991754 --- /dev/null +++ b/offload-build @@ -0,0 +1,100 @@ +#!/bin/bash +# +# offload-build - build a PKGBUILD on a remote server using makechrootpkg. +# +# Copyright (c) 2019 by Eli Schwartz <eschwartz@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# + + +# global defaults suitable for use by Arch staff +repo=extra +arch=x86_64 +server=dragon.archlinux.org + +die() { printf "error: $1\n" "${@:2}"; exit 1; } + +usage() { + cat <<- _EOF_ + Usage: ${BASH_SOURCE[0]##*/} [--repo REPO] [--arch ARCHITECTURE] [--server SERVER] + + Build a PKGBUILD on a remote server using makechrootpkg. Requires a remote user + that can run archbuild without password auth. + + OPTIONS + -r, --repo Build against a specific repository (current: $repo) + -a, --arch Build against a specific architecture (current: $arch) + -s, --server Offload to a specific build server (current: $server) + -h, --help Show this help text +_EOF_ +} + +# option checking +while (( $# )); do + case $1 in + -h|--help) + usage + exit 0 + ;; + -r|--repo) + repo=$2 + shift 2 + ;; + -a|--arch) + arch=$2 + shift 2 + ;; + -s|--server) + server=$2 + shift 2 + ;; + *) + die "invalid argument: %s" "$1" + ;; + esac +done + +# multilib must be handled specially +if [[ $repo = multilib* ]]; then + arch= +fi + +trap 'rm -rf $SRCPKGDEST' EXIT + +# Use a source-only tarball as an intermediate to transfer files. This +# guarantees the checksums are okay, and guarantees that all needed files are +# transferred, including local sources, install scripts, and changelogs. +export SRCPKGDEST=$(mktemp -d) +makepkg --source || die "unable to make source package" + +mapfile -t files < <( + # This is sort of bash golfing but it allows running a mildly complex + # command over ssh with a single connection. + cat "$SRCPKGDEST"/*.src.tar.gz | + ssh $server ' + temp="${XDG_CACHE_HOME:-$HOME/.cache}/offload-build" && + mkdir -p "$temp" && + temp=$(mktemp -d -p "$temp") && + cd "$temp" && + { + bsdtar --strip-components 1 -xvf - && + script -qefc '"${repo}${arch:+-$arch}-build"' /dev/null && + printf "%s\n" "" "-> build complete" && + printf "\t%s\n" "$temp"/* + } >&2 && + makepkg --packagelist +') + +(( ${#files[@]} )) && printf '%s\n' '' '-> copying files...' && scp "${files[@]/#/$server:}" . -- 2.21.0
This tool is useful for running makechrootpkg on a remote build server, and is by default hooked up to send a PKGBUILD and initiate a build on our shiny new build server "dragon". Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- v3: Add passthrough of archbuild options as requested by anthraxx. Makefile | 1 + offload-build | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100755 offload-build diff --git a/Makefile b/Makefile index ba2d3e4..2306a17 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ IN_PROGS = \ BINPROGS = \ $(IN_PROGS) \ + offload-build \ sogrep CONFIGFILES = \ diff --git a/offload-build b/offload-build new file mode 100755 index 0000000..101a146 --- /dev/null +++ b/offload-build @@ -0,0 +1,107 @@ +#!/bin/bash +# +# offload-build - build a PKGBUILD on a remote server using makechrootpkg. +# +# Copyright (c) 2019 by Eli Schwartz <eschwartz@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# + + +# global defaults suitable for use by Arch staff +repo=extra +arch=x86_64 +server=dragon.archlinux.org + +die() { printf "error: $1\n" "${@:2}"; exit 1; } + +usage() { + cat <<- _EOF_ + Usage: ${BASH_SOURCE[0]##*/} [--repo REPO] [--arch ARCHITECTURE] [--server SERVER] -- [ARCHBUILD_ARGS] + + Build a PKGBUILD on a remote server using makechrootpkg. Requires a remote user + that can run archbuild without password auth. Options passed after a -- are + passed on to archbuild, and eventually to makechrootpkg. + + OPTIONS + -r, --repo Build against a specific repository (current: $repo) + -a, --arch Build against a specific architecture (current: $arch) + -s, --server Offload to a specific build server (current: $server) + -h, --help Show this help text +_EOF_ +} + +# option checking +while (( $# )); do + case $1 in + -h|--help) + usage + exit 0 + ;; + -r|--repo) + repo=$2 + shift 2 + ;; + -a|--arch) + arch=$2 + shift 2 + ;; + -s|--server) + server=$2 + shift 2 + ;; + --) + shift + break + ;; + *) + die "invalid argument: %s" "$1" + ;; + esac +done + +# multilib must be handled specially +if [[ $repo = multilib* ]]; then + arch= +fi + +archbuild_cmd=("${repo}${arch:+-$arch}-build" "$@") + +trap 'rm -rf $SRCPKGDEST' EXIT + +# Use a source-only tarball as an intermediate to transfer files. This +# guarantees the checksums are okay, and guarantees that all needed files are +# transferred, including local sources, install scripts, and changelogs. +export SRCPKGDEST=$(mktemp -d) +makepkg --source || die "unable to make source package" + +mapfile -t files < <( + # This is sort of bash golfing but it allows running a mildly complex + # command over ssh with a single connection. + cat "$SRCPKGDEST"/*.src.tar.gz | + ssh $server ' + temp="${XDG_CACHE_HOME:-$HOME/.cache}/offload-build" && + mkdir -p "$temp" && + temp=$(mktemp -d -p "$temp") && + cd "$temp" && + { + bsdtar --strip-components 1 -xvf - && + script -qefc "'"${archbuild_cmd[@]@Q}"'" /dev/null && + printf "%s\n" "" "-> build complete" && + printf "\t%s\n" "$temp"/* + } >&2 && + makepkg --packagelist +') + +(( ${#files[@]} )) && printf '%s\n' '' '-> copying files...' && scp "${files[@]/#/$server:}" . -- 2.21.0
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- v3: update manpage for new v3 parameters. Makefile | 1 + doc/offload-build.1.asciidoc | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 doc/offload-build.1.asciidoc diff --git a/Makefile b/Makefile index 2306a17..27cd90f 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ BASHCOMPLETION_LINKS = \ MANS = \ doc/lddd.1 \ doc/checkpkg.1 \ + doc/offload-build.1 \ doc/sogrep.1 \ doc/mkarchroot.1 \ doc/find-libdeps.1 \ diff --git a/doc/offload-build.1.asciidoc b/doc/offload-build.1.asciidoc new file mode 100644 index 0000000..3633faa --- /dev/null +++ b/doc/offload-build.1.asciidoc @@ -0,0 +1,52 @@ +offload-build(1) +================ + +Name +---- +offload-build - Build a PKGBUILD on a remote server using makechrootpkg + +Synopsis +-------- +offload-build [OPTIONS] -- [ARCHBUILD_OPTIONS] + +Description +----------- + +Build a PKGBUILD on a remote server using makechrootpkg. Requires a remote user +that can run archbuild in a non-interactive manner, e.g. must be able to +elevate permissions using passwordless sudo. + +Options +------- + +*-r, --repo* <reponame>:: + Build against a specific repository. The default is `extra`, to build packages using + the stable repositories via extra-x86_64-build. + +*-a, --arch* <architecture>:: + Build against a specific architecture. The default is `x86_64`, the only + architecture officially supported by Arch Linux. + +*-s, --server* <hostname>:: + Offload to a specific build server. The default is dragon.archlinux.org + which is used as part of the build toolchain for the official Arch Linux + repos. + +*-h, --help*:: + Show a help text. + +Passing options to archbuild +---------------------------- + +Options after a delimiting -- are passed on to archbuild on the remote. +archbuild in turn supports passing arguments on to makechrootpkg, which in turn +supports passing options to makepkg. Since each uses -- to delimit options that +are forwarded, make sure to escape them properly: + + `offload-build offload-args -- archbuild-args -- makechrootpkg-args -- makepkg-args` + +Example: To use a second `testing-x86_64-build` instance with another copydir: + + `offload-build -r testing -- -- -l <chroot_copy>` + +include::footer.asciidoc[] -- 2.21.0
participants (1)
-
Eli Schwartz