Blob Blame History Raw
# Generated by go2rpm 1.5.0
%global shortname prometheus-alertmanager

# https://github.com/prometheus/alertmanager
%global goipath         github.com/prometheus/alertmanager
Version:                0.23.0

%gometa

%global common_description %{expand:
The Alertmanager handles alerts sent by client applications such as the
Prometheus server. It takes care of deduplicating, grouping, and routing them to
the correct receiver integrations such as email, PagerDuty, or OpsGenie. It also
takes care of silencing and inhibition of alerts.}

%global golicenses      COPYRIGHT.txt LICENSE NOTICE
%global godocs          doc examples MAINTAINERS.md README.md CHANGELOG.md SECURITY.md

Name:           %{goname}
Release:        %autorelease
Summary:        Prometheus Alertmanager

# Upstream license specification: Apache-2.0
License:        ASL 2.0
URL:            %{gourl}
Source0:        %{gosource}
Source1:        %{shortname}.service
Source2:        %{shortname}.sysusers
Source3:        %{shortname}.conf
Source4:        %{shortname}.yml
Source5:        README.templates
Source6:        %{shortname}.logrotate
# git clone https://github.com/prometheus/alertmanager
# cd alertmanager
# git checkout v%%{version}
# go mod vendor
# tar -czvf ../vendor-%%{version}.tar.gz vendor/
Source10:       vendor-%{version}.tar.gz
# Replace defaults paths for config files
Patch0:         defaults-paths.patch

ExcludeArch:    s390x

BuildRequires:  systemd-rpm-macros
Requires(pre):  shadow-utils

%description
%{common_description}

%prep
%goprep -k
%setup -q -T -D -a 10 -n alertmanager-%{version}
%patch0 -p1

%build
export GO111MODULE=on
export GOFLAGS=-mod=vendor
LDFLAGS="-X github.com/prometheus/common/version.Version=%{version}  \
         -X github.com/prometheus/common/version.Revision=%{release} \
         -X github.com/prometheus/common/version.Branch=tarball      \
         -X github.com/prometheus/common/version.BuildDate=$(date -u -d@$SOURCE_DATE_EPOCH +%%Y%%m%%d) "

for cmd in cmd/* ; do
  %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd
done

%install
install -m 0755 -vd                     %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/
mv %{buildroot}%{_bindir}/alertmanager %{buildroot}%{_bindir}/%{shortname}
pushd %{buildroot}%{_bindir}
ln -s %{shortname} alertmanager
popd

install -Dpm0644 %{S:4} %{buildroot}%{_sysconfdir}/prometheus/alertmanager.yml
install -Dpm0644 %{S:5} %{buildroot}%{_sysconfdir}/prometheus/alertmanager_templates/README.templates
mkdir -vp %{buildroot}%{_sharedstatedir}/prometheus/alertmanager

install -Dpm0644 %{S:1} %{buildroot}%{_unitdir}/%{shortname}.service
install -Dpm0644 %{S:2} %{buildroot}%{_sysusersdir}/%{shortname}.conf
install -Dpm0644 %{S:3} %{buildroot}%{_sysconfdir}/default/%{shortname}
install -Dpm0644 %{S:6} %{buildroot}%{_sysconfdir}/logrotate.d/%{shortname}
install -Dpm0644 template/default.tmpl %{buildroot}/%{_datadir}/prometheus/alertmanager/template/default.tmpl

# Build man pages.
mkdir -vp %{buildroot}/%{_mandir}/man1/
%{buildroot}%{_bindir}/%{shortname} --help-man > \
    %{buildroot}/%{_mandir}/man1/%{shortname}.1
%{buildroot}%{_bindir}/amtool --help-man > \
    %{buildroot}/%{_mandir}/man1/amtool.1
sed -i '/^  /d; /^.SH "NAME"/,+1c.SH "NAME"\nprometheus-alertmanager \\- The Prometheus alert manager' \
    %{buildroot}/%{_mandir}/man1/%{shortname}.1
sed -i '/^  /d; /^.SH "NAME"/,+1c.SH "NAME"\namtool \\- Tooling for the Prometheus alert manager' \
    %{buildroot}/%{_mandir}/man1/amtool.1
# Fix executable path in amtool examples
sed -i 's/\.\/amtool/amtool/' %{buildroot}/%{_mandir}/man1/amtool.1

%pre
%sysusers_create_compat %{SOURCE2}

%post
%systemd_post %{shortname}.service

%preun
%systemd_preun %{shortname}.service

%postun
%systemd_postun_with_restart %{shortname}.service

%files
%license COPYRIGHT.txt LICENSE NOTICE
%doc doc examples MAINTAINERS.md README.md CHANGELOG.md SECURITY.md
%{_bindir}/*
%{_datadir}/prometheus
%{_mandir}/man1/%{shortname}.1*
%{_mandir}/man1/amtool.1*
%dir %{_sysconfdir}/prometheus
%config(noreplace) %{_sysconfdir}/prometheus/alertmanager.yml
%config(noreplace) %{_sysconfdir}/logrotate.d/%{shortname}
%{_sysconfdir}/prometheus/alertmanager_templates
%config(noreplace) %{_sysconfdir}/default/%{shortname}
%dir %attr(0755,prometheus,prometheus) %{_sharedstatedir}/prometheus
%dir %attr(0755,prometheus,prometheus) %{_sharedstatedir}/prometheus/alertmanager
%{_sysusersdir}/%{shortname}.conf
%{_unitdir}/%{shortname}.service

%changelog
%autochangelog