diff --git a/.gitignore b/.gitignore index 53ba083f..aec6680f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ README README.html /unifi-poller_manual.html /homebrew-mugs +/.metadata.make diff --git a/.metadata.sh b/.metadata.sh new file mode 100755 index 00000000..c18d6db6 --- /dev/null +++ b/.metadata.sh @@ -0,0 +1,34 @@ +# Each line must have an export clause. +# This file is parsed and sourced by the Makefile, Docker and Homebrew builds. + +# github username +GHUSER="davidnewhall" +# docker hub username +DHUSER="golift" +MAINT="David Newhall II " +VENDOR="Go Lift" +DESC="Polls a UniFi controller and stores metrics in InfluxDB" +GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals" +CONFIG_FILE="up.conf" +LICENSE="MIT" + +# The rest if mostly automatic. + +BINARY="$(basename $(pwd))" +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/${GHUSER}/${BINARY}/$(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 GHUSER DHUSER MAINT DESC CONFIG_FILE LICENSE GOLANGCI_LINT_ARGS +export BINARY GHREPO URL VERSION_PATH VERSION ITERATION DATE COMMIT diff --git a/Makefile b/Makefile index 77f25848..4a6ed5f6 100644 --- a/Makefile +++ b/Makefile @@ -1,39 +1,27 @@ # 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. # -# github username -GHUSER=davidnewhall -# docker hub username -DHUSER=golift -MAINT=David Newhall II -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. -# 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/$(GHUSER)/$(BINARY)/$(shell echo $(BINARY) | tr -d -- -).Version +IGNORE := $(shell bash -c "source .metadata.sh ; env | sed 's/=/:=/;s/^/export /' > .metadata.make") # These don't generally need to be changed. # md2roff turns markdown into man files and html files. 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. ifeq ($(VERSION),) - VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v || echo development) -endif -ifeq ($(VERSION),) - VERSION:=development + include .metadata.make +else + # Preserve the passed-in version & iteration (homebrew). + _VERSION:=$(VERSION) + _ITERATION:=$(ITERATION) + include .metadata.make + VERSION:=$(_VERSION) + ITERATION:=$(_ITERATION) endif + # rpm is wierd and changes - to _ in versions. 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. diff --git a/init/docker/Dockerfile b/init/docker/Dockerfile index 7bc72b1e..dc00d8b4 100644 --- a/init/docker/Dockerfile +++ b/init/docker/Dockerfile @@ -38,19 +38,25 @@ ARG OS ARG BUILD_DATE ARG COMMIT ARG VERSION +ARG LICENSE=MIT +ARG TITLE=unifi-poller +ARG URL=http://github.com/davidnewhall/unifi-poller +ARG DESC=unifi-poller +ARG VENDOR=golift +ARG AUTHOR=golift # Build-time metadata as defined at https://github.com/opencontainers/image-spec/blob/master/annotations.md LABEL org.opencontainers.image.created="${BUILD_DATE}" \ - org.opencontainers.image.title="UniFi Poller" \ - org.opencontainers.image.documentation="https://github.com/davidnewhall/unifi-poller/wiki/Docker" \ - org.opencontainers.image.description="Polls a UniFi controller and stores metrics in InfluxDB" \ - org.opencontainers.image.url="https://github.com/davidnewhall/unifi-poller" \ + org.opencontainers.image.title="${TITLE}" \ + org.opencontainers.image.documentation="${URL}/wiki/Docker" \ + org.opencontainers.image.description="${DESC}" \ + org.opencontainers.image.url="${URL}" \ org.opencontainers.image.revision="${COMMIT}" \ - org.opencontainers.image.source="https://github.com/davidnewhall/unifi-poller" \ - org.opencontainers.image.vendor="Go Lift" \ - org.opencontainers.image.authors="David Newhall II " \ + org.opencontainers.image.source="${URL}" \ + org.opencontainers.image.vendor="${VENDOR}" \ + org.opencontainers.image.authors="${AUTHOR}" \ org.opencontainers.image.architecture="${OS} ${ARCH}" \ - org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.licenses="${LICENSE}" \ org.opencontainers.image.version="${VERSION}" COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/unifi-poller.${ARCH}.${OS} /unifi-poller diff --git a/init/docker/hooks/build b/init/docker/hooks/build index 8e15743b..25d0c098 100755 --- a/init/docker/hooks/build +++ b/init/docker/hooks/build @@ -7,10 +7,7 @@ set -e -o pipefail # The Docker Cloud config must pass in the BUILDS env variable. # 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 -DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) -COMMIT=$(git rev-parse --short HEAD) -ITERATION=$(git rev-list --count --all) +source ../../.metadata.sh # Build each configured image from Docker Cloud. for build in $BUILDS; do @@ -23,6 +20,12 @@ for build in $BUILDS; do --build-arg "BUILD_DATE=${DATE}" \ --build-arg "COMMIT=${COMMIT}" \ --build-arg "VERSION=${VERSION}-${ITERATION}" \ + --build-arg "LICENSE=${LICENSE}" \ + --build-arg "TITLE=${TITLE}" \ + --build-arg "DESC=${DESC}" \ + --build-arg "URL=${URL}" \ + --build-arg "VENDOR=${VENDOR}" \ + --build-arg "AUTHOR=${AUTHOR}" \ --tag "${IMAGE_NAME}_${os}_${name}" \ --file Dockerfile ../.. done diff --git a/init/docker/hooks/push b/init/docker/hooks/push index e030ad4d..c71e906c 100755 --- a/init/docker/hooks/push +++ b/init/docker/hooks/push @@ -4,8 +4,8 @@ # It's all a bit complicated for some reason. set -e -o pipefail -VERSION=$(git tag -l --merged | tail -n1 | tr -d v) # 1.2.3 -SHORTVER=$(echo $VERSION | cut -d. -f1,2) # 1.2 +source ../../.metadata.sh + if [ "$BUILDS" != "" ]; then TAGS=$DOCKER_TAG fi diff --git a/scripts/formula-deploy.sh b/scripts/formula-deploy.sh index 9bbe1c06..978b4507 100755 --- a/scripts/formula-deploy.sh +++ b/scripts/formula-deploy.sh @@ -3,26 +3,27 @@ # Deploys a new homebrew formula file to golift/homebrew-tap. # Requires SSH credentials in ssh-agent to work. # Run by Travis-CI when a new release is created on GitHub. -APP=unpacker-poller + +source ../.metadata.sh if [ -z "$VERSION" ]; then VERSION=$TRAVIS_TAG fi VERSION=$(echo $VERSION|tr -d v) -make ${APP}.rb VERSION=$VERSION +make ${BINARY}.rb VERSION=$VERSION if [ -z "$VERSION" ]; then - VERSION=$(grep -E '^\s+url\s+"' ${APP}.rb | cut -d/ -f7 | cut -d. -f1,2,3) + VERSION=$(grep -E '^\s+url\s+"' ${BINARY}.rb | cut -d/ -f7 | cut -d. -f1,2,3) fi rm -rf homebrew-mugs -git config --global user.email "${APP}@auto.releaser" -git config --global user.name "${APP}-auto-releaser" +git config --global user.email "${BINARY}@auto.releaser" +git config --global user.name "${BINARY}-auto-releaser" git clone git@github.com:golift/homebrew-mugs.git -cp ${APP}.rb homebrew-mugs/Formula +cp ${BINARY}.rb homebrew-mugs/Formula pushd homebrew-mugs -git commit -m "Update ${APP} on Release: ${VERSION}" Formula/${APP}.rb +git commit -m "Update ${BINARY} on Release: ${VERSION}" Formula/${BINARY}.rb git push popd