Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#14) Add basic packager for el8 and 9 #16

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions ABTaskFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: build_tasks
description: Choria Build Tasks

commands:
- name: dependencies
type: parent
description: Manage dependencies
aliases: [d]
commands:
- name: update
description: Update dependencies
type: exec
aliases: [up]
dir: "{{ AppDir }}"
flags:
- name: verbose
description: Log verbosely
short: v
bool: true
- name: proxy
description: Enable using go proxy
bool: true
default: "true"
script: |
. "{{ BashHelperPath }}"

ab_announce Updating all dependencies
echo

{{ if eq .Flags.proxy false }}
export GOPROXY=direct
ab_say Disabling go mod proxy
{{ end }}

go get -u -n -a -t {{- if .Flags.verbose }} -d -x {{ end }} ./...

ab_say Running go mod tidy

go mod tidy

- name: build
type: parent
aliases: [b]
description: Code build steps
commands:
- name: binary
description: Build a basic test binary
type: exec
dir: "{{ AppDir }}"
aliases: [bin]
banner: |
>>>
>>> Building 'tally' locally
>>>
>>> Target: {{ if .Flags.target }}{{ .Flags.target }}{{else}}host{{end}}
>>>
flags:
- name: target
description: Target platform to build for
enum: ["linux/amd64", "linux/arm64"]
short: T
- name: verbose
description: Logs packages being build
bool: true
short: v
script: |
set -e

. "{{ BashHelperPath }}"

{{ if eq .Flags.target "linux/amd64" }}
export GOOS=linux
export GOARCH=amd64
{{ else if eq .Flags.target "linux/arm64" }}
export GOOS=linux
export GOARCH=arm64
{{ end }}

{{ if .Flags.verbose }}
ab_say Packages being build
{{ end }}

go build \
{{ if .Flags.verbose }}-v{{ end }} \
-ldflags="-s -w \
-X 'github.com/choria-io/tally.version=0.98.0.$(date +%s)' \
" -o tally

ab_say Build completed

echo
ls -l tally
echo
file tally
echo
28 changes: 28 additions & 0 deletions packager/buildspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
foss:
compile_targets:
defaults:
output: tally-{{version}}-{{os}}-{{arch}}
strip: true

64bit_linux:
os: linux
arch: amd64

packages:
defaults:
name: tally
bindir: /usr/sbin
etcdir: /etc/tally
release: 1

el8_64:
dist: el8
template: el/el8
target_arch: x86_64
binary: 64bit_linux

el9_64:
dist: el9
template: el/el9
target_arch: x86_64
binary: 64bit_linux
10 changes: 10 additions & 0 deletions packager/templates/el/el8/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
required_properties:
- name
- etcdir
- bindir
- release
- dist

artifacts:
- /usr/src/redhat/**/*.rpm
- /root/rpmbuild/**/*.rpm
14 changes: 14 additions & 0 deletions packager/templates/el/el8/tally.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=The Choria Tally Service
After=network.target

[Service]
EnvironmentFile=/etc/sysconfig/{{cpkg_name}}
StandardOutput=syslog
StandardError=syslog
User=root
Group=root
ExecStart={{cpkg_bindir}}/{{cpkg_name}} --component '*' --port 8080 --prefix choria_tally --config={{cpkg_etcdir}}/choria.conf

[Install]
WantedBy=multi-user.target
83 changes: 83 additions & 0 deletions packager/templates/el/el8/tally.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
%define debug_package %{nil}
%define pkgname {{cpkg_name}}
%define version {{cpkg_version}}
%define bindir {{cpkg_bindir}}
%define etcdir {{cpkg_etcdir}}
%define release {{cpkg_release}}
%define dist {{cpkg_dist}}
%define binary {{cpkg_binary}}
%define tarball {{cpkg_tarball}}

