From 158200fd49f8691b085c5ad17835fe1feb1ef665 Mon Sep 17 00:00:00 2001 From: Steve Durrheimer Date: Sun, 24 Jan 2016 23:38:06 +0100 Subject: [PATCH] New release process using docker, circleci and a centralized building tool --- .dockerignore | 4 ++++ .gitignore | 9 ++++---- .promu.yml | 27 +++++++++++++++++++++++ .travis.yml | 10 ++------- Dockerfile | 5 ++++- Makefile | 54 +++++++++++++++++++++++++++++++++++---------- README.md | 13 +++++++++-- VERSION | 1 + circle.yml | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 158 insertions(+), 26 deletions(-) create mode 100644 .dockerignore create mode 100644 .promu.yml create mode 100644 VERSION create mode 100644 circle.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..1694cb06 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.build/ +.tarballs/ + +!.build/linux-amd64 diff --git a/.gitignore b/.gitignore index 78a0fab6..2e212948 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,8 @@ _testmain.go *.exe dependencies-stamp -node_exporter -.build -.deps -*.tar.gz +/node_exporter +/.build +/.deps +/.release +/.tarballs diff --git a/.promu.yml b/.promu.yml new file mode 100644 index 00000000..aa65811b --- /dev/null +++ b/.promu.yml @@ -0,0 +1,27 @@ +go: 1.5.4 +repository: + path: github.com/prometheus/node_exporter +build: + ldflags: | + -X main.Version={{.Version}} + -X {{repoPath}}/collector.Version={{.Version}} + -X {{repoPath}}/collector.Revision={{.Revision}} + -X {{repoPath}}/collector.Branch={{.Branch}} +tarball: + files: + - LICENSE + - NOTICE +crossbuild: + platforms: + - linux/amd64 + - linux/386 + - darwin/amd64 + - darwin/386 + - windows/amd64 + - windows/386 + - netbsd/amd64 + - netbsd/386 + - linux/arm + - linux/arm64 + - netbsd/arm + - linux/ppc64le diff --git a/.travis.yml b/.travis.yml index 872db93e..e4687918 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,15 +2,9 @@ sudo: false language: go go: -- 1.5.3 +- 1.5 - tip -env: -- GO15VENDOREXPERIMENT=1 - script: -- "! gofmt -l $(find . -path ./vendor -prune -o -name '*.go' -print) | read nothing" -- go vet -- go test -v $(go list ./... | grep -v /vendor/) -- go build +- make - ./end-to-end-test.sh diff --git a/Dockerfile b/Dockerfile index 78c658ae..e6ce19e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ -FROM sdurrheimer/alpine-golang-make-onbuild +FROM quay.io/prometheus/busybox:glibc MAINTAINER The Prometheus Authors +COPY node_exporter /bin/node_exporter + EXPOSE 9100 +ENTRYPOINT [ "/bin/node_exporter" ] diff --git a/Makefile b/Makefile index 10d7545c..ef94cec9 100644 --- a/Makefile +++ b/Makefile @@ -11,18 +11,50 @@ # See the License for the specific language governing permissions and # limitations under the License. -VERSION := 0.12.0rc3 -TARGET := node_exporter +GO := GO15VENDOREXPERIMENT=1 go +PROMU := $(GOPATH)/bin/promu +pkgs = $(shell $(GO) list ./... | grep -v /vendor/) -REVISION := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown') -BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown') +PREFIX ?= $(shell pwd) +BIN_DIR ?= $(shell pwd) +DOCKER_IMAGE_NAME ?= node-exporter +DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) -REPO_PATH := "github.com/prometheus/node_exporter" -LDFLAGS := -X main.Version=$(VERSION) -LDFLAGS += -X $(REPO_PATH)/collector.Version=$(VERSION) -LDFLAGS += -X $(REPO_PATH)/collector.Revision=$(REVISION) -LDFLAGS += -X $(REPO_PATH)/collector.Branch=$(BRANCH) -GOFLAGS := -ldflags "$(LDFLAGS)" +all: format build test -include Makefile.COMMON +style: + @echo ">> checking code style" + @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' + +test: + @echo ">> running tests" + @$(GO) test -short $(pkgs) + +format: + @echo ">> formatting code" + @$(GO) fmt $(pkgs) + +vet: + @echo ">> vetting code" + @$(GO) vet $(pkgs) + +build: promu + @echo ">> building binaries" + @$(PROMU) build --prefix $(PREFIX) + +tarball: promu + @echo ">> building release tarball" + @$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR) + +docker: + @echo ">> building docker image" + @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . + +promu: + @GOOS=$(shell uname -s | tr A-Z a-z) \ + GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \ + $(GO) get -u github.com/prometheus/promu + + +.PHONY: all style format build test vet tarball docker promu diff --git a/README.md b/README.md index 3a3d3472..e53366c9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ -# Node exporter +# Node exporter [![Build Status](https://travis-ci.org/prometheus/node_exporter.svg)][travis] -[![Build Status](https://travis-ci.org/prometheus/node_exporter.svg)](https://travis-ci.org/prometheus/node_exporter) +[![CircleCI](https://circleci.com/gh/prometheus/node_exporter/tree/master.svg?style=shield)][circleci] +[![Image Size & Layers](https://imagelayers.io/badge/prom/node-exporter:master.svg)][imagelayers] +[![Docker Stars](https://img.shields.io/docker/stars/prom/node-exporter.svg)][hub] +[![Docker Pulls](https://img.shields.io/docker/pulls/prom/node-exporter.svg)][hub] Prometheus exporter for machine metrics, written in Go with pluggable metric collectors. @@ -99,3 +102,9 @@ docker pull prom/node-exporter docker run -d -p 9100:9100 --net="host" prom/node-exporter ``` + + +[travis]: https://travis-ci.org/prometheus/node_exporter +[hub]: https://hub.docker.com/r/prom/node-exporter/ +[circleci]: https://circleci.com/gh/prometheus/node_exporter +[imagelayers]: https://imagelayers.io/?images=prom/node-exporter:master diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..5cd5c4ff --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.12.0rc3 diff --git a/circle.yml b/circle.yml new file mode 100644 index 00000000..557ad179 --- /dev/null +++ b/circle.yml @@ -0,0 +1,61 @@ +machine: + 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.5.4-main + REPO_PATH: github.com/prometheus/node_exporter + pre: + - sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.1-circleci' + - sudo chmod 0755 /usr/bin/docker + - sudo curl -L 'https://github.com/aktau/github-release/releases/download/v0.6.2/linux-amd64-github-release.tar.bz2' | tar xvjf - --strip-components 3 -C $HOME/bin + services: + - docker + +dependencies: + pre: + - go get -u github.com/prometheus/promu + - docker info + override: + - promu crossbuild + - ln -s .build/linux-amd64/node_exporter node_exporter + - | + 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 + post: + - mkdir $CIRCLE_ARTIFACTS/binaries/ && cp -a .build/* $CIRCLE_ARTIFACTS/binaries/ + - docker images + +test: + override: + - docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T + +deployment: + hub_branch: + branch: master + owner: prometheus + commands: + - docker login -e $DOCKER_EMAIL -u $DOCKER_LOGIN -p $DOCKER_PASSWORD + - docker login -e $QUAY_EMAIL -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io + - docker push $DOCKER_IMAGE_NAME + - docker push $QUAY_IMAGE_NAME + hub_tag: + tag: /^[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/ + owner: prometheus + commands: + - promu crossbuild tarballs + - promu release .tarballs + - mkdir $CIRCLE_ARTIFACTS/releases/ && cp -a .tarballs/* $CIRCLE_ARTIFACTS/releases/ + - docker login -e $DOCKER_EMAIL -u $DOCKER_LOGIN -p $DOCKER_PASSWORD + - docker login -e $QUAY_EMAIL -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io + - | + if [[ "$CIRCLE_TAG" =~ ^[0-9]+(\.[0-9]+){2}$ ]]; then + docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest" + docker tag "$QUAY_IMAGE_NAME:$CIRCLE_TAG" "$QUAY_IMAGE_NAME:latest" + fi + - docker push $DOCKER_IMAGE_NAME + - docker push $QUAY_IMAGE_NAME