File loki.spec of Package loki
# Copyright (c) 2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%global provider_prefix gitlab.com/grafana/loki
%global import_path %{provider_prefix}
%define datadir /var/lib/%{name}
Name: loki
Version: 2.0.0
Release: 0
License: Apache-2.0
Summary: Like Prometheus, but for logs
Url: https://gitlab.com/grafana/loki
Group: Development/Languages/Other
Source0: %{name}-%{version}.tar.gz
Source2: loki.service
Source3: promtail.service
BuildRequires: golang-packaging
BuildRequires: systemd-devel
Requires(post): %fillup_prereq
%{?systemd_requires}
%{go_nostrip}
%{go_provides}
%package promtail
Group: Development/Languages/Other
Summary: Prometheus Loki log tailer
License: AGPL-3.0
%description
Grafana Loki is a set of components that can be composed into a fully featured logging stack.
%description promtail
Promtail is an agent which ships the contents of local logs to a private Loki instance or Grafana Cloud.
%prep
%autosetup
%build
go build -mod=vendor -buildmode=pie ./cmd/loki
go build -mod=vendor -buildmode=pie ./cmd/promtail
%install
install -D -m 755 loki %{buildroot}%{_bindir}/loki
install -D -m 755 promtail %{buildroot}%{_bindir}/promtail
install -D -m 644 %{S:2} %{buildroot}%{_unitdir}/loki.service
install -D -m 644 %{S:3} %{buildroot}%{_unitdir}/promtail.service
install -D -d -m 755 %{buildroot}%{_sbindir}
mkdir -p %{buildroot}%{_sysconfdir}/loki
mkdir -p %{buildroot}%{_sysconfdir}/promtail
install -D -m 644 ./cmd/loki/loki-local-config.yaml %{buildroot}%{_sysconfdir}/loki/config.yaml
install -D -m 644 ./cmd/promtail/promtail-local-config.yaml %{buildroot}%{_sysconfdir}/promtail/config.yaml
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcloki
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcpromtail
%pre
/usr/sbin/groupadd -r %{name} &>/dev/null || :
/usr/sbin/useradd -g %{name} -s /bin/false -r -c "Grafana Loki" -d %{datadir} %{name} &>/dev/null || :
%service_add_pre loki.service
%post
%service_add_post loki.service
%preun
%service_del_preun loki.service
%postun
%service_del_postun loki.service
%pre promtail
%service_add_pre promtail.service
%post promtail
%service_add_post promtail.service
%preun promtail
%service_del_preun promtail.service
%postun promtail
%service_del_postun promtail.service
%files
%defattr(-,root,root)
%doc README.md LICENSE
%{_sbindir}/rcloki
%{_bindir}/loki
%defattr(-,%{name},%{name})
%{_unitdir}/loki.service
%dir %{_sysconfdir}/loki
%config %{_sysconfdir}/loki/config.yaml
%files promtail
%defattr(-,root,root)
%doc README.md LICENSE
%{_sbindir}/rcpromtail
%{_bindir}/promtail
%defattr(-,%{name},%{name})
%{_unitdir}/promtail.service
%dir %{_sysconfdir}/promtail
%config %{_sysconfdir}/promtail/config.yaml
%changelog