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"
|
||||
@@ -0,0 +1,79 @@
|
||||
%global debug_package %{nil}
|
||||
%global __strip /bin/true
|
||||
%global _binary_payload w9.gzdio
|
||||
|
||||
%{!?package_version:%global package_version 0.1.0}
|
||||
%{!?package_release:%global package_release 1}
|
||||
|
||||
Name: yms-daemon
|
||||
Version: %{package_version}
|
||||
Release: %{package_release}
|
||||
Summary: YMS update daemon
|
||||
License: Proprietary
|
||||
Requires: systemd
|
||||
|
||||
Source0: yms-daemon
|
||||
Source1: yms-daemon.toml
|
||||
Source2: yms-daemon.service
|
||||
Source3: yms-backend@.service
|
||||
Source4: yms-daemon-tmpfiles.conf
|
||||
|
||||
%description
|
||||
Transactional update daemon and native backend systemd units for YMS installations.
|
||||
|
||||
%prep
|
||||
|
||||
%build
|
||||
|
||||
%install
|
||||
install -d -m 0755 %{buildroot}/usr/bin
|
||||
install -m 0755 %{SOURCE0} %{buildroot}/usr/bin/yms-daemon
|
||||
|
||||
install -d -m 0755 %{buildroot}/etc/yms-daemon
|
||||
install -m 0640 %{SOURCE1} %{buildroot}/etc/yms-daemon/yms-daemon.toml
|
||||
|
||||
install -d -m 0755 %{buildroot}/etc/systemd/system
|
||||
install -m 0644 %{SOURCE2} %{buildroot}/etc/systemd/system/yms-daemon.service
|
||||
install -m 0644 %{SOURCE3} %{buildroot}/etc/systemd/system/yms-backend@.service
|
||||
|
||||
install -d -m 0755 %{buildroot}/etc/tmpfiles.d
|
||||
install -m 0644 %{SOURCE4} %{buildroot}/etc/tmpfiles.d/yms-daemon.conf
|
||||
|
||||
install -d -m 0755 %{buildroot}/home/yms/dump
|
||||
|
||||
%post
|
||||
tmpfiles_path="$(command -v systemd-tmpfiles 2>/dev/null || :)"
|
||||
if [ -n "$tmpfiles_path" ]; then
|
||||
"$tmpfiles_path" --create /etc/tmpfiles.d/yms-daemon.conf >/dev/null 2>&1 || :
|
||||
fi
|
||||
systemctl_path="$(command -v systemctl 2>/dev/null || :)"
|
||||
if [ -n "$systemctl_path" ]; then
|
||||
"$systemctl_path" daemon-reload >/dev/null 2>&1 || :
|
||||
fi
|
||||
|
||||
%preun
|
||||
if [ "$1" -eq 0 ]; then
|
||||
systemctl_path="$(command -v systemctl 2>/dev/null || :)"
|
||||
if [ -n "$systemctl_path" ]; then
|
||||
"$systemctl_path" disable --now yms-daemon.service >/dev/null 2>&1 || :
|
||||
fi
|
||||
fi
|
||||
|
||||
%postun
|
||||
systemctl_path="$(command -v systemctl 2>/dev/null || :)"
|
||||
if [ -n "$systemctl_path" ]; then
|
||||
"$systemctl_path" daemon-reload >/dev/null 2>&1 || :
|
||||
fi
|
||||
|
||||
%files
|
||||
%dir %attr(0755,root,root) /etc/yms-daemon
|
||||
%config(noreplace) %attr(0640,root,root) /etc/yms-daemon/yms-daemon.toml
|
||||
%attr(0644,root,root) /etc/systemd/system/yms-daemon.service
|
||||
%attr(0644,root,root) /etc/systemd/system/yms-backend@.service
|
||||
%attr(0644,root,root) /etc/tmpfiles.d/yms-daemon.conf
|
||||
%attr(0755,root,root) /usr/bin/yms-daemon
|
||||
%dir %attr(0755,root,root) /home/yms/dump
|
||||
|
||||
%changelog
|
||||
* Sun Aug 16 2026 YMS Engineering
|
||||
- Add the initial native backend update daemon package.
|
||||
Reference in New Issue
Block a user