File blackbox_exporter.spec of Package blackbox_exporter
%define realname blackbox_exporter
%define realver 0.25.0
%define srcext tar.gz
%define promu_ver 0.17.0
%if %{defined suse_version}
%if ! %{defined _fillupdir}
%define _fillupdir /var/adm/fillup-templates
%endif
%define sysconffile %{_fillupdir}/sysconfig.blackbox_exporter
%else
%define sysconffile %{_sysconfdir}/sysconfig/blackbox_exporter
%endif
# Common info
Name: %{realname}
Version: %{realver}
Release: wiz%{?extraver:0.}1%{?dist}
License: Apache-2.0
Group: System/Monitoring
URL: https://github.com/prometheus/blackbox_exporter
Summary: Blackbox prober exporter
# Install-time parameters
Requires: systemd
%if "%{expand:%_vendor}" == "suse"
Requires: %{fillup_prereq}
%endif
# Build-time parameters
BuildRequires: go >= 1.10
BuildRequires: systemd-devel
BuildRoot: %{_tmppath}/%{name}-root
Source0: https://codeload.github.com/prometheus/blackbox_exporter/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}
Source1: https://codeload.github.com/prometheus/promu/%{srcext}/refs/tags/v%{promu_ver}#/promu-%{promu_ver}.%{srcext}
# cd blackbox_exporter; go mod vendor -v && tar -Jcvf ../bb-vendor.tar.xz vendor && rm -rf vendor/; cd -
Source2: bb-vendor.tar.xz
# cd promu; go mod vendor -v && tar -Jcvf ../promu-vendor.tar.xz vendor && rm -rf vendor/; cd -
Source3: promu-vendor.tar.xz
# Configs
Source12: blackbox_exporter.sysconfig
Source13: blackbox_exporter.service
%description
The blackbox exporter allows blackbox probing of endpoints over HTTP, HTTPS,
DNS, TCP and ICMP.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a1 -a2
# Add flags to skip debug symbols
%{__sed} -ri \
-e '/^go:/ a\ cgo: true' \
-e '/^build:/ a\ static: false' \
-e '/^\s*flags:/ s|$| -buildmode=pie -gcflags=all=-dwarf=false -v|' \
-e "/^\s*ldflags:/ a\ -s\n -w\n -linkmode external\n -extldflags '$_LDFLAGS'" \
.promu.yml
# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS='%{optflags}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,-z,now -Wl,-z,relro'
export GOPATH=$(pwd -P)/gomodules
export GOCACHE=$(pwd -P)/.gocache
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS="$_CFLAGS"
export CGO_LDFLAGS="$_LDFLAGS"
cd promu-%{promu_ver}
tar -Jxf %{S:3}
go build -v -mod=vendor -o ../bin/promu
cd ..
%{__make} %{?_smp_mflags} build \
PROMU=$(pwd -P)/bin/promu
# Install built stuff
%install
# Install binaries
%{__install} -D -m0755 blackbox_exporter-%{version} %{buildroot}%{_bindir}/blackbox_exporter
# Install configuration file
%{__install} -D -m0644 blackbox.yml %{buildroot}%{_sysconfdir}/prometheus/blackbox.yml
# Install sysconfig file
%{__install} -D -m0644 %{S:12} %{buildroot}%{sysconffile}
# Systemd unit file
%{__install} -D -m0644 %{S:13} %{buildroot}%{_unitdir}/blackbox_exporter.service
# Cleanup
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
# Files list
%files
%defattr(-,root,root)
%license LICENSE
%doc CONFIGURATION.md MAINTAINERS.md NOTICE README.md
%dir %{_sysconfdir}/prometheus
%config(noreplace) %{_sysconfdir}/prometheus/blackbox.yml
%{_bindir}/*
%config(noreplace) %{sysconffile}
%{_unitdir}/blackbox_exporter.service
%if "%{expand:%_vendor}" == "suse"
%pre
%{service_add_pre blackbox_exporter.service}
%post
%{fillup_only}
%{service_add_post blackbox_exporter.service}
%preun
%{service_del_preun blackbox_exporter.service}
%{stop_on_removal blackbox_exporter.service}
%postun
%{service_del_postun blackbox_exporter.service}
%{restart_on_update blackbox_exporter.service}
%endif
%changelog