Name: %{pkgname}
Version: %{version}
Release: %{release}.%{dist}
Summary: The Choria Tally Service
License: Apache-2.0
URL: https://choria.io
Group: System Tools
Packager: R.I.Pienaar <[email protected]>
Source0: %{tarball}
BuildRoot: %{_tmppath}/%{pkgname}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires(pre): /usr/sbin/useradd, /usr/bin/getent
Requires(postun): /usr/sbin/userdel

%description
A service that passively listen for events on a Choria network and expose the
observed data via a Prometheus compatible exporter.

%prep
%setup -q

%build

%install
rm -rf %{buildroot}
%{__install} -d -m0755 %{buildroot}/etc/sysconfig
%{__install} -d -m0755 %{buildroot}/usr/lib/systemd/system
%{__install} -d -m0755 %{buildroot}/etc/logrotate.d
%{__install} -d -m0755 %{buildroot}%{bindir}
%{__install} -d -m0755 %{buildroot}%{etcdir}
%{__install} -d -m0755 %{buildroot}/var/log/%{pkgname}
%{__install} -m0644 dist/%{pkgname}.service %{buildroot}/usr/lib/systemd/system/%{pkgname}.service
%{__install} -m0644 dist/sysconfig %{buildroot}/etc/sysconfig/%{pkgname}
%{__install} -m0644 dist/%{pkgname}-logrotate %{buildroot}/etc/logrotate.d/%{pkgname}
%{__install} -m0755 %{binary} %{buildroot}%{bindir}/%{pkgname}
%{__install} -m0755 dist/choria.conf %{buildroot}%{etcdir}/choria.conf

touch %{buildroot}/var/log/%{pkgname}/%{pkgname}.log

%clean
rm -rf %{buildroot}

%post
if [ $1 -eq 1 ] ; then
systemctl --no-reload preset %{pkgname} >/dev/null 2>&1 || :
fi

/bin/systemctl --system daemon-reload >/dev/null 2>&1 || :

if [ $1 -ge 1 ]; then
/bin/systemctl try-restart %{pkgname} >/dev/null 2>&1 || :;
fi

%preun
if [ $1 -eq 0 ] ; then
systemctl --no-reload disable --now %{pkgname} >/dev/null 2>&1 || :
/usr/sbin/userdel %{pkgname} || :
fi

%pre
/usr/bin/getent group %{pkgname} || /usr/sbin/groupadd -r %{pkgname}
/usr/bin/getent passwd %{pkgname} || /usr/sbin/useradd -r -s /sbin/nologin -d /home/%{pkgname} -g %{pkgname} -c "Choria Tally Service" %{pkgname}

%files
%{bindir}/%{pkgname}
/etc/logrotate.d/%{pkgname}
/usr/lib/systemd/system/%{pkgname}.service
%attr(755, %{pkgname}, %{pkgname})/var/log/%{pkgname}
%config(noreplace) /etc/sysconfig/%{pkgname}
%config(noreplace) %{etcdir}

%changelog
* Fri Nov 08 2024 R.I.Pienaar <[email protected]>
- Initial Release
10 changes: 10 additions & 0 deletions packager/templates/el/el9/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
required_properties:
- name
- etcdir
- bindir
- release
- dist

artifacts:
- /usr/src/redhat/**/*.rpm
- /root/rpmbuild/**/*.rpm
14 changes: 14 additions & 0 deletions packager/templates/el/el9/tally.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=The Choria Tally Service
After=network.target

[Service]
EnvironmentFile=/etc/sysconfig/{{cpkg_name}}
StandardOutput=syslog
StandardError=syslog
User=root
Group=root
ExecStart={{cpkg_bindir}}/{{cpkg_name}} --component '*' --port 8080 --prefix choria_tally --config={{cpkg_etcdir}}/choria.conf

[Install]
WantedBy=multi-user.target
83 changes: 83 additions & 0 deletions packager/templates/el/el9/tally.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
%define debug_package %{nil}
%define pkgname {{cpkg_name}}
%define version {{cpkg_version}}
%define bindir {{cpkg_bindir}}
%define etcdir {{cpkg_etcdir}}
%define release {{cpkg_release}}
%define dist {{cpkg_dist}}
%define binary {{cpkg_binary}}
%define tarball {{cpkg_tarball}}

