New release process using docker, circleci and a centralized building tool
authorSteve Durrheimer <s.durrheimer@gmail.com>
Sat, 14 May 2016 11:52:25 +0000 (13:52 +0200)
committerSteve Durrheimer <s.durrheimer@gmail.com>
Sat, 14 May 2016 19:10:22 +0000 (21:10 +0200)
.dockerignore [new file with mode: 0644]
.gitignore
.promu.yml [new file with mode: 0644]
.travis.yml [new file with mode: 0644]
Dockerfile
Makefile
Makefile.COMMON [deleted file]
README.md
VERSION [new file with mode: 0644]
circle.yml [new file with mode: 0644]

diff --git a/.dockerignore b/.dockerignore
new file mode 100644 (file)
index 0000000..69c6945
--- /dev/null
@@ -0,0 +1,4 @@
+.build/
+.tarballs/
+
+!.build/linux-amd64/
index a7d0155b485d282516dd32070b868f6352c4e762..c4c951d3a22365e1f64e371a7ed3689609966442 100644 (file)
@@ -21,7 +21,9 @@ _testmain.go
 
 *.exe
 dependencies-stamp
-blackbox_exporter
-.build
+/blackbox_exporter
+/.build
+/.release
+/.tarballs
 .deps
 *.tar.gz
diff --git a/.promu.yml b/.promu.yml
new file mode 100644 (file)
index 0000000..48904d5
--- /dev/null
@@ -0,0 +1,12 @@
+go: 1.6.2
+repository:
+    path: github.com/prometheus/blackbox_exporter
+build:
+    flags: -a -tags netgo
+    ldflags: |
+        -X main.Version={{.Version}}
+tarball:
+    files:
+        - blackbox.yml
+        - LICENSE
+        - NOTICE
diff --git a/.travis.yml b/.travis.yml
new file mode 100644 (file)
index 0000000..24225ea
--- /dev/null
@@ -0,0 +1,10 @@
+sudo: false
+
+language: go
+
+go:
+- 1.5.4
+- 1.6.2
+
+script:
+- make
index 9fefe89b84650c61fe01c0c9d013f3d725bfd591..ddea2b3c9c7b37a57ccd77a522cf5442cf1a19e2 100644 (file)
@@ -1,4 +1,9 @@
-FROM        sdurrheimer/alpine-golang-make-onbuild
+FROM        quay.io/prometheus/busybox:latest
 MAINTAINER  The Prometheus Authors <prometheus-developers@googlegroups.com>
 
+COPY blackbox_exporter  /bin/blackbox_exporter
+COPY blackbox.yml       /etc/blackbox_exporter/config.yml
+
 EXPOSE      9115
+ENTRYPOINT  [ "/bin/blackbox_exporter" ]
+CMD         [ "-config.file=/etc/blackbox_exporter/config.yml" ]
index 0e1dccb86c84e567bf629422d178d305e708095e..ffbad58a190b29efe6d6a50c2088e191c14e60f7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# Copyright 2015 The Prometheus Authors
+# Copyright 2016 The Prometheus Authors
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-VERSION  := 0.2.0
-TARGET   := blackbox_exporter
-GOFLAGS  := -ldflags "-X main.Version=$(VERSION)"
+GO    := GO15VENDOREXPERIMENT=1 go
+PROMU := $(GOPATH)/bin/promu
+pkgs   = $(shell $(GO) list ./... | grep -v /vendor/)
 
