Merge pull request #75 from davidnewhall/dn2_metadata
Pass in build env from file.
This commit is contained in:
		
						commit
						b2daf23ccb
					
				|  | @ -21,4 +21,5 @@ MANUAL.html | ||||||
| README | README | ||||||
| README.html | README.html | ||||||
| /unifi-poller_manual.html | /unifi-poller_manual.html | ||||||
| /homebrew-mugs | /homebrew_release_repo | ||||||
|  | /.metadata.make | ||||||
|  |  | ||||||
|  | @ -0,0 +1,39 @@ | ||||||
|  | # Each line must have an export clause. | ||||||
|  | # This file is parsed and sourced by the Makefile, Docker and Homebrew builds. | ||||||
|  | 
 | ||||||
|  | # Must match the repo name. | ||||||
|  | BINARY="unifi-poller" | ||||||
|  | # github username | ||||||
|  | GHUSER="davidnewhall" | ||||||
|  | # docker hub username | ||||||
|  | DHUSER="golift" | ||||||
|  | # Github repo containing homebrew formula repo. | ||||||
|  | HBREPO="golift/homebrew-mugs" | ||||||
|  | MAINT="David Newhall II <david at sleepers dot pro>" | ||||||
|  | VENDOR="Go Lift" | ||||||
|  | DESC="Polls a UniFi controller and stores metrics in InfluxDB" | ||||||
|  | GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals" | ||||||
|  | # Example must exist at examples/$CONFIG_FILE.example | ||||||
|  | CONFIG_FILE="up.conf" | ||||||
|  | LICENSE="MIT" | ||||||
|  | 
 | ||||||
|  | export BINARY GHUSER DHUSER HBREPO MAINT VENDOR DESC GOLANGCI_LINT_ARGS CONFIG_FILE LICENSE | ||||||
|  | 
 | ||||||
|  | # The rest is mostly automatic. | ||||||
|  | 
 | ||||||
|  | GHREPO="${GHUSER}/${BINARY}" | ||||||
|  | URL="https://github.com/${GHREPO}" | ||||||
|  | 
 | ||||||
|  | # This parameter is passed in as -X to go build. Used to override the Version variable in a package. | ||||||
|  | # This makes a path like github.com/davidnewhall/unifi-poller/unifipoller.Version=1.3.3 | ||||||
|  | # Name the Version-containing library the same as the github repo, without dashes. | ||||||
|  | VERSION_PATH="github.com/${GHREPO}/$(echo ${BINARY} | tr -d -- -).Version" | ||||||
|  | 
 | ||||||
|  | # Dynamic. Recommend not changing. | ||||||
|  | VERSION="$(git tag -l --merged | tail -n1 | tr -d v || echo development)" | ||||||
|  | # This produces a 0 in some envirnoments (like Homebrew), but it's only used for packages. | ||||||
|  | ITERATION=$(git rev-list --count --all || echo 0) | ||||||
|  | DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" | ||||||
|  | COMMIT="$(git rev-parse --short HEAD || echo 0)" | ||||||
|  | 
 | ||||||
|  | export GHREPO URL VERSION_PATH VERSION ITERATION DATE COMMIT | ||||||
|  | @ -1,4 +1,6 @@ | ||||||
| language: go | language: go | ||||||
|  | git: | ||||||
|  |   depth: false | ||||||
| addons: | addons: | ||||||
|   apt: |   apt: | ||||||
|     packages: |     packages: | ||||||
|  |  | ||||||
							
								
								
									
										90
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										90
									
								
								Makefile
								
								
								
								
							|  | @ -1,39 +1,27 @@ | ||||||
| # This Makefile is written as generic as possible.
 | # This Makefile is written as generic as possible.
 | ||||||
| # Setting these variables and creating the necesarry paths in your GitHub repo will make this file work.
 | # Setting the variables in .metadata.sh and creating the paths in the repo makes this work.
 | ||||||
| #
 | #
 | ||||||
| # github username
 |  | ||||||
| GHUSER=davidnewhall |  | ||||||
| # docker hub username
 |  | ||||||
| DHUSER=golift |  | ||||||
| MAINT=David Newhall II <david at sleepers dot pro> |  | ||||||
| DESC=Polls a UniFi controller and stores metrics in InfluxDB |  | ||||||
| GOLANGCI_LINT_ARGS=--enable-all -D gochecknoglobals |  | ||||||
| BINARY:=$(shell basename $(shell pwd)) |  | ||||||
| URL:=https://github.com/$(GHUSER)/$(BINARY) |  | ||||||
| CONFIG_FILE=up.conf |  | ||||||
| 
 | 
 | ||||||
| # This parameter is passed in as -X to go build. Used to override the Version variable in a package.
 | # Suck in our application information.
 | ||||||
| # This makes a path like github.com/davidnewhall/unifi-poller/unifipoller.Version=1.3.3
 | IGNORE := $(shell bash -c "source .metadata.sh ; env | sed 's/=/:=/;s/^/export /' > .metadata.make") | ||||||
| # Name the Version-containing library the same as the github repo, without dashes.
 |  | ||||||
| VERSION_PATH:=github.com/$(GHUSER)/$(BINARY)/$(shell echo $(BINARY) | tr -d -- -).Version |  | ||||||
| 
 |  | ||||||
