Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from lovoo/packaging
Browse files Browse the repository at this point in the history
add packaging target in Makefile
  • Loading branch information
thomersch authored Oct 20, 2016
2 parents 654010e + cf75d80 commit 35bba58
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
language: go
go:
- 1.7

script:
- make build
- make test

before_deploy: make release-build
before_deploy:
- gem install fpm package_cloud
- make release-build deb release-package

deploy:
provider: releases
api_key:
Expand Down
49 changes: 42 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
BUILD_DIR = build
BUILD_DIR = $(CURDIR)/build
PROJECT_NAME = ipmi_exporter

GO = go
GOX = gox
GOX_ARGS = -output="$(BUILD_DIR)/{{.Dir}}_{{.OS}}_{{.Arch}}" -osarch="linux/amd64 linux/386 linux/arm linux/arm64 darwin/amd64 freebsd/amd64 freebsd/386 windows/386 windows/amd64"
VERSION = $(shell git describe --tags || echo 0.0.0-dev)
GO = go
GOX = gox
GOX_ARGS = -output="$(BUILD_DIR)/{{.Dir}}_{{.OS}}_{{.Arch}}" -osarch="linux/amd64 linux/386 linux/arm linux/arm64 darwin/amd64 freebsd/amd64 freebsd/386 windows/386 windows/amd64"

.PHONY: build
build:
$(GO) build -o $(BUILD_DIR)/$(PROJECT_NAME) .
GOBIN=$(BUILD_DIR) $(GO) install -v -ldflags '-X main.Version=$(VERSION)'

.PHONY: clean
clean:
Expand All @@ -19,5 +19,40 @@ test:

.PHONY: release-build
release-build:
@go get -u github.com/mitchellh/gox
@$(GO) get -u github.com/mitchellh/gox
@$(GOX) $(GOX_ARGS) github.com/lovoo/$(PROJECT_NAME)

.PHONY: deb
deb:
make build-deb ARCH=amd64 GOARCH=amd64
make build-deb ARCH=i386 GOARCH=386
make build-deb ARCH=arm64 GOARCH=arm64
make build-deb ARCH=armhf GOARCH=arm

.PHONY: build-deb
build-deb:
fpm -s dir -t deb \
--name $(PROJECT_NAME) \
--version $(VERSION) \
--package $(BUILD_DIR)/$(PROJECT_NAME)_$(VERSION)_$(ARCH).deb \
--depends ipmitool \
--maintainer "LOVOO IT Operations <[email protected]>" \
--deb-priority optional \
--category monitoring \
--force \
--deb-compression bzip2 \
--license "BSD-3-Clause" \
--vendor "LOVOO GmbH" \
--deb-no-default-config-files \
--after-install packaging/postinst.deb \
--before-remove packaging/prerm.deb \
--url https://github.com/lovoo/ipmi_exporter \
--description "Exports statistics from IPMI and publishes them for scraping by Prometheus." \
--architecture $(ARCH) \
$(BUILD_DIR)/$(PROJECT_NAME)_linux_$(GOARCH)=/usr/bin/ipmi_exporter \
packaging/ipmi-exporter.service=/lib/systemd/system/ipmi-exporter.service

.PHONY: release-package
release-package:
package_cloud push lovoo/prometheus-exporters/debian/jessie build/*.deb
package_cloud push lovoo/prometheus-exporters/debian/stretch build/*.deb
18 changes: 18 additions & 0 deletions packaging/ipmi-exporter.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=IPMI Metrics Exporter for Prometheus
After=syslog.target network.target

[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/tmp
ExecStart=/usr/bin/ipmi_exporter
RestartSec=1
Restart=on-failure
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=ipmi_exporter

[Install]
WantedBy=multi-user.target
26 changes: 26 additions & 0 deletions packaging/postinst.deb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
set -e

case "$1" in
abort-upgrade|abort-remove|abort-deconfigure)
;;

configure)
if which systemctl > /dev/null; then
systemctl daemon-reload || :
systemctl enable ipmi-exporter || :
systemctl restart ipmi-exporter || :
else
echo "Couldn't find systemd to control IPMI Metrics Exporter, cannot proceed."
echo "Open an issue and tell us about your system."
exit 1
fi
;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

exit 0
9 changes: 9 additions & 0 deletions packaging/prerm.deb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e

if [ $1 = "remove" ] ; then
if which systemctl > /dev/null; then
systemctl --no-reload disable ipmi-exporter || :
systemctl stop ipmi-exporter || :
fi
fi

0 comments on commit 35bba58

Please sign in to comment.