diff --git a/core/poller/Makefile b/core/poller/Makefile index 67d71420..b8ff7019 100644 --- a/core/poller/Makefile +++ b/core/poller/Makefile @@ -32,7 +32,8 @@ ifeq ($(VERSION),) endif # rpm is wierd and changes - to _ in versions. RPMVERSION:=$(shell echo $(VERSION) | tr -- - _) -DATE:=$(shell date) +DATE:=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) +COMMIT:=$(shell git rev-parse --short HEAD || echo 0) # Makefile targets follow. @@ -264,7 +265,11 @@ $(BINARY)_$(VERSION)-$(ITERATION)_armhf.deb: package_build_linux_armhf check_fpm --chdir $< docker: - docker build -f init/docker/Dockerfile -t $(DHUSER)/$(BINARY):local . + docker build -f init/docker/Dockerfile \ + --build-arg "BUILD_DATE=${DATE}" \ + --build-arg "COMMIT=${COMMIT}" \ + --build-arg "VERSION=${VERSION}" \ + --tag $(DHUSER)/$(BINARY):local . # Build an environment that can be packaged for linux. package_build_linux: readme man linux diff --git a/core/poller/init/docker/Dockerfile b/core/poller/init/docker/Dockerfile index 5435d41f..afdbd632 100644 --- a/core/poller/init/docker/Dockerfile +++ b/core/poller/init/docker/Dockerfile @@ -2,9 +2,15 @@ # building static go binary with Debian golang container # -FROM golang:stretch as builder ARG ARCH=amd64 ARG OS=linux +ARG BUILD_DATE=0 +ARG COMMIT=0 +ARG VERSION=development + +FROM golang:stretch as builder +ARG ARCH +ARG OS RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin $GOPATH/src/github.com/davidnewhall/unifi-poller RUN apt-get update \ @@ -15,8 +21,7 @@ COPY . $GOPATH/src/github.com/davidnewhall/unifi-poller WORKDIR $GOPATH/src/github.com/davidnewhall/unifi-poller RUN dep ensure --vendor-only \ - && CGO_ENABLED=0 make unifi-poller.${ARCH}.${OS} \ - && mv unifi-poller.${ARCH}.${OS} unifi-poller + && CGO_ENABLED=0 make unifi-poller.${ARCH}.${OS} # # creating container for run @@ -28,8 +33,27 @@ RUN dep ensure --vendor-only \ # FROM scratch +ARG ARCH +ARG OS +ARG BUILD_DATE +ARG COMMIT +ARG VERSION -COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/unifi-poller /unifi-poller +# 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" \ + 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.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.architecture="${OS} ${ARCH}" \ + org.opencontainers.image.licenses="MIT" \ + 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/examples/up.conf.example /etc/unifi-poller/up.conf VOLUME [ "/etc/unifi-poller" ] diff --git a/core/poller/init/docker/hooks/build b/core/poller/init/docker/hooks/build index 136b6851..a8ad7a84 100755 --- a/core/poller/init/docker/hooks/build +++ b/core/poller/init/docker/hooks/build @@ -7,6 +7,10 @@ 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) + # Build each configured image from Docker Cloud. for build in $BUILDS; do # os:name:arch:variant @@ -15,6 +19,9 @@ for build in $BUILDS; do echo "Building Image ${IMAGE_NAME}_${os}_${name}" docker build \ --build-arg "ARCH=${name}" \ + --build-arg "BUILD_DATE=${DATE}" \ + --build-arg "COMMIT=${COMMIT}" \ + --build-arg "VERSION=${VERSION}" \ --tag "${IMAGE_NAME}_${os}_${name}" \ --file Dockerfile ../.. done