-include Makefile.COMMON
+PREFIX                  ?= $(shell pwd)
+BIN_DIR                 ?= $(shell pwd)
+DOCKER_IMAGE_NAME       ?= blackbox-exporter
+DOCKER_IMAGE_TAG        ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
+
+
+all: format build test
+
+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/Makefile.COMMON b/Makefile.COMMON
deleted file mode 100644 (file)
index ac286fd..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-# Copyright 2015 The Prometheus Authors
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# THE AUTHORITATIVE VERSION OF THIS MAKEFILE LIVES IN:
-#
-#   https://github.com/prometheus/utils
-#
-# PLEASE MAKE ANY CHANGES THERE AND PROPAGATE THEM TO ALL PROMETHEUS
-# REPOSITORIES THAT ARE USING THIS MAKEFILE.
-#
-# This file provides common Makefile infrastructure for several Prometheus
-# components. This includes make tasks for downloading Go, setting up a
-# self-contained build environment, fetching Go dependencies, building
-# binaries, running tests, and doing release management. This file is intended
-# to be included from a project's Makefile, which needs to define the following
-# variables, at a minimum:
-#
-# * VERSION - The current version of the project in question.
-# * TARGET  - The desired name of the built binary.
-#
-# Many of the variables defined below are defined conditionally (using '?'),
-# which allows the project's main Makefile to override any of these settings, if
-# needed. See also:
-#
-# https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors.
-#
-# The including Makefile may define any number of extra targets that are
-# specific to that project.
-
-VERSION ?= $(error VERSION not set in including Makefile)
-TARGET  ?= $(error TARGET not set in including Makefile)
-
-SRC    ?= $(shell find . -type f -name "*.go" ! -path "./.build/*")
-GOOS   ?= $(shell uname | tr A-Z a-z)
-GOARCH ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m)))
-
-GO_VERSION ?= 1.5.3
-GOPATH     ?= $(CURDIR)/.build/gopath
-ROOTPKG    ?= github.com/prometheus/$(TARGET)
-SELFLINK   ?= $(GOPATH)/src/$(ROOTPKG)
-
-# Check for the correct version of go in the path. If we find it, use it.
-# Otherwise, prepare to build go locally.
-ifeq ($(shell command -v "go" >/dev/null && go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/'), $(GO_VERSION))
-       GOCC   ?= $(shell command -v "go")
-       GOFMT  ?= $(shell command -v "gofmt")
-       GO     ?= GOPATH=$(GOPATH) $(GOCC)
-else
-       GOURL  ?= https://golang.org/dl
-       GOPKG  ?= go$(GO_VERSION).$(GOOS)-$(GOARCH).tar.gz
-       GOROOT ?= $(CURDIR)/.build/go$(GO_VERSION)
-       GOCC   ?= $(GOROOT)/bin/go
-       GOFMT  ?= $(GOROOT)/bin/gofmt
-       GO     ?= GOPATH=$(GOPATH) GOROOT=$(GOROOT) $(GOCC)
-endif
-
-# Use vendored dependencies if available. Otherwise try to download them.
-ifneq (,$(wildcard vendor))
-       DEPENDENCIES := $(shell find vendor/ -type f -iname '*.go')
-       GO           := GO15VENDOREXPERIMENT=1 $(GO)
-else
-       DEPENDENCIES := dependencies-stamp
-endif
-
-# Never honor GOBIN, should it be set at all.
-unexport GOBIN
-
-SUFFIX   ?= $(GOOS)-$(GOARCH)
-BINARY   ?= $(TARGET)
-ARCHIVE  ?= $(TARGET)-$(VERSION).$(SUFFIX).tar.gz
-
-default: $(BINARY)
-
-$(BINARY): $(GOCC) $(SRC) $(DEPENDENCIES) Makefile Makefile.COMMON | $(SELFLINK)
-       cd $(SELFLINK) && $(GO) build $(GOFLAGS) -o $@
-
-.PHONY: archive
-archive: $(ARCHIVE)
-
-$(ARCHIVE): $(BINARY)
-       tar -czf $@ $<
-
-.PHONY: tag
-tag:
-       git tag $(VERSION)
-       git push --tags
-
-.PHONY: test
-test: $(GOCC) $(DEPENDENCIES) | $(SELFLINK)
-       cd $(SELFLINK) && $(GO) test $$($(GO) list ./... | grep -v /vendor/)
-
-.PHONY: format
-format: $(GOCC)
-       find . -iname '*.go' | egrep -v "^\./\.build|./generated|\./vendor|\.(l|y)\.go" | xargs -n1 $(GOFMT) -w -s=true
-
-.PHONY: clean
-clean:
-       rm -rf $(BINARY) $(ARCHIVE) .build *-stamp
-
-
-
-$(GOCC):
-       @echo Go version $(GO_VERSION) required but not found in PATH.
-       @echo About to download and install go$(GO_VERSION) to $(GOROOT)
-       @echo Abort now if you want to manually install it system-wide instead.
-       @echo
-       @sleep 5
-       mkdir -p .build
-       # The archive contains a single directory called 'go/'.
-       curl -L $(GOURL)/$(GOPKG) | tar -C .build -xzf -
-       rm -rf $(GOROOT)
-       mv .build/go $(GOROOT)
-
-$(SELFLINK):
-       mkdir -p $(dir $@)
-       ln -s $(CURDIR) $@
-
-# Download dependencies if project doesn't vendor them.
-dependencies-stamp: $(GOCC) $(SRC) | $(SELFLINK)
-       $(GO) get -d
-       touch $@
index 041ff29f6aeca500297715d73f7a8193fe31a276..1cc414a0982eeaeac6495093cbc1630858d91ee0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,4 +1,8 @@
-# Blackbox exporter
+# Blackbox exporter [![Build Status](https://travis-ci.org/prometheus/blackbox_exporter.svg)][travis]
+
+[![CircleCI](https://circleci.com/gh/prometheus/blackbox_exporter/tree/master.svg?style=shield)][circleci]
+[![Docker Repository on Quay](https://quay.io/repository/prometheus/blackbox-exporter/status)][quay]
+[![Docker Pulls](https://img.shields.io/docker/pulls/prom/blackbox-exporter.svg?maxAge=604800)][hub]
 
 The blackbox exporter allows blackbox probing of endpoints over
 HTTP, HTTPS, TCP and ICMP.
@@ -104,3 +108,9 @@ scrape_configs:
         target_label: __address__
         replacement: 127.0.0.1:9115  # Blackbox exporter.
 ```
+
+
+[circleci]: https://circleci.com/gh/prometheus/blackbox_exporter
+[hub]: https://hub.docker.com/r/prom/blackbox-exporter/
+[travis]: https://travis-ci.org/prometheus/blackbox_exporter
+[quay]: https://quay.io/repository/prometheus/blackbox-exporter
diff --git a/VERSION b/VERSION
new file mode 100644 (file)
index 0000000..0ea3a94
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.2.0
diff --git a/circle.yml b/circle.yml
new file mode 100644 (file)
index 0000000..1e3423f
--- /dev/null
@@ -0,0 +1,61 @@
+machine:
+  environment:
+    DOCKER_IMAGE_NAME: prom/blackbox-exporter
+    QUAY_IMAGE_NAME: quay.io/prometheus/blackbox-exporter
+    DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.6.2-main
+    REPO_PATH: github.com/prometheus/blackbox_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:
+    - make promu
+    - docker info
+  override:
+    - promu crossbuild
+    - ln -s .build/linux-amd64/blackbox_exporter blackbox_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