Browse Source

Update build (#1010)

* Update from upstream `Makefile.common`.
* Update CircleCI with simplifed upstream templating.
* Cleanup `Makefile`.

Signed-off-by: Ben Kochie <superq@gmail.com>
pull/1016/head
Ben Kochie 6 years ago committed by GitHub
parent
commit
981de58fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      .circleci/config.yml
  2. 17
      Makefile
  3. 59
      Makefile.common

47
.circleci/config.yml

@ -27,8 +27,6 @@ jobs:
working_directory: /home/circleci/.go_workspace/src/github.com/prometheus/node_exporter working_directory: /home/circleci/.go_workspace/src/github.com/prometheus/node_exporter
environment: environment:
DOCKER_IMAGE_NAME: prom/node-exporter
QUAY_IMAGE_NAME: quay.io/prometheus/node-exporter
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base
REPO_PATH: github.com/prometheus/node_exporter REPO_PATH: github.com/prometheus/node_exporter
@ -44,11 +42,9 @@ jobs:
- run: - run:
command: | command: |
if [ -n "$CIRCLE_TAG" ]; then if [ -n "$CIRCLE_TAG" ]; then
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG make docker DOCKER_IMAGE_TAG=$CIRCLE_TAG
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
else else
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME make docker
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME
fi fi
- run: docker images - run: docker images
- run: docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T - run: docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T
@ -65,37 +61,25 @@ jobs:
- image: circleci/golang:1.10 - image: circleci/golang:1.10
working_directory: /go/src/github.com/prometheus/node_exporter working_directory: /go/src/github.com/prometheus/node_exporter
environment:
DOCKER_IMAGE_NAME: prom/node-exporter
QUAY_IMAGE_NAME: quay.io/prometheus/node-exporter
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base
REPO_PATH: github.com/prometheus/node_exporter
steps: steps:
- checkout - checkout
- setup_remote_docker - setup_remote_docker
- attach_workspace: - attach_workspace:
at: . at: .
- run: ln -s .build/linux-amd64/node_exporter node_exporter - run: ln -s .build/linux-amd64/node_exporter node_exporter
- run: make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME - run: make docker
- run: make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME - run: make docker DOCKER_REPO=quay.io/prometheus
- run: docker images - run: docker images
- run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io
- run: docker push $DOCKER_IMAGE_NAME - run: make docker-publish
- run: docker push $QUAY_IMAGE_NAME - run: make docker-publish DOCKER_REPO=quay.io/prometheus
docker_hub_release_tags: docker_hub_release_tags:
docker: docker:
- image: circleci/golang:1.10 - image: circleci/golang:1.10
working_directory: /go/src/github.com/prometheus/node_exporter working_directory: /go/src/github.com/prometheus/node_exporter
environment:
DOCKER_IMAGE_NAME: prom/node-exporter
QUAY_IMAGE_NAME: quay.io/prometheus/node-exporter
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base
REPO_PATH: github.com/prometheus/node_exporter
steps: steps:
- checkout - checkout
- setup_remote_docker - setup_remote_docker
@ -112,24 +96,17 @@ jobs:
path: .tarballs path: .tarballs
destination: releases destination: releases
- run: ln -s .build/linux-amd64/node_exporter node_exporter - run: ln -s .build/linux-amd64/node_exporter node_exporter
- run: - run: make docker DOCKER_IMAGE_TAG=$CIRCLE_TAG
command: | - run: make docker DOCKER_IMAGE_TAG=$CIRCLE_TAG DOCKER_REPO=quay.io/prometheus
if [ -n "$CIRCLE_TAG" ]; then
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
else
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME
fi
- run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io
- run: | - run: |
if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then
docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest" make docker-tag-latest DOCKER_IMAGE_TAG="$CIRCLE_TAG"
docker tag "$QUAY_IMAGE_NAME:$CIRCLE_TAG" "$QUAY_IMAGE_NAME:latest" make docker-tag-latest DOCKER_IMAGE_TAG="$CIRCLE_TAG" DOCKER_REPO=quay.io/prometheus
fi fi
- run: docker push $DOCKER_IMAGE_NAME:$CIRCLE_TAG - run: make docker-publish
- run: docker push $QUAY_IMAGE_NAME:$CIRCLE_TAG - run: make docker-publish DOCKER_REPO=quay.io/prometheus
workflows: workflows:
version: 2 version: 2

17
Makefile

@ -70,14 +70,17 @@ $(eval $(call goarch_pair,mips64el,mipsel))
all: style vet staticcheck checkmetrics build test $(cross-test) $(test-e2e) all: style vet staticcheck checkmetrics build test $(cross-test) $(test-e2e)
.PHONY: test
test: collector/fixtures/sys/.unpacked test: collector/fixtures/sys/.unpacked
@echo ">> running tests" @echo ">> running tests"
$(GO) test -short $(test-flags) $(pkgs) $(GO) test -short $(test-flags) $(pkgs)
.PHONY: test-32bit
test-32bit: collector/fixtures/sys/.unpacked test-32bit: collector/fixtures/sys/.unpacked
@echo ">> running tests in 32-bit mode" @echo ">> running tests in 32-bit mode"
@env GOARCH=$(GOARCH_CROSS) $(GO) test $(pkgs) @env GOARCH=$(GOARCH_CROSS) $(GO) test $(pkgs)
.PHONY: skip-test-32bit
skip-test-32bit: skip-test-32bit:
@echo ">> SKIP running tests in 32-bit mode: not supported on $(OS_detected)/$(GOARCH)" @echo ">> SKIP running tests in 32-bit mode: not supported on $(OS_detected)/$(GOARCH)"
@ -87,17 +90,21 @@ collector/fixtures/sys/.unpacked: collector/fixtures/sys.ttar
./ttar -C collector/fixtures -x -f collector/fixtures/sys.ttar ./ttar -C collector/fixtures -x -f collector/fixtures/sys.ttar
touch $@ touch $@
.PHONY: test-e2e
test-e2e: build collector/fixtures/sys/.unpacked test-e2e: build collector/fixtures/sys/.unpacked
@echo ">> running end-to-end tests" @echo ">> running end-to-end tests"
./end-to-end-test.sh ./end-to-end-test.sh
.PHONY: skip-test-e2e
skip-test-e2e: skip-test-e2e:
@echo ">> SKIP running end-to-end tests on $(OS_detected)" @echo ">> SKIP running end-to-end tests on $(OS_detected)"
.PHONY: checkmetrics
checkmetrics: $(PROMTOOL) checkmetrics: $(PROMTOOL)
@echo ">> checking metrics for correctness" @echo ">> checking metrics for correctness"
./checkmetrics.sh $(PROMTOOL) $(e2e-out) ./checkmetrics.sh $(PROMTOOL) $(e2e-out)
.PHONY: docker
docker: docker:
ifeq ($(MACH), ppc64le) ifeq ($(MACH), ppc64le)
$(eval DOCKERFILE=Dockerfile.ppc64le) $(eval DOCKERFILE=Dockerfile.ppc64le)
@ -105,17 +112,11 @@ endif
@echo ">> building docker image from $(DOCKERFILE)" @echo ">> building docker image from $(DOCKERFILE)"
@docker build --file $(DOCKERFILE) -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . @docker build --file $(DOCKERFILE) -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
.PHONY: test-docker
test-docker: test-docker:
@echo ">> testing docker image" @echo ">> testing docker image"
./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9100 ./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9100
.PHONY: promtool $(FIRST_GOPATH)/bin/promtool
$(FIRST_GOPATH)/bin/promtool promtool: $(FIRST_GOPATH)/bin/promtool promtool:
@GOOS= GOARCH= $(GO) get -u github.com/prometheus/prometheus/cmd/promtool @GOOS= GOARCH= $(GO) get -u github.com/prometheus/prometheus/cmd/promtool
.PHONY: test-e2e promtool checkmetrics
# Declaring the binaries at their default locations as PHONY targets is a hack
# to ensure the latest version is downloaded on every make execution.
# If this is not desired, copy/symlink these binaries to a different path and
# set the respective environment variables.
.PHONY: $(FIRST_GOPATH)/bin/promtool

59
Makefile.common

@ -36,14 +36,23 @@ pkgs = ./...
PREFIX ?= $(shell pwd) PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd) BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
DOCKER_REPO ?= prom
.PHONY: all
all: style staticcheck unused build test all: style staticcheck unused build test
style: # This rule is used to forward a target like "build" to "common-build". This
# allows a new "build" target to be defined in a Makefile which includes this
# one and override "common-build" without override warnings.
%: common-% ;
.PHONY: common-style
common-style:
@echo ">> checking code style" @echo ">> checking code style"
! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' ! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
check_license: .PHONY: common-check_license
common-check_license:
@echo ">> checking license header" @echo ">> checking license header"
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \ @licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \ awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
@ -53,48 +62,66 @@ check_license:
exit 1; \ exit 1; \
fi fi
test-short: .PHONY: common-test-short
common-test-short:
@echo ">> running short tests" @echo ">> running short tests"
$(GO) test -short $(pkgs) $(GO) test -short $(pkgs)
test: .PHONY: common-test
common-test:
@echo ">> running all tests" @echo ">> running all tests"
$(GO) test -race $(pkgs) $(GO) test -race $(pkgs)
format: .PHONY: common-format
common-format:
@echo ">> formatting code" @echo ">> formatting code"
$(GO) fmt $(pkgs) $(GO) fmt $(pkgs)
vet: .PHONY: common-vet
common-vet:
@echo ">> vetting code" @echo ">> vetting code"
$(GO) vet $(pkgs) $(GO) vet $(pkgs)
staticcheck: $(STATICCHECK) .PHONY: common-staticcheck
common-staticcheck: $(STATICCHECK)
@echo ">> running staticcheck" @echo ">> running staticcheck"
$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
unused: $(GOVENDOR) .PHONY: common-unused
common-unused: $(GOVENDOR)
@echo ">> running check for unused packages" @echo ">> running check for unused packages"
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages' @$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
build: promu .PHONY: common-build
common-build: promu
@echo ">> building binaries" @echo ">> building binaries"
$(PROMU) build --prefix $(PREFIX) $(PROMU) build --prefix $(PREFIX)
tarball: promu .PHONY: common-tarball
common-tarball: promu
@echo ">> building release tarball" @echo ">> building release tarball"
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR) $(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
docker: .PHONY: common-docker
docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . common-docker:
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
.PHONY: common-docker-publish
common-docker-publish:
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"
.PHONY: common-docker-tag-latest
common-docker-tag-latest:
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):latest"
.PHONY: promu
promu: promu:
GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
$(FIRST_GOPATH)/bin/staticcheck: .PHONY: $(STATICCHECK)
$(STATICCHECK):
GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
$(FIRST_GOPATH)/bin/govendor: .PHONY: $(GOVENDOR)
$(GOVENDOR):
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
.PHONY: all style check_license format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH)/bin/staticcheck govendor $(FIRST_GOPATH)/bin/govendor
Loading…
Cancel
Save