Add tools to build debian package
All checks were successful
/ go-test (push) Successful in 9m50s

This commit is contained in:
Melora Hugues 2024-12-03 14:11:19 +01:00
parent 47b5ae14af
commit f84419de0d
Signed by: faercol
SSH key fingerprint: SHA256:lzUKsKDIw1w0bcLnoBu84oYJOnLmi7SeKetszpyDCFY
7 changed files with 87 additions and 3 deletions

View file

@ -1,15 +1,34 @@
.PHONY: all client server .PHONY: all client server
BUILDDIR?=./build
VERSION?=$(shell echo "$$(date +'%Y%m%d')-$$(git rev-parse --short=8 HEAD)")
all: client server all: client server
clean: clean:
rm -rf ./build rm -rf $(BUILDDIR)
client: client:
go build -o ./build/client ./cmd/client go build -o $(BUILDDIR)/client ./cmd/client
server: server:
go build -o ./build/server ./cmd/server go build -o $(BUILDDIR)/server ./cmd/server
test: test:
go test -v ./... go test -v ./...
debpkg_server_prepare: server
rm -rf $(BUILDDIR)/debpkg
mkdir -p $(BUILDDIR)/debpkg/usr/bin $(BUILDDIR)/debpkg/DEBIAN $(BUILDDIR)/debpkg/etc/systemd/system $(BUILDDIR)/debpkg/etc/sys-exporter
install -m 755 -o root -g root $(BUILDDIR)/server $(BUILDDIR)/debpkg/usr/bin/
install -m 644 -o root -g root debian/sys-exporter/etc/systemd/system/sys-exporter.service $(BUILDDIR)/debpkg/etc/systemd/system/
install -m 644 -o root -g root debian/sys-exporter/etc/sys-exporter/config.yml $(BUILDDIR)/debpkg/etc/sys-exporter/
install -m 644 -o root -g root debian/sys-exporter/control $(BUILDDIR)/debpkg/DEBIAN/control
install -m 755 -o root -g root debian/sys-exporter/postinst $(BUILDDIR)/debpkg/DEBIAN/postinst
debpkg_server: debpkg_server_prepare
dpkg-deb --build $(BUILDDIR)/debpkg/ $(BUILDDIR)/sys-exporter.deb
debpkg_server_docker: server
docker build -t debian-builder ./debian/tools
docker run -t -e PACKAGE_VERSION="$(VERSION)" -v $(BUILDDIR):/build/ -v ./debian:/debian debian-builder

5
debian/sys-exporter/control vendored Normal file
View file

@ -0,0 +1,5 @@
Package: sys-exporter
Version: ${PACKAGE_VERSION}
Architecture: amd64
Maintainer: Melora Hugues <dev@faercol.me>
Description: System information exporter

View file

@ -0,0 +1,7 @@
logging:
level: info
collectors:
- system.loadavg
- system.meminfo
- services.systemd
- system.uptime

View file

@ -0,0 +1,16 @@
[Unit]
Description=System information exporter daemon
After=network-online.target
Wants=network-online.target
StartLimitIntervalSec=0
[Service]
Type=simple
ExecStart=/usr/bin/sys-exporter
TimeoutStartSec=10
Restart=on-failure
RestartSec=60s
[Install]
RequiredBy=multi-user.target

4
debian/sys-exporter/postinst vendored Normal file
View file

@ -0,0 +1,4 @@
#!/bin/bash
systemctl enable sys-exporter.service
systemctl start sys-exporter.service

16
debian/tools/Dockerfile vendored Normal file
View file

@ -0,0 +1,16 @@
FROM debian:bookworm
RUN set -ex \
&& sed -i -- 's/Types: deb/Types: deb deb-src/g' /etc/apt/sources.list.d/debian.sources \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
cdbs \
devscripts \
equivs \
fakeroot \
&& apt-get clean \
&& rm -rf /tmp/* /var/tmp/*
COPY build.sh /root/
ENTRYPOINT [ "/root/build.sh" ]

17
debian/tools/build.sh vendored Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
rm -rf /build/debpkg
mkdir -p /build/debpkg/usr/bin /build/debpkg/DEBIAN /build/debpkg/etc/systemd/system /build/debpkg/etc/sys-exporter
install -m 755 -o root -g root /build/server /build/debpkg/usr/bin/
install -m 644 -o root -g root /debian/sys-exporter/etc/systemd/system/sys-exporter.service /build/debpkg/etc/systemd/system/
install -m 644 -o root -g root /debian/sys-exporter/etc/sys-exporter/config.yml /build/debpkg/etc/sys-exporter/
install -m 644 -o root -g root /debian/sys-exporter/control /build/debpkg/DEBIAN/control
install -m 755 -o root -g root /debian/sys-exporter/postinst /build/debpkg/DEBIAN/postinst
envsubst < /debian/sys-exporter/control > /build/debpkg/DEBIAN/control
dpkg-deb --build /build/debpkg/ /build/sys-exporter.deb