Skip to content

Commit

Permalink
Debian and RPM packaging (#58)
Browse files Browse the repository at this point in the history
* Add deb and rpm pkg config

* Using nfpm for deb and rpm packaging

* Add packaging step that builds deb and rpm

* Run packaging step in CI for testing

* Fix failing unit test

* Execute only e2e tests in e2e step

* Add promtool as dependent step for e2e target in Makefile

* Update README for IPMI

---------

Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri authored Mar 24, 2024
1 parent 7b2de36 commit 3d6b8e0
Show file tree
Hide file tree
Showing 32 changed files with 1,013 additions and 47 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ jobs:
build:
needs: [test-lint, test-unit, test-e2e]
uses: ./.github/workflows/step_build.yml

packaging:
needs: [build]
uses: ./.github/workflows/step_packaging.yml
29 changes: 13 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ jobs:
needs: [test-unit, test-e2e]
uses: ./.github/workflows/step_build.yml

publish:
cross-build:
needs: [build]
uses: ./.github/workflows/step_cross-build.yml

packaging:
needs: [cross-build]
uses: ./.github/workflows/step_packaging.yml

publish:
needs: [packaging]
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -46,22 +54,11 @@ jobs:
make promu
go mod download
# These steps are taken from https://circleci.com/developer/orbs/orb/prometheus/prometheus#jobs-publish_release
- name: Setup build environment
run: |
docker version
docker run --privileged linuxkit/binfmt:v0.8
- name: Cross compile Go packages
run: promu --config .promu-go.yml crossbuild -v

- name: Cross compile CGo packages
run: |
sed -i -e 's/CGO_BUILD ?= 0/CGO_BUILD ?= 1/g' Makefile
promu --config .promu-cgo.yml crossbuild -v
- name: Download release artifacts
uses: actions/download-artifact@v3
with:
name: release-artifacts

- name: Publish release
run: |
promu crossbuild tarballs
promu checksum .tarballs
promu release .tarballs
8 changes: 5 additions & 3 deletions .github/workflows/step_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ jobs:
# Cross compile for only AMD and ARM archs in CI to reduce CI time and artifacts size
# We will compile for all supported archs in release workflow
- name: Cross compile Go packages
run: promu --config .promu-go.yml crossbuild -v -p linux/amd64 linux/arm64
run: promu --config .promu-go.yml crossbuild -v -p linux/amd64 -p linux/arm64

- name: Cross compile CGo packages
run: |
sed -i -e 's/CGO_BUILD ?= 0/CGO_BUILD ?= 1/g' Makefile
promu --config .promu-cgo.yml crossbuild -v -p linux/amd64 linux/arm64
promu --config .promu-cgo.yml crossbuild -v -p linux/amd64 -p linux/arm64
- name: Upload go build artifacts
uses: actions/upload-artifact@v3
with:
name: build-go-artifacts
path: .build
path: |
.build
.tarballs
retention-days: 3
51 changes: 51 additions & 0 deletions .github/workflows/step_cross-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: cross-build
run-name: Cross build

on:
workflow_call:

jobs:
cross-build:
name: cross-build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.21.x

- name: Install promu
run: |
make promu
go mod download
# These steps are taken from https://circleci.com/developer/orbs/orb/prometheus/prometheus#jobs-publish_release
- name: Setup build environment
run: |
docker version
docker run --privileged linuxkit/binfmt:v0.8
- name: Cross compile Go packages
run: promu --config .promu-go.yml crossbuild -v

- name: Cross compile CGo packages
run: |
sed -i -e 's/CGO_BUILD ?= 0/CGO_BUILD ?= 1/g' Makefile
promu --config .promu-cgo.yml crossbuild -v
- name: Create tarballs and checksums
run: |
promu crossbuild tarballs
promu checksum .tarballs
- name: Upload go build artifacts
uses: actions/upload-artifact@v3
with:
name: build-go-artifacts
path: |
.build
.tarballs
retention-days: 1
57 changes: 57 additions & 0 deletions .github/workflows/step_packaging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: packaging
run-name: Packaging

on:
workflow_call:

jobs:
packaging:
name: packaging
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.21.x

- name: Install nfpm
run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest

- name: Download go build artifacts
uses: actions/download-artifact@v3
with:
name: build-go-artifacts

# Build RPM and DEB packages
- name: Build deb and rpm packages
run: |
# Replace any '/' with '-' for non tag workflows
export REF_NAME=$(echo "${GITHUB_REF_NAME//\//-}")
# Strip v from tag name, eg v0.1.0 -> 0.1.0
export CEEMS_VERSION=$(echo "${REF_NAME//v}")
export GOOS=linux
# Ensure target directory exists
mkdir -p .tarballs
# Build packages
# Use a simple for loop instead of matrix strategy as building packages
# is a very rapid process and we pay more price by repeating all the steps
# if using a matrix strategy
for arch in amd64 arm64; do
for packager in rpm deb; do
for app in ceems_exporter ceems_api_server ceems_lb; do
GOARCH=${arch} nfpm pkg --config build/package/${app}/nfpm.yml --packager ${packager} --target .tarballs/${app}-${CEEMS_VERSION}-${GOOS}-${arch}.${packager}
done
done
done
- name: Upload release artifacts
uses: actions/upload-artifact@v3
with:
name: release-artifacts
path: .tarballs
retention-days: 1
4 changes: 2 additions & 2 deletions .github/workflows/step_tests-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
go mod download
- name: Run e2e tests for Go packages
run: make
run: make test-e2e

- name: Run e2e tests for CGo packages
run: CGO_BUILD=1 make
run: CGO_BUILD=1 make test-e2e
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ data-backup

# Ignore extracted folder
ceems-*

# Ignore .deb and .rpm files
*.deb
*.rpm
3 changes: 2 additions & 1 deletion .promu-cgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ build:
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- configs/ceems_lb.yml
- build/package/ceems_lb/config.yml
- build/config/web-config.yml
- LICENSE
- README.md
crossbuild:
Expand Down
1 change: 1 addition & 0 deletions .promu-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build:
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- build/config/web-config.yml
- LICENSE
- README.md
crossbuild:
Expand Down
3 changes: 2 additions & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ build:
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- configs/ceems_lb.yml
- build/package/ceems_lb/config.yml
- build/config/web-config.yml
- LICENSE
- README.md
crossbuild:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ test-e2e: build pkg/collector/testdata/sys/.unpacked pkg/collector/testdata/proc
./scripts/e2e-test.sh -s exporter-cgroups-v2-all-metrics
else
.PHONY: test-e2e
test-e2e: build pkg/collector/testdata/sys/.unpacked pkg/collector/testdata/proc/.unpacked
test-e2e: $(PROMTOOL) build pkg/collector/testdata/sys/.unpacked pkg/collector/testdata/proc/.unpacked
@echo ">> running end-to-end tests"
./scripts/e2e-test.sh -s api-project-query
./scripts/e2e-test.sh -s api-uuid-query
Expand Down Expand Up @@ -153,7 +153,7 @@ test-e2e-update: build pkg/collector/testdata/sys/.unpacked pkg/collector/testda
./scripts/e2e-test.sh -s exporter-cgroups-v2-all-metrics -u || true
else
.PHONY: test-e2e-update
test-e2e-update: build pkg/collector/testdata/sys/.unpacked pkg/collector/testdata/proc/.unpacked
test-e2e-update: $(PROMTOOL) build pkg/collector/testdata/sys/.unpacked pkg/collector/testdata/proc/.unpacked
@echo ">> updating end-to-end tests outputs"
./scripts/e2e-test.sh -s api-project-query -u || true
./scripts/e2e-test.sh -s api-uuid-query -u || true
Expand Down
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,29 @@ always favoured to running the exporter as `root`.

### IPMI collector

There are several IPMI implementation available like FreeIPMI, IPMITool, IPMIUtil,
_etc._ Current exporter allows to configure the IPMI command that will report
the power usage of the node. The default value is set to FreeIPMI one as
`--collector.ipmi.dcmi.cmd="/usr/bin/ipmi-dcmi --get-system-power-statistics"`.
There are several IPMI implementation available like FreeIPMI, OpenIPMI, IPMIUtil,
_etc._ Current exporter is capable of auto detecting the IPMI implementation and using
the one that is found.

> [!IMPORTANT]
> In addition to IPMI, the exporter can scrape energy readings
from Cray's [capmc](https://cray-hpe.github.io/docs-csm/en-10/operations/power_management/cray_advanced_platform_monitoring_and_control_capmc/) interface.

If the host where exporter is running does not use any of the IPMI implementations,
it is possible to configure the custom command using CLI flag `--collector.ipmi.dcmi.cmd`.

> [!NOTE]
> Current auto detection mode is only limited to `ipmi-dcmi` (FreeIPMI), `ipmitool`
(OpenIPMI), `ipmitutil` (IPMIUtils) and `capmc` (Cray) implementations. These binaries
must be on `PATH` for the exporter to detect them. If a custom IPMI command is used,
the command must output the power info in
[one of these formats](https://github.com/mahendrapaipuri/ceems/blob/c031e0e5b484c30ad8b6e2b68e35874441e9d167/pkg/collector/ipmi.go#L35-L92).
If that is not the case, operators must write a wrapper around the custom IPMI command
to output the energy info in one of the supported formats.

The exporter is capable of parsing FreeIPMI, IPMITool and IPMIUtil outputs.
If your IPMI implementation does not return an output in
[one of these formats](https://github.com/mahendrapaipuri/ceems/blob/96190ca346333e073d2ad636695efd61c292b7f5/pkg/collector/ipmi.go#L31-L89),
[one of these formats](https://github.com/mahendrapaipuri/ceems/blob/c031e0e5b484c30ad8b6e2b68e35874441e9d167/pkg/collector/ipmi.go#L35-L92),
you can write your own wrapper that parses your IPMI implementation's output and
returns output in one of above formats.

Expand All @@ -217,9 +232,7 @@ implementation, that sudoers entry will be
```
ceems ALL = NOPASSWD: /usr/sbin/ipmi-dcmi
```

and pass the flag `--collector.ipmi.dcmi.cmd="sudo /usr/bin/ipmi-dcmi --get-system-power-statistics"`
to `ceems_exporter`.
The exporter will automatically execute the command with `sudo`.

Another supported approach is to run the subprocess `ipmi-dcmi` command as root. In this
approach, the subprocess will be spawned as root to be able to execute the command.
Expand Down Expand Up @@ -358,7 +371,6 @@ Using prolog and epilog scripts approach and `sudo` for `ipmi`,
--collector.slurm.job.props.path="/run/slurmjobprops" \
--collector.slurm.gpu.type="nvidia" \
--collector.slurm.gpu.job.map.path="/run/gpujobmap" \
--collector.ipmi.dcmi.cmd="sudo /usr/sbin/ipmi-dcmi --get-system-power-statistics" \
--log.level="debug"
```

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0-rc.5
0.1.0-dev
33 changes: 33 additions & 0 deletions build/package/ceems_api_server/ceems_api_server.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[Unit]
Description=Prometheus CEEMS API Server
After=network-online.target

[Service]
Type=simple
User=ceemsapi
Group=ceemsapi
ExecStart=/usr/local/bin/ceems_api_server \
--storage.data.path="/var/lib/ceems_api_server" \
--storage.data.retention.period="30d" \
--storage.data.update.interval="15m" \
--web.config.file=/etc/ceems_api_server/web-config.yml

SyslogIdentifier=ceems_api_server
Restart=always
RestartSec=1
StartLimitInterval=0

ProtectHome=read-only
ReadWritePaths=/var/lib/ceems_api_server
WorkingDirectory=/var/lib/ceems_api_server

AmbientCapabilities=CAP_SETUID CAP_SETGID
CapabilityBoundingSet=CAP_SETUID CAP_SETGID

ProtectSystem=strict
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=yes

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit 3d6b8e0

Please sign in to comment.