feat: backend executor implement
This commit is contained in:
Executable
+102
@@ -0,0 +1,102 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
project_dir=$(CDPATH= cd -- "$script_dir/../.." && pwd)
|
||||
|
||||
version=0.1.0
|
||||
release="$(date -u +%Y%m%d%H%M%S).$(git -C "$project_dir" rev-parse --short=8 HEAD)"
|
||||
go_arch=$(go env GOARCH)
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--version)
|
||||
[ "$#" -ge 2 ] || { echo "--version requires a value" >&2; exit 2; }
|
||||
version=$2
|
||||
shift 2
|
||||
;;
|
||||
--release)
|
||||
[ "$#" -ge 2 ] || { echo "--release requires a value" >&2; exit 2; }
|
||||
release=$2
|
||||
shift 2
|
||||
;;
|
||||
--goarch)
|
||||
[ "$#" -ge 2 ] || { echo "--goarch requires a value" >&2; exit 2; }
|
||||
go_arch=$2
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
echo "usage: packaging/rpm/build-rpm.sh [--version <rpm-version>] [--release <rpm-release>] [--goarch amd64|arm64]"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "unknown argument: $1" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "$version" in
|
||||
""|*[!A-Za-z0-9._+]*|*-*)
|
||||
echo "RPM version contains an unsupported character: $version" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
case "$release" in
|
||||
""|*[!A-Za-z0-9._+]*|*-*)
|
||||
echo "RPM release contains an unsupported character: $release" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$go_arch" in
|
||||
amd64)
|
||||
rpm_arch=x86_64
|
||||
;;
|
||||
arm64)
|
||||
rpm_arch=aarch64
|
||||
;;
|
||||
*)
|
||||
echo "--goarch accepts only amd64 or arm64" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
mkdir -p "$project_dir/.build" "$project_dir/dist"
|
||||
build_dir=$(mktemp -d "$project_dir/.build/rpm.XXXXXX")
|
||||
trap 'rm -rf "$build_dir"' EXIT HUP INT TERM
|
||||
|
||||
top_dir="$build_dir/rpmbuild"
|
||||
sources_dir="$top_dir/SOURCES"
|
||||
temporary_dir="$build_dir/tmp"
|
||||
mkdir -p "$sources_dir" "$top_dir/BUILD" "$top_dir/BUILDROOT" "$top_dir/RPMS" "$top_dir/SRPMS" "$temporary_dir"
|
||||
|
||||
echo "Building static linux/$go_arch yms-daemon"
|
||||
(
|
||||
cd "$project_dir"
|
||||
GOCACHE="$build_dir/go-cache" CGO_ENABLED=0 GOOS=linux GOARCH="$go_arch" \
|
||||
go build -trimpath -ldflags="-s -w" -o "$sources_dir/yms-daemon" .
|
||||
)
|
||||
|
||||
install -m 0640 "$project_dir/packaging/etc/yms-daemon/yms-daemon.toml" "$sources_dir/yms-daemon.toml"
|
||||
install -m 0644 "$project_dir/packaging/systemd/yms-daemon.service" "$sources_dir/yms-daemon.service"
|
||||
install -m 0644 "$project_dir/packaging/systemd/yms-backend@.service" "$sources_dir/yms-backend@.service"
|
||||
install -m 0644 "$project_dir/packaging/tmpfiles.d/yms-daemon.conf" "$sources_dir/yms-daemon-tmpfiles.conf"
|
||||
|
||||
echo "Building $rpm_arch RPM version=$version release=$release"
|
||||
TMPDIR="$temporary_dir" rpmbuild -bb "$project_dir/packaging/rpm/yms-daemon.spec" \
|
||||
--target "$rpm_arch" \
|
||||
--define "_topdir $top_dir" \
|
||||
--define "_tmppath $temporary_dir" \
|
||||
--define "package_version $version" \
|
||||
--define "package_release $release"
|
||||
|
||||
rpm_path="$top_dir/RPMS/$rpm_arch/yms-daemon-$version-$release.$rpm_arch.rpm"
|
||||
if [ ! -f "$rpm_path" ]; then
|
||||
echo "rpmbuild did not create the expected RPM: $rpm_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
output_path="$project_dir/dist/$(basename "$rpm_path")"
|
||||
install -m 0644 "$rpm_path" "$output_path"
|
||||
echo "$output_path"
|
||||
Reference in New Issue
Block a user