Pass in build env from file.
This commit is contained in:
parent
f680257272
commit
3930ec495c
|
|
@ -22,3 +22,4 @@ README
|
||||||
README.html
|
README.html
|
||||||
/unifi-poller_manual.html
|
/unifi-poller_manual.html
|
||||||
/homebrew-mugs
|
/homebrew-mugs
|
||||||
|
/.metadata.make
|
||||||
|
|
|
||||||
|
|
@ -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 <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"
|
||||||
|
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
|
||||||
32
Makefile
32
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 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 <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.
|
IGNORE := $(shell bash -c "source .metadata.sh ; env | sed 's/=/:=/;s/^/export /' > .metadata.make")
|
||||||
# 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
|
|
||||||
|
|
||||||
# These don't generally need to be changed.
|
# 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.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,19 +38,25 @@ ARG OS
|
||||||
ARG BUILD_DATE
|
ARG BUILD_DATE
|
||||||
ARG COMMIT
|
ARG COMMIT
|
||||||
ARG VERSION
|
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
|
# 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="${TITLE}" \
|
||||||
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="${URL}" \
|
||||||
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/davidnewhall/unifi-poller/unifi-poller.${ARCH}.${OS} /unifi-poller
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@ 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
|
source ../../.metadata.sh
|
||||||
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
||||||
COMMIT=$(git rev-parse --short HEAD)
|
|
||||||
ITERATION=$(git rev-list --count --all)
|
|
||||||
|
|
||||||
# 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,12 @@ 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 "TITLE=${TITLE}" \
|
||||||
|
--build-arg "DESC=${DESC}" \
|
||||||
|
--build-arg "URL=${URL}" \
|
||||||
|
--build-arg "VENDOR=${VENDOR}" \
|
||||||
|
--build-arg "AUTHOR=${AUTHOR}" \
|
||||||
--tag "${IMAGE_NAME}_${os}_${name}" \
|
--tag "${IMAGE_NAME}_${os}_${name}" \
|
||||||
--file Dockerfile ../..
|
--file Dockerfile ../..
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
# 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
|
source ../../.metadata.sh
|
||||||
SHORTVER=$(echo $VERSION | cut -d. -f1,2) # 1.2
|
|
||||||
if [ "$BUILDS" != "" ]; then
|
if [ "$BUILDS" != "" ]; then
|
||||||
TAGS=$DOCKER_TAG
|
TAGS=$DOCKER_TAG
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,27 @@
|
||||||
# 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
|
|
||||||
|
source ../.metadata.sh
|
||||||
|
|
||||||
if [ -z "$VERSION" ]; then
|
if [ -z "$VERSION" ]; then
|
||||||
VERSION=$TRAVIS_TAG
|
VERSION=$TRAVIS_TAG
|
||||||
fi
|
fi
|
||||||
VERSION=$(echo $VERSION|tr -d v)
|
VERSION=$(echo $VERSION|tr -d v)
|
||||||
|
|
||||||
make ${APP}.rb VERSION=$VERSION
|
make ${BINARY}.rb VERSION=$VERSION
|
||||||
|
|
||||||
if [ -z "$VERSION" ]; then
|
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
|
fi
|
||||||
|
|
||||||
rm -rf homebrew-mugs
|
rm -rf homebrew-mugs
|
||||||
git config --global user.email "${APP}@auto.releaser"
|
git config --global user.email "${BINARY}@auto.releaser"
|
||||||
git config --global user.name "${APP}-auto-releaser"
|
git config --global user.name "${BINARY}-auto-releaser"
|
||||||
git clone git@github.com:golift/homebrew-mugs.git
|
git clone git@github.com:golift/homebrew-mugs.git
|
||||||
|
|
||||||
cp ${APP}.rb homebrew-mugs/Formula
|
cp ${BINARY}.rb homebrew-mugs/Formula
|
||||||
pushd homebrew-mugs
|
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
|
git push
|
||||||
popd
|
popd
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue