From 3618aafca4597ee10349e7d7f3340305778fe500 Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Mon, 26 Jun 2017 15:15:39 -0400 Subject: [PATCH 1/5] [build] fix build makefile target path The `build` Makefile target attempted to place the generated artifact in `/build`, where it should have used a local directory instead. This commit makes the directory configurable using the `OUT_DIR` argument, and defaults it to ./_output --- .gitignore | 2 +- Makefile | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c57f793b..69d2ba91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.swp *~ vendor -./adapter +_output diff --git a/Makefile b/Makefile index 9fe211b6..b30779ad 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ TEMP_DIR:=$(shell mktemp -d) ARCH?=amd64 ALL_ARCH=amd64 arm arm64 ppc64le s390x ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x +OUT_DIR?=./_output VERSION?=latest @@ -25,7 +26,7 @@ endif all: docker-build build: - CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -tags netgo -o /build/adapter github.com/directxman12/k8s-prometheus-adapter/cmd/adapter + CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -tags netgo -o $(OUT_DIR)/$(ARCH)/adapter github.com/directxman12/k8s-prometheus-adapter/cmd/adapter docker-build: cp deploy/Dockerfile $(TEMP_DIR) From a723582f584a408cc0c881da26c58ee03c52606a Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Mon, 26 Jun 2017 15:26:28 -0400 Subject: [PATCH 2/5] [build] add make rule for vendor This commit adds a Makefile rule for installing the vendor directory. Both the `build` and `docker-build` phony rules depend on the `vendor` rule, which in turn depends on the `glide.lock` rule. This means that any time the `glide.lock` file is updated, the vendor directory will be re-installed. --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b30779ad..9271e5b2 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,10 @@ ifeq ($(ARCH),s390x) endif all: docker-build -build: +build: vendor CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -tags netgo -o $(OUT_DIR)/$(ARCH)/adapter github.com/directxman12/k8s-prometheus-adapter/cmd/adapter -docker-build: +docker-build: vendor cp deploy/Dockerfile $(TEMP_DIR) cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile @@ -48,3 +48,6 @@ push: ./manifest-tool $(addprefix push-,$(ALL_ARCH)) ./manifest-tool: curl -sSL https://github.com/estesp/manifest-tool/releases/download/v0.5.0/manifest-tool-linux-amd64 > manifest-tool chmod +x manifest-tool + +vendor: glide.lock + glide install -v From 91bc1dcd71f83c9abadbbef1a79226ed4b53e2de Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Mon, 26 Jun 2017 15:30:54 -0400 Subject: [PATCH 3/5] [build] cause all to trigger build This commit causes the `all` Makefile rule to trigger `build` instead of `docker-build`. This allows people with convoluted setups that involve `go build`-ing and `docker build`-ing on different machines (like @directxman12) to not complain as much. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9271e5b2..f43fc322 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ ifeq ($(ARCH),s390x) BASEIMAGE?=s390x/busybox endif -all: docker-build +all: build build: vendor CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -tags netgo -o $(OUT_DIR)/$(ARCH)/adapter github.com/directxman12/k8s-prometheus-adapter/cmd/adapter From 88b3531ef509b434ad80a868ee426d5d6de2e1cd Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Mon, 26 Jun 2017 16:22:57 -0400 Subject: [PATCH 4/5] [build] add a test target This commit adds a target for running `go test`. --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index f43fc322..969964a5 100644 --- a/Makefile +++ b/Makefile @@ -51,3 +51,6 @@ push: ./manifest-tool $(addprefix push-,$(ALL_ARCH)) vendor: glide.lock glide install -v + +test: vendor + CGO_ENABLED=0 go test ./pkg/... From d46c73ae6fbbdf55070d86b1b508a6095ca9a6ca Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Mon, 26 Jun 2017 16:29:36 -0400 Subject: [PATCH 5/5] [build] mark phony targets as such This commit marks the phony targets in the Makefile as phony, following good Makefile practices (for example, so we don't have have issues with someone creating a file with a matching name in the future, etc). --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 969964a5..b60221a7 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,8 @@ ifeq ($(ARCH),s390x) BASEIMAGE?=s390x/busybox endif +.PHONY: all build docker-build push-% push test + all: build build: vendor CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -tags netgo -o $(OUT_DIR)/$(ARCH)/adapter github.com/directxman12/k8s-prometheus-adapter/cmd/adapter