Name: %{pkgname}
Version: %{version}
Release: %{release}.%{dist}
Summary: The Choria Tally Service
License: Apache-2.0
URL: https://choria.io
Group: System Tools
Packager: R.I.Pienaar <[email protected]>
Source0: %{tarball}
BuildRoot: %{_tmppath}/%{pkgname}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires(pre): /usr/sbin/useradd, /usr/bin/getent
Requires(postun): /usr/sbin/userdel

%description
A service that passively listen for events on a Choria network and expose the
observed data via a Prometheus compatible exporter.

%prep
%setup -q

%build

%install
rm -rf %{buildroot}
%{__install} -d -m0755 %{buildroot}/etc/sysconfig
%{__install} -d -m0755 %{buildroot}/usr/lib/systemd/system
%{__install} -d -m0755 %{buildroot}/etc/logrotate.d
%{__install} -d -m0755 %{buildroot}%{bindir}
%{__install} -d -m0755 %{buildroot}%{etcdir}
%{__install} -d -m0755 %{buildroot}/var/log/%{pkgname}
%{__install} -m0644 dist/%{pkgname}.service %{buildroot}/usr/lib/systemd/system/%{pkgname}.service
%{__install} -m0644 dist/sysconfig %{buildroot}/etc/sysconfig/%{pkgname}
%{__install} -m0644 dist/%{pkgname}-logrotate %{buildroot}/etc/logrotate.d/%{pkgname}
%{__install} -m0755 %{binary} %{buildroot}%{bindir}/%{pkgname}
%{__install} -m0755 dist/choria.conf %{buildroot}%{etcdir}/choria.conf

touch %{buildroot}/var/log/%{pkgname}/%{pkgname}.log

%clean
rm -rf %{buildroot}

%post
if [ $1 -eq 1 ] ; then
systemctl --no-reload preset %{pkgname} >/dev/null 2>&1 || :
fi

/bin/systemctl --system daemon-reload >/dev/null 2>&1 || :

if [ $1 -ge 1 ]; then
/bin/systemctl try-restart %{pkgname} >/dev/null 2>&1 || :;
fi

%preun
if [ $1 -eq 0 ] ; then
systemctl --no-reload disable --now %{pkgname} >/dev/null 2>&1 || :
/usr/sbin/userdel %{pkgname} || :
fi

%pre
/usr/bin/getent group %{pkgname} || /usr/sbin/groupadd -r %{pkgname}
/usr/bin/getent passwd %{pkgname} || /usr/sbin/useradd -r -s /sbin/nologin -d /home/%{pkgname} -g %{pkgname} -c "Choria Tally Service" %{pkgname}

%files
%{bindir}/%{pkgname}
/etc/logrotate.d/%{pkgname}
/usr/lib/systemd/system/%{pkgname}.service
%attr(755, %{pkgname}, %{pkgname})/var/log/%{pkgname}
%config(noreplace) /etc/sysconfig/%{pkgname}
%config(noreplace) %{etcdir}

%changelog
* Fri Nov 08 2024 R.I.Pienaar <[email protected]>
- Initial Release
13 changes: 13 additions & 0 deletions packager/templates/el/global/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -x

TARGET_ARCH="{{cpkg_target_arch}}"
TARBALL="{{cpkg_tarball}}"

if [ ! -z $TARGET_ARCH ]
then
rpmbuild --target "${TARGET_ARCH}" -ta "${TARBALL}"
else
rpmbuild -ta "${TARBALL}"
fi
1 change: 1 addition & 0 deletions packager/templates/el/global/choria.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# add tally user specific choria configuration
Empty file.
6 changes: 6 additions & 0 deletions packager/templates/el/global/tally-logrotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/var/log/{{cpkg_name}}/*.log {
copytruncate
daily
notifempty
rotate 10
}
Loading