%define         debug_package %{nil}

Name:           prometheus-ha_cluster_exporter
# Version will be processed via set_version source service
Version:        1.3.1
Release:        1
Summary:        Prometheus exporter for Pacemaker HA clusters metrics
License:        Apache-2.0
URL:            https://github.com/ClusterLabs/ha_cluster_exporter
Source:         https://github.com/ClusterLabs/ha_cluster_exporter/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
# tar -xvf Source0
# run 'go mod vendor' in it
# tar -czvf promu-vendor.tar.gz vendor
Source1:        vendor.tar.gz

BuildRequires:  golang >= 1.14
BuildRequires:  systemd

Provides:       ha_cluster_exporter = %{version}-%{release}
Provides:       prometheus(ha_cluster_exporter) = %{version}-%{release}
ExclusiveArch:  aarch64 x86_64

%description
Prometheus exporter for Pacemaker HA clusters metrics

%prep
%setup -q -T -n %{name}-%{version} -b 0
tar -xzvf %{SOURCE1}

%define shortname ha_cluster_exporter

%build
export CGO_ENABLED=0
go build -mod=vendor \
         -buildmode=pie \
         -ldflags="-s -w -X github.com/prometheus/common/version.Version=%{version}" \
         -o %{shortname}

%install
install -D -m 755 %{shortname} %{buildroot}%{_bindir}/%{shortname}
install -D -m 644 %{shortname}.service %{buildroot}%{_unitdir}/%{name}.service
install -D -m 644 %{shortname}.sysconfig %{buildroot}%{_sysconfdir}/sysconfig.%{name}

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun %{name}.service

%files
%doc *.md
%doc doc/*
%doc LICENSE
%{_bindir}/%{shortname}
%{_unitdir}/%{name}.service
%{_sysconfdir}/sysconfig.%{name}

%changelog
* Mon Nov 27 2023  <zouzhimin@kylinos.cn> -1.3.1-1
- init package 1.3.1 release
