add rpm build via docker

This commit is contained in:
Gabriele Iannetti 2022-11-24 10:42:43 +01:00
parent 6a0e85dd89
commit 916eaff588
7 changed files with 156 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
build/
ipmi_exporter ipmi_exporter
*.tar.gz *.tar.gz

15
docker/RPM-Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM centos:7
MAINTAINER jknedlik <j.knedlik@gsi.de>, Gabriele Iannetti <g.iannetti@gsi.de>
WORKDIR /tmp
RUN yum install -y git make gcc rpm-build which
RUN curl -LO https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
RUN tar -C /usr/local -xvzf go1.18.1.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin
COPY . /go/ipmi_exporter
WORKDIR /go/ipmi_exporter
RUN rpm/build.sh
RUN mkdir /rpm
ENTRYPOINT ["/bin/sh"]
ENTRYPOINT ["cp"]
CMD ["-r","/root/rpmbuild/RPMS/x86_64/","/rpm/build"]

View File

@ -0,0 +1,27 @@
# Configuration file for ipmi_exporter
modules:
default:
collectors:
- bmc
- ipmi
- dcmi
- chassis
- sel
collector_cmd:
bmc: sudo
ipmi: sudo
dcmi: sudo
chassis: sudo
sel: sudo
custom_args:
bmc:
- "bmc-info"
ipmi:
- "ipmimonitoring"
dcmi:
- "ipmi-dcmi"
chassis:
- "ipmi-chassis"
sel:
- "ipmi-sel"

23
rpm/build.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
set -e
export VERSION=$(cat VERSION)
export promdir=prometheus-ipmi-exporter-$VERSION
export builddir=$HOME/rpmbuild
make build
sed -i "s/VERSION/$(cat VERSION)/" rpm/prometheus-ipmi-exporter.spec
mkdir -p $builddir/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
mkdir -p $builddir/SOURCES/$promdir/usr/bin
mkdir -p $builddir/SOURCES/$promdir/usr/lib/systemd/system
mkdir -p $builddir/SOURCES/$promdir/etc/sysconfig
mkdir -p $builddir/SOURCES/$promdir/etc/sudoers.d
cp rpm/prometheus-ipmi-exporter.spec $builddir/SPECS/
cp systemd/prometheus-ipmi-exporter.service $builddir/SOURCES/$promdir/usr/lib/systemd/system/
cp sudoers/prometheus-ipmi-exporter $builddir/SOURCES/$promdir/etc/sudoers.d/
cp prometheus-ipmi-exporter.yml $builddir/SOURCES/$promdir/etc/sysconfig/
cp ipmi_exporter $builddir/SOURCES/$promdir/usr/bin/
cd $builddir/SOURCES
tar -czvf $promdir.tar.gz $promdir
cd $builddir
echo build dir is $builddir
ls -la $builddir/SOURCES
rpmbuild -ba $builddir/SPECS/prometheus-ipmi-exporter.spec

View File

@ -0,0 +1,68 @@
%define __spec_install_post %{nil}
%define debug_package %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Name: prometheus-ipmi-exporter
Version: VERSION
Release: 1.0%{?dist}
Summary: Remote IPMI exporter for Prometheus
Group: Monitoring
License: The MIT License
URL: https://github.com/prometheus-community/ipmi_exporter
Source0: %{name}-%{version}.tar.gz
Requires(pre): shadow-utils
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
%{?systemd_requires}
BuildRequires: systemd
BuildRoot: %{_tmppath}/%{name}-%{version}-1-root
%description
Remote IPMI exporter for Prometheus
%prep
%setup -q
%build
# Empty section.
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_unitdir}/
cp usr/lib/systemd/system/%{name}.service %{buildroot}%{_unitdir}/
# in builddir
cp -a * %{buildroot}
%clean
rm -rf %{buildroot}
%pre
getent group prometheus >/dev/null || groupadd -r prometheus
getent passwd prometheus >/dev/null || \
useradd -r -g prometheus -d /dev/null -s /sbin/nologin \
-c "Prometheus exporter user" prometheus
cp etc/sudoers.d/%{name} /etc/sudoers.d/%{name}
exit 0
%post
systemctl enable %{name}.service
systemctl start %{name}.service
%preun
%systemd_preun %{name}.service
%postun
%systemd_postun_with_restart %{name}.service
%files
%defattr(-,root,root,-)
%config /etc/sysconfig/prometheus-ipmi-exporter.yml
%attr(0440, root, root) /etc/sudoers.d/prometheus-ipmi-exporter
%{_bindir}/ipmi_exporter
%{_unitdir}/%{name}.service

View File

@ -0,0 +1,10 @@
# !log_allowed setting should be used instead, but is only supported by version 1.8.29 or higher.
Defaults:prometheus !syslog
prometheus ALL = NOPASSWD: /usr/sbin/ipmimonitoring,\
/usr/sbin/ipmi-sensors,\
/usr/sbin/ipmi-dcmi,\
/usr/sbin/ipmi-raw,\
/usr/sbin/bmc-info,\
/usr/sbin/ipmi-chassis,\
/usr/sbin/ipmi-sel

View File

@ -0,0 +1,12 @@
[Unit]
Description=Prometheus IPMI Exporter
Documentation=https://github.com/prometheus-community/ipmi_exporter
[Service]
ExecStart=/usr/bin/ipmi_exporter --config.file=/etc/sysconfig/prometheus-ipmi-exporter.yml
User=prometheus
Restart=always
[Install]
WantedBy=multi-user.target