Refactor rpm build process

* Move rpm build files to contrib/rpm/ directory structure
* Update top level README.md for referencing to contrib/rpm/README.md for rpm build
This commit is contained in:
Gabriele Iannetti 2022-12-02 14:19:17 +01:00
parent 188c9ef67f
commit b72f43d24f
9 changed files with 79 additions and 48 deletions

View File

@ -45,28 +45,9 @@ You can build a Docker container with the included `docker` make target:
This will not even require Go tooling on the host. See the included [docker This will not even require Go tooling on the host. See the included [docker
compose example](docker-compose.yml) for how to use the resulting container. compose example](docker-compose.yml) for how to use the resulting container.
### Building RPM Package ### Building a RPM Package
The RPM package build targets to run the exporter locally with sudo permissions to expose most metrics. See [how to build a RPM package](contrib/rpm/README.md).
#### Directly on CentOS with rpmbuild
Build script is located in `rpm/build.sh`.
The RPM package will be available under `$HOME/rpmbuild/`.
#### Docker Build Container
The build container uses CentOS7.
```bash
# from repo base dir run
sudo docker build -t rpm_dock -f docker/RPM-Dockerfile .
sudo docker run -v $PWD:/rpm -it rpm_dock
```
The RPM package will be available under `build/`.
## Running ## Running

25
contrib/rpm/README.md Normal file
View File

@ -0,0 +1,25 @@
# Building a RPM Package
The RPM package build targets to run the exporter locally as Prometheus user with sudo permissions to expose most metrics.
For building a RPM package a build script and [Docker](https://www.docker.com/) build container are available.
NOTE:
> The build script and the Docker build image must be executed from the project base directory!
## CentOS with rpmbuild
A Build script is located in `contrib/rpm/build.sh` to be executed on a CentOS-based host with rpmbuild tool.
The RPM package will be available under `$HOME/rpmbuild/`.
## Docker Build Container
A Docker build container is provided for CentOS7.
```bash
sudo docker build -t centos7_rpmbuild_ipmi_exporter -f contrib/rpm/docker/Dockerfile-centos7 .
sudo docker run -v $PWD/contrib/rpm/build:/outdir -it centos7_rpmbuild_ipmi_exporter
```
The RPM package will be available under `contrib/rpm/build/`.

49
contrib/rpm/build.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
set -e
function do_checks {
info_msg="The build script must be executed from the projects base directory!"
if [ -z "$VERSION" ]; then
echo "ERROR: Build failed! VERSION file not found" >&2
echo "INFO: $info_msg"
exit 1
fi
if [ ! -d "$CONTRIB_DIR" ]; then
echo "ERROR: Build failed! Directory does not exist: $CONTRIB_DIR" >&2
echo "INFO: $info_msg"
exit 1
fi
}
export VERSION=$(cat VERSION)
export BUILD_DIR=$HOME/rpmbuild
export CONTRIB_DIR="contrib/rpm"
export PACKAGE_DIR=prometheus-ipmi-exporter-$VERSION
do_checks
make build
mkdir -p $BUILD_DIR/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
mkdir -p $BUILD_DIR/SOURCES/$PACKAGE_DIR/usr/bin
mkdir -p $BUILD_DIR/SOURCES/$PACKAGE_DIR/usr/lib/systemd/system
mkdir -p $BUILD_DIR/SOURCES/$PACKAGE_DIR/etc/sysconfig
mkdir -p $BUILD_DIR/SOURCES/$PACKAGE_DIR/etc/sudoers.d
sed "s/VERSION/$VERSION/" $CONTRIB_DIR/prometheus-ipmi-exporter.spec > $BUILD_DIR/SPECS/prometheus-ipmi-exporter.spec
cp $CONTRIB_DIR/systemd/prometheus-ipmi-exporter.service $BUILD_DIR/SOURCES/$PACKAGE_DIR/usr/lib/systemd/system/
cp $CONTRIB_DIR/sudoers/prometheus-ipmi-exporter $BUILD_DIR/SOURCES/$PACKAGE_DIR/etc/sudoers.d/
cp $CONTRIB_DIR/config/prometheus-ipmi-exporter.yml $BUILD_DIR/SOURCES/$PACKAGE_DIR/etc/sysconfig/
cp ipmi_exporter $BUILD_DIR/SOURCES/$PACKAGE_DIR/usr/bin/
cd $BUILD_DIR/SOURCES
tar -czvf $PACKAGE_DIR.tar.gz $PACKAGE_DIR
cd $BUILD_DIR
echo Build dir is: $BUILD_DIR
ls -la $BUILD_DIR/SOURCES
rpmbuild -ba $BUILD_DIR/SPECS/prometheus-ipmi-exporter.spec

View File

@ -7,9 +7,8 @@ RUN tar -C /usr/local -xvzf go1.18.1.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin ENV PATH=$PATH:/usr/local/go/bin
COPY . /go/ipmi_exporter COPY . /go/ipmi_exporter
WORKDIR /go/ipmi_exporter WORKDIR /go/ipmi_exporter
RUN rpm/build.sh RUN contrib/rpm/build.sh
RUN mkdir /rpm RUN mkdir /outdir
ENTRYPOINT ["/bin/sh"] ENTRYPOINT ["/bin/sh"]
ENTRYPOINT ["cp"] ENTRYPOINT ["cp"]
CMD ["-r","/root/rpmbuild/RPMS/x86_64/","/rpm/build"] CMD ["-r", "/root/rpmbuild/RPMS/x86_64/", "/outdir"]

View File

@ -1,23 +0,0 @@
#!/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