Makefile and build pipeline updates.
This commit is contained in:
parent
47d0acf718
commit
ab180e1fa0
77
Makefile
77
Makefile
|
|
@ -1,53 +1,64 @@
|
||||||
PACKAGE=./cmd/unifi-poller
|
BINARY:=unifi-poller
|
||||||
BINARY=unifi-poller
|
PACKAGE:=./cmd/$(BINARY)
|
||||||
VERSION=`git tag -l --merged | tail -n1`
|
VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v)
|
||||||
|
ITERATION:=$(shell git rev-list --all --count)
|
||||||
|
|
||||||
all: man unifi-poller
|
all: man build
|
||||||
|
|
||||||
# Prepare a release. Called in Travis CI.
|
# Prepare a release. Called in Travis CI.
|
||||||
release: clean test man linux macos rpm deb osxpkg
|
release: clean test man linux macos rpm deb osxpkg
|
||||||
mkdir -p release
|
mkdir -p release
|
||||||
gzip -9k unifi-poller.linux
|
gzip -9 $(BINARY).linux
|
||||||
gzip -9k unifi-poller.macos
|
gzip -9 $(BINARY).macos
|
||||||
mv unifi-poller.macos.gz unifi-poller.linux.gz release/
|
mv $(BINARY).macos.gz $(BINARY).linux.gz release/
|
||||||
cp *.rpm *.deb *.pkg release/
|
mv *.rpm *.deb *.pkg release/
|
||||||
|
|
||||||
|
# Delete all build assets.
|
||||||
clean:
|
clean:
|
||||||
rm -f `echo $(PACKAGE)|cut -d/ -f3`{.macos,.linux,.1,}{,.gz}
|
rm -f $(BINARY){.macos,.linux,.1,}{,.gz}
|
||||||
rm -f `echo $(PACKAGE)|cut -d/ -f3`{_,-}*.{deb,rpm,pkg}
|
rm -f $(BINARY){_,-}*.{deb,rpm,pkg}
|
||||||
rm -rf package_build release
|
rm -rf package_build release
|
||||||
|
|
||||||
build: unifi-poller
|
# Build a man page from a markdown file using ronn.
|
||||||
unifi-poller:
|
man: $(BINARY).1.gz
|
||||||
go build -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
|
$(BINARY).1.gz:
|
||||||
|
scripts/build_manpages.sh ./
|
||||||
|
|
||||||
linux: unifi-poller.linux
|
# Binaries
|
||||||
unifi-poller.linux:
|
|
||||||
GOOS=linux go build -o unifi-poller.linux -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
|
|
||||||
|
|
||||||
macos: unifi-poller.macos
|
build: $(BINARY)
|
||||||
unifi-poller.macos:
|
$(BINARY):
|
||||||
GOOS=darwin go build -o unifi-poller.macos -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
|
go build -o $(BINARY) -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
|
||||||
|
|
||||||
|
linux: $(BINARY).linux
|
||||||
|
$(BINARY).linux:
|
||||||
|
GOOS=linux go build -o $(BINARY).linux -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
|
||||||
|
|
||||||
|
macos: $(BINARY).macos
|
||||||
|
$(BINARY).macos:
|
||||||
|
GOOS=darwin go build -o $(BINARY).macos -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
|
||||||
|
|
||||||
|
# Packages
|
||||||
|
|
||||||
|
rpm: man linux $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm
|
||||||
|
$(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm:
|
||||||
|
scripts/build_packages.sh rpm "$(VERSION)" "$(ITERATION)"
|
||||||
|
|
||||||
|
deb: man linux $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb
|
||||||
|
$(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb:
|
||||||
|
scripts/build_packages.sh deb "$(VERSION)" "$(ITERATION)"
|
||||||
|
|
||||||
|
osxpkg: man macos $(BINARY)-$(VERSION).pkg
|
||||||
|
$(BINARY)-$(VERSION).pkg:
|
||||||
|
scripts/build_packages.sh osxpkg "$(VERSION)" "$(ITERATION)"
|
||||||
|
|
||||||
|
# Extras
|
||||||
|
|
||||||
test: lint
|
test: lint
|
||||||
go test -race -covermode=atomic $(PACKAGE)
|
go test -race -covermode=atomic $(PACKAGE)
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
golangci-lint run --enable-all -D gochecknoglobals
|
golangci-lint run --enable-all -D gochecknoglobals
|
||||||
|
|
||||||
man: unifi-poller.1.gz
|
|
||||||
unifi-poller.1.gz:
|
|
||||||
scripts/build_manpages.sh ./
|
|
||||||
|
|
||||||
rpm: man linux
|
|
||||||
scripts/build_linux_packages.sh rpm
|
|
||||||
|
|
||||||
deb: man linux
|
|
||||||
scripts/build_linux_packages.sh deb
|
|
||||||
|
|
||||||
osxpkg: man macos
|
|
||||||
scripts/build_osx_package.sh
|
|
||||||
|
|
||||||
install: man
|
install: man
|
||||||
scripts/local_install.sh
|
scripts/local_install.sh
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
"gnetId": null,
|
"gnetId": null,
|
||||||
"graphTooltip": 1,
|
"graphTooltip": 1,
|
||||||
"id": null,
|
"id": null,
|
||||||
"iteration": 1559898667753,
|
"iteration": 1559898956053,
|
||||||
"links": [
|
"links": [
|
||||||
{
|
{
|
||||||
"icon": "external link",
|
"icon": "external link",
|
||||||
|
|
@ -3410,5 +3410,5 @@
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
"title": "UniFi USW Insights",
|
"title": "UniFi USW Insights",
|
||||||
"uid": "HIKZ98GZz",
|
"uid": "HIKZ98GZz",
|
||||||
"version": 85
|
"version": 87
|
||||||
}
|
}
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# This script builds a deb or rpm package. Run by the Makefile.
|
|
||||||
# Use: `make rpm` or `make deb`
|
|
||||||
|
|
||||||
OUTPUT=$1
|
|
||||||
BINARY=unifi-poller
|
|
||||||
VERSION=$(git tag -l --merged | tail -n1 | tr -d v)
|
|
||||||
|
|
||||||
if [ "$OUTPUT" != "deb" ] && [ "$OUTPUT" != "rpm" ]; then
|
|
||||||
echo "first argument must be 'deb' or 'rpm'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
fpm -h > /dev/null 2>&1
|
|
||||||
if [ "$?" != "0" ]; then
|
|
||||||
echo "fpm missing. Install fpm: https://fpm.readthedocs.io/en/latest/installing.html"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Building '${OUTPUT}' package for ${BINARY} version ${VERSION}."
|
|
||||||
|
|
||||||
# eh, don't change these.
|
|
||||||
PREFIX=
|
|
||||||
BINFIX=/usr
|
|
||||||
|
|
||||||
# Make a build environment.
|
|
||||||
rm -rf package_build
|
|
||||||
mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY} package_build${BINFIX}/share/man/man1
|
|
||||||
|
|
||||||
# Copy the binary, config file and man page into the env.
|
|
||||||
cp ${BINARY}.linux package_build${BINFIX}/bin/${BINARY}
|
|
||||||
cp *.1.gz package_build${BINFIX}/share/man/man1
|
|
||||||
cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/up.conf
|
|
||||||
|
|
||||||
# Fix the paths in the systemd unit file before copying it into the emv.
|
|
||||||
mkdir -p package_build/lib/systemd/system
|
|
||||||
sed "s#ExecStart.*#ExecStart=${BINFIX}/bin/${BINARY} --config=${PREFIX}/etc/${BINARY}/up.conf#" \
|
|
||||||
init/systemd/unifi-poller.service > package_build/lib/systemd/system/${BINARY}.service
|
|
||||||
|
|
||||||
# Make a package.
|
|
||||||
fpm -s dir -t ${OUTPUT} \
|
|
||||||
--name ${BINARY} \
|
|
||||||
--version ${VERSION} \
|
|
||||||
--iteration $(git rev-list --all --count) \
|
|
||||||
--after-install scripts/after-install.sh \
|
|
||||||
--before-remove scripts/before-remove.sh \
|
|
||||||
--license MIT \
|
|
||||||
--url 'https://github.com/davidnewhall/unifi-poller' \
|
|
||||||
--maintainer 'david at sleepers dot pro' \
|
|
||||||
--description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \
|
|
||||||
--chdir package_build
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# This script builds a simple macos Installer pkg. Run by the Makefile.
|
|
||||||
# Use: `make osxpkg`
|
|
||||||
|
|
||||||
OUTPUT=osxpkg
|
|
||||||
BINARY=unifi-poller
|
|
||||||
VERSION=$(git tag -l --merged | tail -n1 | tr -d v)
|
|
||||||
|
|
||||||
fpm -h > /dev/null 2>&1
|
|
||||||
if [ "$?" != "0" ]; then
|
|
||||||
echo "fpm missing. Install fpm: https://fpm.readthedocs.io/en/latest/installing.html"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Building '${OUTPUT}' package for ${BINARY} version ${VERSION}."
|
|
||||||
|
|
||||||
PREFIX=/usr/local
|
|
||||||
BINFIX=/usr/local
|
|
||||||
|
|
||||||
# Make a build environment.
|
|
||||||
rm -rf package_build
|
|
||||||
mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY} package_build${BINFIX}/share/man/man1
|
|
||||||
mkdir -p package_build${PREFIX}/var/log
|
|
||||||
|
|
||||||
# Copy the binary, config file and man page into the env.
|
|
||||||
cp ${BINARY}.macos package_build${BINFIX}/bin/${BINARY}
|
|
||||||
cp *.1.gz package_build${BINFIX}/share/man/man1
|
|
||||||
cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/
|
|
||||||
|
|
||||||
# Copy in launch agent.
|
|
||||||
mkdir -p package_build/Library/LaunchAgents
|
|
||||||
cp init/launchd/com.github.davidnewhall.unifi-poller.plist package_build/Library/LaunchAgents/
|
|
||||||
|
|
||||||
# Make a package.
|
|
||||||
fpm -s dir -t ${OUTPUT} \
|
|
||||||
--name ${BINARY} \
|
|
||||||
--version ${VERSION} \
|
|
||||||
--iteration $(git rev-list --all --count) \
|
|
||||||
--after-install scripts/after-install-osx.sh \
|
|
||||||
--osxpkg-identifier-prefix com.github.davidnewhall \
|
|
||||||
--license MIT \
|
|
||||||
--maintainer 'david at sleepers dot pro' \
|
|
||||||
--url 'https://github.com/davidnewhall/unifi-poller' \
|
|
||||||
--description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \
|
|
||||||
--chdir package_build
|
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script builds a deb, rpm or osx package. Run by the Makefile.
|
||||||
|
# Use: `make rpm`, `make deb`, or `make osxpkg`
|
||||||
|
|
||||||
|
set -e -o pipefail
|
||||||
|
|
||||||
|
BINARY=unifi-poller
|
||||||
|
OUTPUT=$1
|
||||||
|
VERSION=$2
|
||||||
|
ITERATION=$3
|
||||||
|
[ "$VERSION" != "" ] || VERSION=$(git tag -l --merged | tail -n1 | tr -d v)
|
||||||
|
[ "$ITERATION" != "" ] || ITERATION=$(git rev-list --all --count)
|
||||||
|
|
||||||
|
if [ "$OUTPUT" != "deb" ] && [ "$OUTPUT" != "rpm" ] && [ "$OUTPUT" != "osxpkg" ]; then
|
||||||
|
echo "first argument must be 'deb' or 'rpm' or 'osxpkg'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
fpm -h > /dev/null 2>&1
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo "Package Build Failure. FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Building '${OUTPUT}' package for ${BINARY} version '${VERSION}-${ITERATION}'."
|
||||||
|
|
||||||
|
# These paths work on Linux. Suggest not changing.
|
||||||
|
PREFIX=
|
||||||
|
BINFIX=/usr
|
||||||
|
UNAME=linux
|
||||||
|
AFTER=scripts/after-install.sh
|
||||||
|
if [ "$OUTPUT" = "osxpkg" ]; then
|
||||||
|
# These paths work on OSX. Do not change.
|
||||||
|
PREFIX=/usr/local
|
||||||
|
BINFIX=/usr/local
|
||||||
|
UNAME=macos
|
||||||
|
AFTER=scripts/after-install-osx.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make a build environment.
|
||||||
|
rm -rf package_build
|
||||||
|
mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY}
|
||||||
|
mkdir -p package_build${BINFIX}/share/man/man1 package_build${BINFIX}/share/doc/unifi-poller
|
||||||
|
|
||||||
|
# Copy the binary, config file and man page into the env.
|
||||||
|
cp ${BINARY}.${UNAME} package_build${BINFIX}/bin/${BINARY}
|
||||||
|
cp *.1.gz package_build${BINFIX}/share/man/man1
|
||||||
|
cp examples/*.conf.example package_build${PREFIX}/etc/${BINARY}/
|
||||||
|
cp examples/* package_build${BINFIX}/share/doc/unifi-poller
|
||||||
|
|
||||||
|
# Copy startup file. Different for osx vs linux.
|
||||||
|
if [ "$UNAME" = "linux" ]; then
|
||||||
|
cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/up.conf
|
||||||
|
# Fix the paths in the systemd unit file before copying it into the emv.
|
||||||
|
mkdir -p package_build/lib/systemd/system
|
||||||
|
sed "s#ExecStart.*#ExecStart=${BINFIX}/bin/${BINARY} --config=${PREFIX}/etc/${BINARY}/up.conf#" \
|
||||||
|
init/systemd/unifi-poller.service > package_build/lib/systemd/system/${BINARY}.service
|
||||||
|
|
||||||
|
else # macos
|
||||||
|
# Sometimes the log folder is missing on osx. Create it.
|
||||||
|
mkdir -p package_build${PREFIX}/var/log
|
||||||
|
mkdir -p package_build/Library/LaunchAgents
|
||||||
|
cp init/launchd/com.github.davidnewhall.unifi-poller.plist package_build/Library/LaunchAgents/
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make a package.
|
||||||
|
fpm -s dir -t ${OUTPUT} \
|
||||||
|
--name ${BINARY} \
|
||||||
|
--version ${VERSION} \
|
||||||
|
--iteration ${ITERATION} \
|
||||||
|
--after-install ${AFTER} \
|
||||||
|
--before-remove scripts/before-remove.sh \
|
||||||
|
--osxpkg-identifier-prefix com.github.davidnewhall \
|
||||||
|
--license MIT \
|
||||||
|
--url 'https://github.com/davidnewhall/unifi-poller' \
|
||||||
|
--maintainer 'david at sleepers dot pro' \
|
||||||
|
--description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \
|
||||||
|
--chdir package_build
|
||||||
Loading…
Reference in New Issue