From 8b272fb8ff4622f1f2ed7bbfbb04dfa08dc187a0 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Sat, 6 Jul 2019 20:16:45 -0700 Subject: [PATCH] generic Dockerfile. --- Makefile | 2 +- init/docker/Dockerfile | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 5b7dad95..615af904 100644 --- a/Makefile +++ b/Makefile @@ -261,7 +261,7 @@ $(BINARY)_$(VERSION)-$(ITERATION)_armhf.deb: package_build_linux_armhf check_fpm --chdir $< docker: - docker build -f init/docker/Dockerfile -t $(DHUSER)/$(BINARY) . + docker build -f init/docker/Dockerfile -t $(DHUSER)/$(BINARY):local . # Build an environment that can be packaged for linux. package_build_linux: readme man linux diff --git a/init/docker/Dockerfile b/init/docker/Dockerfile index 6a9b5641..80c3cbab 100644 --- a/init/docker/Dockerfile +++ b/init/docker/Dockerfile @@ -1,22 +1,26 @@ # # building static go binary with Debian golang container # +ARG BINARY=unifi-poller +ARG REPO=github.com/davidnewhall/${BINARY} FROM golang:stretch as builder ARG ARCH=amd64 ARG OS=linux +ARG BINARY +ARG REPO -RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin $GOPATH/src/github.com/davidnewhall +RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin $GOPATH/src/${REPO} RUN apt-get update \ && apt-get install -y curl \ && curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh -COPY . $GOPATH/src/github.com/davidnewhall/unifi-poller -WORKDIR $GOPATH/src/github.com/davidnewhall/unifi-poller +COPY . $GOPATH/src/${REPO} +WORKDIR $GOPATH/src/${REPO} RUN dep ensure --vendor-only \ - && CGO_ENABLED=0 make unifi-poller.${ARCH}.${OS} \ - && mv unifi-poller.${ARCH}.${OS} unifi-poller + && CGO_ENABLED=0 make ${BINARY}.${ARCH}.${OS} \ + && mv ${BINARY}.${ARCH}.${OS} ${BINARY} # # creating container for run @@ -28,9 +32,11 @@ RUN dep ensure --vendor-only \ # FROM scratch +ARG REPO +ARG BINARY -COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/unifi-poller /unifi-poller -COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/examples/up.conf.example /etc/unifi-poller/up.conf +COPY --from=builder /go/src/${REPO}/${BINARY} /${BINARY} +COPY --from=builder /go/src/${REPO}/examples/up.conf.example /etc/${BINARY}/up.conf -VOLUME [ "/etc/unifi-poller" ] -ENTRYPOINT [ "/unifi-poller" ] +VOLUME [ "/etc/${BINARY}" ] +ENTRYPOINT [ "/${BINARY}" ]