File golang-github-prometheus-node_exporter.spec of Package golang-github-prometheus-node_exporter

#
# spec file for package golang-github-prometheus-node_exporter
#
# Copyright (c) 2025 SUSE LLC
# Copyright (c) 2017 Silvio Moioli <moio@suse.com>
#
# 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/
#

%if 0%{?rhel}
# build ids are not currently generated
# https://code.google.com/p/go/issues/detail?id=5238
%undefine _missing_build_ids_terminate_build
%global debug_package %{nil}
%define __debug_install_post %{nil}
%endif

Name:           golang-github-prometheus-node_exporter
Version:        1.9.1
Release:        0
Summary:        Prometheus exporter for machine metrics
License:        Apache-2.0
Group:          System/Management
URL:            https://github.com/prometheus/node_exporter
Source:         %{URL}/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        prometheus-node_exporter.service
Source4:        prometheus-node_exporter.sysconfig
%if 0%{?rhel}
Patch0:         change-go-requires.patch
%endif
BuildRequires:  fdupes
%if 0%{?suse_version} == 1315 && !0%{?is_opensuse}
BuildRequires:  gcc11-c++
%endif
BuildRequires:  golang-github-prometheus-promu >= 0.12.0
%if 0%{?rhel}
BuildRequires:  golang >= 1.22
%else
BuildRequires:  golang(API) >= 1.23
%endif
%{?systemd_ordering}
%if 0%{?suse_version}
Requires(post): %fillup_prereq
Requires(pre):  user(prometheus)
Requires(pre):  group(prometheus)
%endif
Provides:       node_exporter
Provides:       prometheus(node_exporter)
ExcludeArch:    s390
#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates
%endif

%if 0%{?debian} || 0%{?ubuntu}
ExclusiveArch:  do_not_build
%endif

%description
Prometheus exporter for hardware and OS metrics exposed by *NIX kernels,
written in Go with pluggable metric collectors.

%prep
%autosetup -a1 -p1 -n node_exporter-%{version}

%build
%ifarch i586 s390x armv7hl armv7l armv7l:armv6l:armv5tel armv6hl
export BUILD_CGO_FLAG="--cgo"
%if 0%{?suse_version} == 1315 && !0%{?is_opensuse}
export CC=gcc-11
export CXX=g++-11
%endif
%endif
export GOFLAGS="-buildmode=pie"
promu build -v $BUILD_CGO_FLAG

%install
install -D -m 0755 %{_builddir}/node_exporter-%{version}/node_exporter %{buildroot}/%{_bindir}/node_exporter
install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/prometheus-node_exporter.service
%if 0%{?rhel}
install -D -m 0644 %{SOURCE4} %{buildroot}%{_sysconfdir}/prometheus-node_exporter
%else
install -D -m 0644 %{SOURCE4} %{buildroot}%{_fillupdir}/sysconfig.prometheus-node_exporter
%endif
%fdupes %{buildroot}

%check
go test -x .
./node_exporter --version

%pre
%if 0%{?rhel}
getent group prometheus >/dev/null || %{_sbindir}/groupadd -r prometheus
getent passwd prometheus >/dev/null || %{_sbindir}/useradd -r -g prometheus -d %{_localstatedir}/lib/prometheus -M -s /sbin/nologin prometheus
%else
%service_add_pre prometheus-node_exporter.service
%endif

%if 0%{?rhel}
%post
%systemd_post prometheus-node_exporter.service
%preun
%systemd_preun prometheus-node_exporter.service
%postun
%systemd_postun prometheus-node_exporter.service
%else
%post
%service_add_post prometheus-node_exporter.service
%fillup_only -n prometheus-node_exporter

%preun
%service_del_preun prometheus-node_exporter.service

%postun
%service_del_postun prometheus-node_exporter.service
%endif

%files
%doc README.md
%license LICENSE
%{_bindir}/node_exporter
%{_unitdir}/prometheus-node_exporter.service

%if 0%{?rhel}
%{_sysconfdir}/prometheus-node_exporter
%else
%{_fillupdir}/sysconfig.prometheus-node_exporter
%endif

%changelog
openSUSE Build Service is sponsored by