| # These don't generally need to be changed.
 |  | ||||||
| 
 | 
 | ||||||
| # md2roff turns markdown into man files and html files.
 | # md2roff turns markdown into man files and html files.
 | ||||||
| MD2ROFF_BIN=github.com/github/hub/md2roff-bin | MD2ROFF_BIN=github.com/github/hub/md2roff-bin | ||||||
| # This produces a 0 in some envirnoments (like Homebrew), but it's only used for packages.
 | 
 | ||||||
| ITERATION:=$(shell git rev-list --count --all || echo 0) |  | ||||||
| # Travis CI passes the version in. Local builds get it from the current git tag.
 | # Travis CI passes the version in. Local builds get it from the current git tag.
 | ||||||
| ifeq ($(VERSION),) | ifeq ($(VERSION),) | ||||||
| 	VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v || echo development) | 	include .metadata.make | ||||||
| endif | else | ||||||
| ifeq ($(VERSION),) | 	# Preserve the passed-in version & iteration (homebrew). | ||||||
| 	VERSION:=development | 	_VERSION:=$(VERSION) | ||||||
|  | 	_ITERATION:=$(ITERATION) | ||||||
|  | 	include .metadata.make | ||||||
|  | 	VERSION:=$(_VERSION) | ||||||
|  | 	ITERATION:=$(_ITERATION) | ||||||
| endif | endif | ||||||
|  | 
 | ||||||
| # rpm is wierd and changes - to _ in versions.
 | # rpm is wierd and changes - to _ in versions.
 | ||||||
| RPMVERSION:=$(shell echo $(VERSION) | tr -- - _) | RPMVERSION:=$(shell echo $(VERSION) | tr -- - _) | ||||||
| DATE:=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) |  | ||||||
| COMMIT:=$(shell git rev-parse --short HEAD || echo 0) |  | ||||||
| 
 | 
 | ||||||
| # Makefile targets follow.
 | # Makefile targets follow.
 | ||||||
| 
 | 
 | ||||||
|  | @ -54,7 +42,7 @@ release: clean vendor test macos arm windows linux_packages | ||||||
| clean: | clean: | ||||||
| 	# Cleaning up. | 	# Cleaning up. | ||||||
| 	rm -f $(BINARY) $(BINARY).*.{macos,linux,exe}{,.gz,.zip} $(BINARY).1{,.gz} $(BINARY).rb | 	rm -f $(BINARY) $(BINARY).*.{macos,linux,exe}{,.gz,.zip} $(BINARY).1{,.gz} $(BINARY).rb | ||||||
| 	rm -f $(BINARY){_,-}*.{deb,rpm} v*.tar.gz.sha256 | 	rm -f $(BINARY){_,-}*.{deb,rpm} v*.tar.gz.sha256 .metadata.make | ||||||
| 	rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html | 	rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html | ||||||
| 	rm -rf package_build_* release | 	rm -rf package_build_* release | ||||||
| 
 | 
 | ||||||
|  | @ -131,7 +119,7 @@ $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm: package_build_linux check_fpm | ||||||
| 		--iteration $(ITERATION) \
 | 		--iteration $(ITERATION) \
 | ||||||
| 		--after-install scripts/after-install.sh \
 | 		--after-install scripts/after-install.sh \
 | ||||||
| 		--before-remove scripts/before-remove.sh \
 | 		--before-remove scripts/before-remove.sh \
 | ||||||
| 		--license MIT \
 | 		--license $(LICENSE) \
 | ||||||
| 		--url $(URL) \
 | 		--url $(URL) \
 | ||||||
| 		--maintainer "$(MAINT)" \
 | 		--maintainer "$(MAINT)" \
 | ||||||
| 		--description "$(DESC)" \
 | 		--description "$(DESC)" \
 | ||||||
|  | @ -149,7 +137,7 @@ $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: package_build_linux check_fpm | ||||||
| 		--iteration $(ITERATION) \
 | 		--iteration $(ITERATION) \
 | ||||||
| 		--after-install scripts/after-install.sh \
 | 		--after-install scripts/after-install.sh \
 | ||||||
| 		--before-remove scripts/before-remove.sh \
 | 		--before-remove scripts/before-remove.sh \
 | ||||||
| 		--license MIT \
 | 		--license $(LICENSE) \
 | ||||||
| 		--url $(URL) \
 | 		--url $(URL) \
 | ||||||
| 		--maintainer "$(MAINT)" \
 | 		--maintainer "$(MAINT)" \
 | ||||||
| 		--description "$(DESC)" \
 | 		--description "$(DESC)" \
 | ||||||
|  | @ -167,7 +155,7 @@ $(BINARY)-$(RPMVERSION)-$(ITERATION).i386.rpm: package_build_linux_386 check_fpm | ||||||
| 		--iteration $(ITERATION) \
 | 		--iteration $(ITERATION) \
 | ||||||
| 		--after-install scripts/after-install.sh \
 | 		--after-install scripts/after-install.sh \
 | ||||||
| 		--before-remove scripts/before-remove.sh \
 | 		--before-remove scripts/before-remove.sh \
 | ||||||
| 		--license MIT \
 | 		--license $(LICENSE) \
 | ||||||
| 		--url $(URL) \
 | 		--url $(URL) \
 | ||||||
