Update build system

This commit is contained in:
Robert Jacob 2020-06-21 14:57:31 +02:00
parent 8e1542e7f4
commit 9573c83179
3 changed files with 23 additions and 12 deletions

1
.dockerignore Symbolic link
View File

@ -0,0 +1 @@
.gitignore

View File

@ -1,29 +1,21 @@
FROM golang:1 AS builder
FROM golang:1.14.4-alpine AS builder
RUN apt-get update && apt-get install -y upx
RUN apk add --no-cache make git
WORKDIR /build
ENV LD_FLAGS="-w"
ENV CGO_ENABLED=0
COPY go.mod go.sum /build/
RUN go mod download
RUN go mod verify
COPY . /build/
RUN echo "-- TEST" \
&& go test -cover ./... \
&& echo "-- BUILD" \
&& go install -tags netgo -ldflags "${LD_FLAGS}" . \
&& echo "-- PACK" \
&& upx -9 /go/bin/netatmo-exporter
RUN make
FROM busybox
LABEL maintainer="Robert Jacob <xperimental@solidproject.de>"
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /go/bin/netatmo-exporter /bin/netatmo-exporter
COPY --from=builder /build/netatmo-exporter /bin/netatmo-exporter
USER nobody
EXPOSE 9210

18
Makefile Normal file
View File

@ -0,0 +1,18 @@
.PHONY: all test build-binary install clean
GO ?= go
GO_CMD := CGO_ENABLED=0 $(GO)
GIT_VERSION := $(shell git describe --tags --dirty)
VERSION := $(GIT_VERSION:v%=%)
GIT_COMMIT := $(shell git rev-parse HEAD)
all: test build-binary
test:
$(GO_CMD) test -cover ./...
build-binary:
$(GO_CMD) build -tags netgo -ldflags "-w -X main.Version=$(VERSION) -X main.GitCommit=$(GIT_COMMIT)" -o netatmo-exporter .
clean:
rm -f netatmo-exporter