From 135533b56ff886ca2f1e4fffb07a08d0c6b0b364 Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Fri, 1 Nov 2019 09:31:31 +0000 Subject: [PATCH] Stop doing vendor build, go modules are good in 1.13 Plus misc cleanups in dockerfile: - Use "1-alpine" to get Go v1 compatibility promise - Include git revision when built by docker in the source tree (i.e. don't require someone to specify it) --- .circleci/config.yml | 9 +++------ Dockerfile | 12 ++++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a10bb3..09d90cf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,14 +13,11 @@ jobs: keys: - pkg-cache - run: - name: Build using vendor directory - command: go build -mod=vendor ./cmd/geras - - run: - name: Build using go modules - command: go build ./... + name: Build geras binary + command: go build ./cmd/geras - run: name: Run unit tests - command: go test ./pkg/... + command: go test ./... - run: name: Check flags are documented command: test/flags-doc.sh diff --git a/Dockerfile b/Dockerfile index 349775e..b856e03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ # build stage -FROM golang:alpine AS build-env +FROM golang:1-alpine AS build-env ADD . /src WORKDIR /src RUN apk add git ARG GRPC_HEALTH_PROBE_VERSION=v0.3.0 RUN go get github.com/grpc-ecosystem/grpc-health-probe@${GRPC_HEALTH_PROBE_VERSION} -# Normally built on CircleCI, you can get a dev image with version info with: -# docker build --build-arg GIT_REVISION="$(git rev-parse HEAD)" \ -# --build-arg GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" . ARG GERAS_VERSION="development" ARG BUILD_USER="docker" ARG GIT_REVISION="unknown" ARG GIT_BRANCH="unknown" -ENV GO111MODULE=on -RUN go install -mod=vendor -ldflags '-extldflags "-static" \ +RUN if [[ "${GIT_REVISION}" = "unknown" ]]; then \ + GIT_REVISION="$(git rev-parse HEAD)"; \ + GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"; \ +fi; \ +go install -ldflags ' \ -X github.com/prometheus/common/version.Version='"${GERAS_VERSION}"' \ -X github.com/prometheus/common/version.Revision='"${GIT_REVISION}"' \ -X github.com/prometheus/common/version.Branch='"${GIT_BRANCH}"' \