| 		--maintainer "$(MAINT)" \
 | 		--maintainer "$(MAINT)" \
 | ||||||
| 		--description "$(DESC)" \
 | 		--description "$(DESC)" \
 | ||||||
|  | @ -185,7 +173,7 @@ $(BINARY)_$(VERSION)-$(ITERATION)_i386.deb: package_build_linux_386 check_fpm | ||||||
| 		--iteration $(ITERATION) \
 | 		--iteration $(ITERATION) \
 | ||||||
| 		--after-install scripts/after-install.sh \
 | 		--after-install scripts/after-install.sh \
 | ||||||
| 		--before-remove scripts/before-remove.sh \
 | 		--before-remove scripts/before-remove.sh \
 | ||||||
| 		--license MIT \
 | 		--license $(LICENSE) \
 | ||||||
| 		--url $(URL) \
 | 		--url $(URL) \
 | ||||||
| 		--maintainer "$(MAINT)" \
 | 		--maintainer "$(MAINT)" \
 | ||||||
| 		--description "$(DESC)" \
 | 		--description "$(DESC)" \
 | ||||||
|  | @ -203,7 +191,7 @@ $(BINARY)-$(RPMVERSION)-$(ITERATION).arm64.rpm: package_build_linux_arm64 check_ | ||||||
| 		--iteration $(ITERATION) \
 | 		--iteration $(ITERATION) \
 | ||||||
| 		--after-install scripts/after-install.sh \
 | 		--after-install scripts/after-install.sh \
 | ||||||
| 		--before-remove scripts/before-remove.sh \
 | 		--before-remove scripts/before-remove.sh \
 | ||||||
| 		--license MIT \
 | 		--license $(LICENSE) \
 | ||||||
| 		--url $(URL) \
 | 		--url $(URL) \
 | ||||||
| 		--maintainer "$(MAINT)" \
 | 		--maintainer "$(MAINT)" \
 | ||||||
| 		--description "$(DESC)" \
 | 		--description "$(DESC)" \
 | ||||||
|  | @ -221,7 +209,7 @@ $(BINARY)_$(VERSION)-$(ITERATION)_arm64.deb: package_build_linux_arm64 check_fpm | ||||||
| 		--iteration $(ITERATION) \
 | 		--iteration $(ITERATION) \
 | ||||||
| 		--after-install scripts/after-install.sh \
 | 		--after-install scripts/after-install.sh \
 | ||||||
| 		--before-remove scripts/before-remove.sh \
 | 		--before-remove scripts/before-remove.sh \
 | ||||||
| 		--license MIT \
 | 		--license $(LICENSE) \
 | ||||||
| 		--url $(URL) \
 | 		--url $(URL) \
 | ||||||
| 		--maintainer "$(MAINT)" \
 | 		--maintainer "$(MAINT)" \
 | ||||||
| 		--description "$(DESC)" \
 | 		--description "$(DESC)" \
 | ||||||
|  | @ -239,7 +227,7 @@ $(BINARY)-$(RPMVERSION)-$(ITERATION).armhf.rpm: package_build_linux_armhf check_ | ||||||
| 		--iteration $(ITERATION) \
 | 		--iteration $(ITERATION) \
 | ||||||
| 		--after-install scripts/after-install.sh \
 | 		--after-install scripts/after-install.sh \
 | ||||||
| 		--before-remove scripts/before-remove.sh \
 | 		--before-remove scripts/before-remove.sh \
 | ||||||
| 		--license MIT \
 | 		--license $(LICENSE) \
 | ||||||
| 		--url $(URL) \
 | 		--url $(URL) \
 | ||||||
| 		--maintainer "$(MAINT)" \
 | 		--maintainer "$(MAINT)" \
 | ||||||
| 		--description "$(DESC)" \
 | 		--description "$(DESC)" \
 | ||||||
|  | @ -257,7 +245,7 @@ $(BINARY)_$(VERSION)-$(ITERATION)_armhf.deb: package_build_linux_armhf check_fpm | ||||||
| 		--iteration $(ITERATION) \
 | 		--iteration $(ITERATION) \
 | ||||||
| 		--after-install scripts/after-install.sh \
 | 		--after-install scripts/after-install.sh \
 | ||||||
| 		--before-remove scripts/before-remove.sh \
 | 		--before-remove scripts/before-remove.sh \
 | ||||||
| 		--license MIT \
 | 		--license $(LICENSE) \
 | ||||||
| 		--url $(URL) \
 | 		--url $(URL) \
 | ||||||
| 		--maintainer "$(MAINT)" \
 | 		--maintainer "$(MAINT)" \
 | ||||||
| 		--description "$(DESC)" \
 | 		--description "$(DESC)" \
 | ||||||
|  | @ -266,24 +254,33 @@ $(BINARY)_$(VERSION)-$(ITERATION)_armhf.deb: package_build_linux_armhf check_fpm | ||||||
| 
 | 
 | ||||||
| docker: | docker: | ||||||
| 	docker build -f init/docker/Dockerfile \
 | 	docker build -f init/docker/Dockerfile \
 | ||||||
| 		--build-arg "BUILD_DATE=${DATE}" \
 | 		--build-arg "BUILD_DATE=$(DATE)" \
 | ||||||
| 		--build-arg "COMMIT=${COMMIT}" \
 | 		--build-arg "COMMIT=$(COMMIT)" \
 | ||||||
| 		--build-arg "VERSION=${VERSION}-${ITERATION}" \
 | 		--build-arg "VERSION=$(VERSION)-$(ITERATION)" \
 | ||||||
|  | 		--build-arg "LICENSE=$(LICENSE)" \
 | ||||||
|  | 		--build-arg "DESC=$(DESC)" \
 | ||||||
|  | 		--build-arg "URL=$(URL)" \
 | ||||||
|  | 		--build-arg "VENDOR=$(VENDOR)" \
 | ||||||
|  | 		--build-arg "AUTHOR=$(MAINT)" \
 | ||||||
|  | 		--build-arg "BINARY=$(BINARY)" \
 | ||||||
|  | 		--build-arg "GHREPO=$(GHREPO)" \
 | ||||||
|  | 		--build-arg "CONFIG_FILE=$(CONFIG_FILE)" \
 | ||||||
| 		--tag $(DHUSER)/$(BINARY):local . | 		--tag $(DHUSER)/$(BINARY):local . | ||||||
| 
 | 
 | ||||||
| # Build an environment that can be packaged for linux.
 | # Build an environment that can be packaged for linux.
 | ||||||
| package_build_linux: readme man linux | package_build_linux: readme man linux | ||||||
| 	# Building package environment for linux. | 	# Building package environment for linux. | ||||||
| 	mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/lib/systemd/system | 	mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) | ||||||
| 	mkdir -p $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) |  | ||||||
| 	# Copying the binary, config file, unit file, and man page into the env. | 	# Copying the binary, config file, unit file, and man page into the env. | ||||||
| 	cp $(BINARY).amd64.linux $@/usr/bin/$(BINARY) | 	cp $(BINARY).amd64.linux $@/usr/bin/$(BINARY) | ||||||
| 	cp *.1.gz $@/usr/share/man/man1 | 	cp *.1.gz $@/usr/share/man/man1 | ||||||
| 	cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/ | 	cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/ | ||||||
| 	cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/$(CONFIG_FILE) | 	cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/$(CONFIG_FILE) | ||||||
| 	cp LICENSE *.html examples/*?.?* $@/usr/share/doc/$(BINARY)/ | 	cp LICENSE *.html examples/*?.?* $@/usr/share/doc/$(BINARY)/ | ||||||
| 	# These go to their own folder so the img src in the html pages continue to work. | 	[ ! -f init/systemd/template.unit.service ] || mkdir -p $@/lib/systemd/system | ||||||
| 	cp init/systemd/$(BINARY).service $@/lib/systemd/system/ | 	[ ! -f init/systemd/template.unit.service ] || \
 | ||||||
|  | 		sed -e "s/{{BINARY}}/$(BINARY)/g" -e "s/{{DESC}}/$(DESC)/g" \
 | ||||||
|  | 		init/systemd/template.unit.service > $@/lib/systemd/system/$(BINARY).service | ||||||
| 
 | 
 | ||||||
| package_build_linux_386: package_build_linux linux386 | package_build_linux_386: package_build_linux linux386 | ||||||
| 	mkdir -p $@ | 	mkdir -p $@ | ||||||
|  | @ -312,7 +309,15 @@ v$(VERSION).tar.gz.sha256: | ||||||
| 	curl -sL $(URL)/archive/v$(VERSION).tar.gz | openssl dgst -r -sha256 | tee $@ | 	curl -sL $(URL)/archive/v$(VERSION).tar.gz | openssl dgst -r -sha256 | tee $@ | ||||||
| $(BINARY).rb: v$(VERSION).tar.gz.sha256 | $(BINARY).rb: v$(VERSION).tar.gz.sha256 | ||||||
| 	# Creating formula from template using sed. | 	# Creating formula from template using sed. | ||||||
| 	sed "s/{{Version}}/$(VERSION)/g;s/{{SHA256}}/`head -c64 $<`/g;s/{{Desc}}/$(DESC)/g;s%{{URL}}%$(URL)%g" init/homebrew/$(BINARY).rb.tmpl | tee $(BINARY).rb | 	sed -e "s/{{Version}}/$(VERSION)/g" \
 | ||||||
|  | 		-e "s/{{Iter}}/$(ITERATION)/g" \
 | ||||||
|  | 		-e "s/{{SHA256}}/$(shell head -c64 $<)/g" \
 | ||||||
|  | 		-e "s/{{Desc}}/$(DESC)/g" \
 | ||||||
|  | 		-e "s%{{URL}}%$(URL)%g" \
 | ||||||
|  | 		-e "s%{{GHREPO}}%$(GHREPO)%g" \
 | ||||||
|  | 		-e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \
 | ||||||
|  | 		-e "s%{{Class}}%$(shell echo $(BINARY) | perl -pe 's/(?:\b|-)(\p{Ll})/\u$$1/g')%g" \
 | ||||||
|  | 		init/homebrew/formula.rb.tmpl | tee $(BINARY).rb | ||||||
| 
 | 
 | ||||||
| # Extras
 | # Extras
 | ||||||
| 
 | 
 | ||||||
|  | @ -352,7 +357,6 @@ install: man readme $(BINARY) | ||||||
| 	/usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/ | 	/usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/ | ||||||
| 	[ -f $(ETC)/$(BINARY)/$(CONFIG_FILE) ] || /usr/bin/install -m 0644 -cp  examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/$(CONFIG_FILE) | 	[ -f $(ETC)/$(BINARY)/$(CONFIG_FILE) ] || /usr/bin/install -m 0644 -cp  examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/$(CONFIG_FILE) | ||||||
| 	/usr/bin/install -m 0644 -cp LICENSE *.html examples/* $(PREFIX)/share/doc/$(BINARY)/ | 	/usr/bin/install -m 0644 -cp LICENSE *.html examples/* $(PREFIX)/share/doc/$(BINARY)/ | ||||||
| 	# These go to their own folder so the img src in the html pages continue to work. |  | ||||||
| 
 | 
 | ||||||
| # If you installed with `make install` run `make uninstall` before installing a binary package. (even on Linux!!!)
 | # If you installed with `make install` run `make uninstall` before installing a binary package. (even on Linux!!!)
 | ||||||
| # This will remove the package install from macOS, it will not remove a package install from Linux.
 | # This will remove the package install from macOS, it will not remove a package install from Linux.
 | ||||||
|  |  | ||||||
|  | @ -6,31 +6,26 @@ ARG ARCH=amd64 | ||||||
| ARG OS=linux | ARG OS=linux | ||||||
| ARG BUILD_DATE=0 | ARG BUILD_DATE=0 | ||||||
| ARG COMMIT=0 | ARG COMMIT=0 | ||||||
| ARG VERSION=development | ARG VERSION=unknown | ||||||
|  | ARG BINARY=application-builder | ||||||
|  | ARG GHREPO=golift/application-builder | ||||||
| 
 | 
 | ||||||
| FROM golang:stretch as builder | FROM golang:stretch as builder | ||||||
| ARG ARCH | ARG ARCH | ||||||
| ARG OS | ARG OS | ||||||
|  | ARG BINARY | ||||||
|  | ARG GHREPO | ||||||
| 
 | 
 | ||||||
| RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin $GOPATH/src/github.com/davidnewhall/unifi-poller | RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin $GOPATH/src/github.com/${GHREPO} | ||||||
| RUN apt-get update \ | RUN apt-get update \ | ||||||
|   && apt-get install -y curl  \ |   && apt-get install -y curl  \ | ||||||
|   && curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh |   && curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||||||
| 
 | 
 | ||||||
| COPY . $GOPATH/src/github.com/davidnewhall/unifi-poller | COPY . $GOPATH/src/github.com/${GHREPO} | ||||||
| WORKDIR $GOPATH/src/github.com/davidnewhall/unifi-poller | WORKDIR $GOPATH/src/github.com/${GHREPO} | ||||||
| 
 | 
 | ||||||
| RUN dep ensure --vendor-only \ | RUN dep ensure --vendor-only \ | ||||||
|   && CGO_ENABLED=0 make unifi-poller.${ARCH}.${OS} |   && CGO_ENABLED=0 make ${BINARY}.${ARCH}.${OS} | ||||||
| 
 |  | ||||||
| # |  | ||||||
| # creating container for run |  | ||||||
| # to use this container use the following command: |  | ||||||
| # |  | ||||||
| # docker run -d -v /your/config/up.conf:/etc/unifi-poller/up.conf golift/unifi-poller |  | ||||||
| # |  | ||||||
| # by using "-e UNIFI_PASSWORD=your-secret-pasword" you can avoid this configuration in the config file |  | ||||||
| # |  | ||||||
| 
 | 
 | ||||||
| FROM scratch | FROM scratch | ||||||
| ARG ARCH | ARG ARCH | ||||||
|  | @ -38,23 +33,31 @@ ARG OS | ||||||
| ARG BUILD_DATE | ARG BUILD_DATE | ||||||
| ARG COMMIT | ARG COMMIT | ||||||
| ARG VERSION | ARG VERSION | ||||||
|  | ARG LICENSE=MIT | ||||||
|  | ARG BINARY | ||||||
|  | ARG GHREPO | ||||||
|  | ARG URL=http://github.com/golift/application-builder | ||||||
|  | ARG DESC=application-builder | ||||||
|  | ARG VENDOR=golift | ||||||
|  | ARG AUTHOR=golift | ||||||
|  | ARG CONFIG_FILE=config.conf | ||||||
| 
 | 
 | ||||||
| # Build-time metadata as defined at https://github.com/opencontainers/image-spec/blob/master/annotations.md | # Build-time metadata as defined at https://github.com/opencontainers/image-spec/blob/master/annotations.md | ||||||
| LABEL org.opencontainers.image.created="${BUILD_DATE}" \ | LABEL org.opencontainers.image.created="${BUILD_DATE}" \ | ||||||
|       org.opencontainers.image.title="UniFi Poller" \ |       org.opencontainers.image.title="${BINARY}" \ | ||||||
|       org.opencontainers.image.documentation="https://github.com/davidnewhall/unifi-poller/wiki/Docker" \ |       org.opencontainers.image.documentation="${URL}/wiki/Docker" \ | ||||||
|       org.opencontainers.image.description="Polls a UniFi controller and stores metrics in InfluxDB" \ |       org.opencontainers.image.description="${DESC}" \ | ||||||
|       org.opencontainers.image.url="https://github.com/davidnewhall/unifi-poller" \ |       org.opencontainers.image.url="${URL}" \ | ||||||
|       org.opencontainers.image.revision="${COMMIT}" \ |       org.opencontainers.image.revision="${COMMIT}" \ | ||||||
|       org.opencontainers.image.source="https://github.com/davidnewhall/unifi-poller" \ |       org.opencontainers.image.source="https://github.com/${GHREPO}" \ | ||||||
|       org.opencontainers.image.vendor="Go Lift" \ |       org.opencontainers.image.vendor="${VENDOR}" \ | ||||||
|       org.opencontainers.image.authors="David Newhall II <david at sleepers dot pro>" \ |       org.opencontainers.image.authors="${AUTHOR}" \ | ||||||
|       org.opencontainers.image.architecture="${OS} ${ARCH}" \ |       org.opencontainers.image.architecture="${OS} ${ARCH}" \ | ||||||
|       org.opencontainers.image.licenses="MIT" \ |       org.opencontainers.image.licenses="${LICENSE}" \ | ||||||
|       org.opencontainers.image.version="${VERSION}" |       org.opencontainers.image.version="${VERSION}" | ||||||
| 
 | 
 | ||||||
| COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/unifi-poller.${ARCH}.${OS} /unifi-poller | COPY --from=builder /go/src/github.com/${GHREPO}/${BINARY}.${ARCH}.${OS} /image | ||||||
| COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/examples/up.conf.example /etc/unifi-poller/up.conf | COPY --from=builder /go/src/github.com/${GHREPO}/examples/${CONFIG_FILE}.example /etc/${BINARY}/${CONFIG_FILE} | ||||||
| 
 | 
 | ||||||
| VOLUME [ "/etc/unifi-poller" ] | VOLUME [ "/etc/${BINARY}" ] | ||||||
| ENTRYPOINT [ "/unifi-poller" ] | ENTRYPOINT [ "/image" ] | ||||||
|  |  | ||||||
|  | @ -1,16 +1,13 @@ | ||||||
| #!/bin/bash | #!/bin/bash | ||||||
| 
 |  | ||||||
| # This always run local to the Dockerfile folder, so the path is ../.. |  | ||||||
| 
 |  | ||||||
| set -e -o pipefail |  | ||||||
| 
 |  | ||||||
| # The Docker Cloud config must pass in the BUILDS env variable. | # The Docker Cloud config must pass in the BUILDS env variable. | ||||||
| # See README.md (in this dir) and the screenshot for more info. | # See README.md (in this dir) and the screenshot for more info. | ||||||
| 
 | 
 | ||||||
| VERSION=$(git tag -l --merged | tail -n1 | tr -d v) # 1.2.3 | set -e -o pipefail | ||||||
| DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) | 
 | ||||||
| COMMIT=$(git rev-parse --short HEAD) | # This always run local to the Dockerfile folder, so the path is ../.. | ||||||
| ITERATION=$(git rev-list --count --all) | pushd ../.. | ||||||
|  | 
 | ||||||
|  | source .metadata.sh | ||||||
| 
 | 
 | ||||||
| # Build each configured image from Docker Cloud. | # Build each configured image from Docker Cloud. | ||||||
| for build in $BUILDS; do | for build in $BUILDS; do | ||||||
|  | @ -23,6 +20,16 @@ for build in $BUILDS; do | ||||||
|     --build-arg "BUILD_DATE=${DATE}" \ |     --build-arg "BUILD_DATE=${DATE}" \ | ||||||
|     --build-arg "COMMIT=${COMMIT}" \ |     --build-arg "COMMIT=${COMMIT}" \ | ||||||
|     --build-arg "VERSION=${VERSION}-${ITERATION}" \ |     --build-arg "VERSION=${VERSION}-${ITERATION}" \ | ||||||
|  |     --build-arg "LICENSE=${LICENSE}" \ | ||||||
|  |     --build-arg "DESC=${DESC}" \ | ||||||
|  |     --build-arg "URL=${URL}" \ | ||||||
|  |     --build-arg "VENDOR=${VENDOR}" \ | ||||||
|  |     --build-arg "AUTHOR=${MAINT}" \ | ||||||
|  |     --build-arg "BINARY=${BINARY}" \ | ||||||
|  |     --build-arg "GHREPO=${GHREPO}" \ | ||||||
|  |     --build-arg "CONFIG_FILE=${CONFIG_FILE}" \ | ||||||
|     --tag "${IMAGE_NAME}_${os}_${name}" \ |     --tag "${IMAGE_NAME}_${os}_${name}" \ | ||||||
|     --file Dockerfile ../.. |     --file ${DOCKERFILE_PATH} . | ||||||
| done | done | ||||||
|  | 
 | ||||||
|  | popd | ||||||
|  |  | ||||||
|  | @ -1,11 +1,13 @@ | ||||||
| #!/bin/bash | #!/bin/bash | ||||||
| 
 |  | ||||||
| # This post build hook creates multi-architecture docker manifests. | # This post build hook creates multi-architecture docker manifests. | ||||||
| # It's all a bit complicated for some reason. | # It's all a bit complicated for some reason. | ||||||
|  | 
 | ||||||
| set -e -o pipefail | set -e -o pipefail | ||||||
| 
 | 
 | ||||||
| VERSION=$(git tag -l --merged | tail -n1 | tr -d v) # 1.2.3 | pushd ../.. | ||||||
| SHORTVER=$(echo $VERSION | cut -d. -f1,2)           # 1.2 | source .metadata.sh | ||||||
|  | popd | ||||||
|  | 
 | ||||||
| if [ "$BUILDS" != "" ]; then | if [ "$BUILDS" != "" ]; then | ||||||
|   TAGS=$DOCKER_TAG |   TAGS=$DOCKER_TAG | ||||||
| fi | fi | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| # Homebrew Formula Template. Built by Makefile: `make fomula` | # Homebrew Formula Template. Built by Makefile: `make fomula` | ||||||
| class UnifiPoller < Formula | class {{Class}} < Formula | ||||||
|   desc "{{Desc}}" |   desc "{{Desc}}" | ||||||
|   homepage "{{URL}}" |   homepage "{{URL}}" | ||||||
|   url "{{URL}}/archive/v{{Version}}.tar.gz" |   url "{{URL}}/archive/v{{Version}}.tar.gz" | ||||||
|  | @ -12,27 +12,25 @@ class UnifiPoller < Formula | ||||||
|   def install |   def install | ||||||
|     ENV["GOPATH"] = buildpath |     ENV["GOPATH"] = buildpath | ||||||
| 
 | 
 | ||||||
|     bin_path = buildpath/"src/github.com/davidnewhall/unifi-poller" |     bin_path = buildpath/"src/github.com/{{GHREPO}}" | ||||||
|     # Copy all files from their current location (GOPATH root) |     # Copy all files from their current location (GOPATH root) | ||||||
|     # to $GOPATH/src/github.com/davidnewhall/unifi-poller |     # to $GOPATH/src/github.com/{{GHREPO}} | ||||||
|     bin_path.install Dir["*"] |     bin_path.install Dir["*",".??*"] | ||||||
|     cd bin_path do |     cd bin_path do | ||||||
|       system "dep", "ensure", "-vendor-only" |       system "dep", "ensure", "--vendor-only" | ||||||
|       system "make", "install", "VERSION=#{version}", "PREFIX=#{prefix}", "ETC=#{etc}" |       system "make", "install", "VERSION=#{version}", "ITERATION={{Iter}}", "PREFIX=#{prefix}", "ETC=#{etc}" | ||||||
|       # If this fails, the user gets a nice big warning about write permissions on their |       # If this fails, the user gets a nice big warning about write permissions on their | ||||||
|       # #{var}/log folder. The alternative could be letting the app silently fail |       # #{var}/log folder. The alternative could be letting the app silently fail | ||||||
|       # to start when it cannot write logs. This is better. Fix perms; reinstall. |       # to start when it cannot write logs. This is better. Fix perms; reinstall. | ||||||
|       touch("#{var}/log/unifi-poller.log") |       touch("#{var}/log/#{name}.log") | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def caveats |   def caveats | ||||||
|     <<-EOS |     <<-EOS | ||||||
|   This application will not work until the config file has authentication |   Edit the config file at #{etc}/#{name}/{{CONFIG_FILE}} then start #{name} with | ||||||
|   information for a UniFi Controller and an Influx Database. Edit the config |   brew services start #{name} ~ log file: #{var}/log/#{name}.log | ||||||
|   file at #{etc}/unifi-poller/up.conf then start the application with |   The manual explains the config file options: man #{name} | ||||||
|   brew services start unifi-poller ~ log file: #{var}/log/unifi-poller.log |  | ||||||
|   The manual explains the config file options: man unifi-poller |  | ||||||
|     EOS |     EOS | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  | @ -48,24 +46,24 @@ class UnifiPoller < Formula | ||||||
|          <string>#{plist_name}</string> |          <string>#{plist_name}</string> | ||||||
|          <key>ProgramArguments</key> |          <key>ProgramArguments</key> | ||||||
|          <array> |          <array> | ||||||
|              <string>#{bin}/unifi-poller</string> |              <string>#{bin}/#{name}</string> | ||||||
|              <string>-c</string> |              <string>-c</string> | ||||||
|              <string>#{etc}/unifi-poller/up.conf</string> |              <string>#{etc}/#{name}/{{CONFIG_FILE}}</string> | ||||||
|          </array> |          </array> | ||||||
|          <key>RunAtLoad</key> |          <key>RunAtLoad</key> | ||||||
|          <true/> |          <true/> | ||||||
|          <key>KeepAlive</key> |          <key>KeepAlive</key> | ||||||
|          <true/> |          <true/> | ||||||
|          <key>StandardErrorPath</key> |          <key>StandardErrorPath</key> | ||||||
|          <string>#{var}/log/unifi-poller.log</string> |          <string>#{var}/log/#{name}.log</string> | ||||||
|          <key>StandardOutPath</key> |          <key>StandardOutPath</key> | ||||||
|          <string>#{var}/log/unifi-poller.log</string> |          <string>#{var}/log/#{name}.log</string> | ||||||
|      </dict> |      </dict> | ||||||
|   </plist> |   </plist> | ||||||
|     EOS |     EOS | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   test do |   test do | ||||||
|     assert_match "unifi-poller v#{version}", shell_output("#{bin}/unifi-poller -v 2>&1", 2) |     assert_match "#{name} v#{version}", shell_output("#{bin}/#{name} -v 2>&1", 2) | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  | @ -0,0 +1,20 @@ | ||||||
|  | # Systemd service unit for {{BINARY}}. | ||||||
|  | 
 | ||||||
|  | [Unit] | ||||||
|  | Description={{BINARY}} - {{DESC}} | ||||||
|  | After=network.target | ||||||
|  | Requires=network.target | ||||||
|  | 
 | ||||||
|  | [Service] | ||||||
|  | ExecStart=/usr/bin/{{BINARY}} $DAEMON_OPTS | ||||||
|  | EnvironmentFile=-/etc/default/{{BINARY}} | ||||||
|  | EnvironmentFile=-/etc/sysconfig/{{BINARY}} | ||||||
|  | Restart=on-error | ||||||
|  | StandardOutput=syslog | ||||||
|  | StandardError=syslog | ||||||
|  | SyslogIdentifier={{BINARY}} | ||||||
|  | Type=simple | ||||||
|  | User=nobody | ||||||
|  | 
 | ||||||
|  | [Install] | ||||||
|  | WantedBy=multi-user.target | ||||||
|  | @ -1,20 +0,0 @@ | ||||||
| # Sytemd service unit for unifi-poller. |  | ||||||
| 
 |  | ||||||
| [Unit] |  | ||||||
| Description=UniFi Poller - Stores UniFi Metrics in InfluxDB |  | ||||||
| After=network.target |  | ||||||
| Requires=network.target |  | ||||||
| 
 |  | ||||||
| [Service] |  | ||||||
| ExecStart=/usr/bin/unifi-poller $DAEMON_OPTS |  | ||||||
| EnvironmentFile=-/etc/default/unifi-poller |  | ||||||
| EnvironmentFile=-/etc/sysconfig/unifi-poller |  | ||||||
| Restart=on-error |  | ||||||
| StandardOutput=syslog |  | ||||||
| StandardError=syslog |  | ||||||
| SyslogIdentifier=unifi-poller |  | ||||||
| Type=simple |  | ||||||
| User=nobody |  | ||||||
| 
 |  | ||||||
| [Install] |  | ||||||
| WantedBy=multi-user.target |  | ||||||
|  | @ -3,26 +3,19 @@ | ||||||
| # Deploys a new homebrew formula file to golift/homebrew-tap. | # Deploys a new homebrew formula file to golift/homebrew-tap. | ||||||
| # Requires SSH credentials in ssh-agent to work. | # Requires SSH credentials in ssh-agent to work. | ||||||
| # Run by Travis-CI when a new release is created on GitHub. | # Run by Travis-CI when a new release is created on GitHub. | ||||||
| APP=unpacker-poller |  | ||||||
| 
 | 
 | ||||||
| if [ -z "$VERSION" ]; then | source .metadata.sh | ||||||
|   VERSION=$TRAVIS_TAG |  | ||||||
| fi |  | ||||||
| VERSION=$(echo $VERSION|tr -d v) |  | ||||||
| 
 | 
 | ||||||
| make ${APP}.rb VERSION=$VERSION | make ${BINARY}.rb | ||||||
| 
 | 
 | ||||||
| if [ -z "$VERSION" ]; then | git config --global user.email "${BINARY}@auto.releaser" | ||||||
|   VERSION=$(grep -E '^\s+url\s+"' ${APP}.rb | cut -d/ -f7 | cut -d. -f1,2,3) | git config --global user.name "${BINARY}-auto-releaser" | ||||||
| fi |  | ||||||
| 
 | 
 | ||||||
| rm -rf homebrew-mugs | rm -rf homebrew_release_repo | ||||||
| git config --global user.email "${APP}@auto.releaser" | git clone git@github.com:${HBREPO}.git homebrew_release_repo | ||||||
| git config --global user.name "${APP}-auto-releaser" |  | ||||||
| git clone git@github.com:golift/homebrew-mugs.git |  | ||||||
| 
 | 
 | ||||||
| cp ${APP}.rb homebrew-mugs/Formula | cp ${BINARY}.rb homebrew_release_repo/Formula | ||||||
| pushd homebrew-mugs | pushd homebrew_release_repo | ||||||
| git commit -m "Update ${APP} on Release: ${VERSION}" Formula/${APP}.rb | git commit -m "Update ${BINARY} on Release: v${VERSION}-${ITERATION}" Formula/${BINARY}.rb | ||||||
| git push | git push | ||||||
| popd | popd | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ | ||||||
| # | # | ||||||
| # Use it like this:  (sudo is optional) | # Use it like this:  (sudo is optional) | ||||||
| # === | # === | ||||||
| #   curl https://raw.githubusercontent.com/davidnewhall/unifi-poller/master/scripts/install.sh | sudo bash | #   curl https://raw.githubusercontent.com/this/repo/master/scripts/install.sh | sudo bash | ||||||
| # === | # === | ||||||
| # If you're on redhat, this installs the latest rpm. If you're on Debian, it installs the latest deb package. | # If you're on redhat, this installs the latest rpm. If you're on Debian, it installs the latest deb package. | ||||||
| # | # | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue