From 8688cf25793d762df66b92b17ae3d9ffb3b75846 Mon Sep 17 00:00:00 2001 From: Steve Durrheimer Date: Mon, 21 Dec 2015 18:09:38 +0100 Subject: [PATCH] New release process using docker, circleci and a centralized building tool --- .dockerignore | 6 +++-- .gitignore | 6 +++++ .promu.yml | 45 +++++++++++++++++++++++++++++++++ Dockerfile | 19 +++++--------- Makefile | 24 ++++++++++++------ README.md | 14 ++++++++++- circle.yml | 47 ++++++++++++++++++++++++++++++++-- scripts/build.sh | 46 ---------------------------------- scripts/goenv.sh | 50 ------------------------------------- scripts/release_tarballs.sh | 42 ------------------------------- 10 files changed, 136 insertions(+), 163 deletions(-) create mode 100644 .promu.yml delete mode 100755 scripts/build.sh delete mode 100755 scripts/goenv.sh delete mode 100755 scripts/release_tarballs.sh diff --git a/.dockerignore b/.dockerignore index 32d134f7d..a4d092b22 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ data/ -prometheus -promtool +.build/ +.tarballs/ + +!.build/linux-amd64/ diff --git a/.gitignore b/.gitignore index 89dabd032..38236068d 100644 --- a/.gitignore +++ b/.gitignore @@ -31,9 +31,15 @@ core benchmark.txt /data /.build +/.release +/.tarballs .#* command-line-arguments.test *BACKUP* *LOCAL* *REMOTE* + +!/circle.yml +!/.travis.yml +!/.promu.yml diff --git a/.promu.yml b/.promu.yml new file mode 100644 index 000000000..af3cffcaf --- /dev/null +++ b/.promu.yml @@ -0,0 +1,45 @@ +go: 1.5.4 +repository: + path: github.com/prometheus/prometheus +build: + binaries: + - name: prometheus + path: ./cmd/prometheus + - name: promtool + path: ./cmd/promtool + flags: -tags netgo + ldflags: | + -X {{repoPath}}/version.Version={{.Version}} + -X {{repoPath}}/version.Revision={{.Revision}} + -X {{repoPath}}/version.Branch={{.Branch}} + -X {{repoPath}}/version.BuildUser={{user}}@{{host}} + -X {{repoPath}}/version.BuildDate={{date "20060102-15:04:05"}} +tarball: + files: + - consoles + - console_libraries + - documentation/examples/prometheus.yml + - LICENSE + - NOTICE +crossbuild: + platforms: + - linux/amd64 + - linux/386 + - darwin/amd64 + - darwin/386 + - windows/amd64 + - windows/386 + - freebsd/amd64 + - freebsd/386 + - openbsd/amd64 + - openbsd/386 + - netbsd/amd64 + - netbsd/386 + - dragonfly/amd64 + - linux/arm + - linux/arm64 + - freebsd/arm + - openbsd/arm + - netbsd/arm + - linux/ppc64 + - linux/ppc64le diff --git a/Dockerfile b/Dockerfile index bafe497af..9be2ba6c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,11 @@ -FROM sdurrheimer/alpine-glibc +FROM prom/busybox:latest MAINTAINER The Prometheus Authors -WORKDIR /gopath/src/github.com/prometheus/prometheus -COPY . /gopath/src/github.com/prometheus/prometheus - -RUN apk add --update -t build-deps tar openssl git make bash \ - && source ./scripts/goenv.sh /go /gopath \ - && make build \ - && cp prometheus promtool /bin/ \ - && mkdir -p /etc/prometheus \ - && mv ./documentation/examples/prometheus.yml /etc/prometheus/prometheus.yml \ - && mv ./console_libraries/ ./consoles/ /etc/prometheus/ \ - && apk del --purge build-deps \ - && rm -rf /go /gopath /var/cache/apk/* +COPY prometheus /bin/prometheus +COPY promtool /bin/promtool +COPY documentation/examples/prometheus.yml /etc/prometheus/prometheus.yml +COPY console_libraries/ /etc/prometheus/ +COPY consoles/ /etc/prometheus/ EXPOSE 9090 VOLUME [ "/prometheus" ] diff --git a/Makefile b/Makefile index 5b02d736b..74dc3d1b6 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,11 @@ GO := GO15VENDOREXPERIMENT=1 go pkgs = $(shell $(GO) list ./... | grep -v /vendor/) +PREFIX ?= $(shell pwd) +BIN_DIR ?= $(shell pwd) +DOCKER_IMAGE_NAME ?= prometheus +DOCKER_IMAGE_TAG ?= $(shell git rev-parse --abbrev-ref HEAD) + ifdef DEBUG bindata_flags = -debug endif @@ -41,22 +46,27 @@ vet: @echo ">> vetting code" @$(GO) vet $(pkgs) -build: +build: promu @echo ">> building binaries" - @./scripts/build.sh + @promu build --prefix $(PREFIX) -tarballs: - @echo ">> building release tarballs" - @./scripts/release_tarballs.sh +tarball: promu + @echo ">> building release tarball" + @promu tarball --prefix $(PREFIX) $(BIN_DIR) docker: - @docker build -t prometheus:$(shell git rev-parse --short HEAD) . + @echo ">> building docker image" + @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . assets: @echo ">> writing assets" @$(GO) get -u github.com/jteeuwen/go-bindata/... @go-bindata $(bindata_flags) -pkg ui -o web/ui/bindata.go -ignore '(.*\.map|bootstrap\.js|bootstrap-theme\.css|bootstrap\.css)' web/ui/templates/... web/ui/static/... +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 check_license format build test vet docker assets tarballs +.PHONY: all style check_license format build test vet assets tarball docker promu diff --git a/README.md b/README.md index 23dd67b75..e7a9bdc76 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -# Prometheus [![Build Status](https://travis-ci.org/prometheus/prometheus.svg)](https://travis-ci.org/prometheus/prometheus) [![Circle CI](https://circleci.com/gh/prometheus/prometheus/tree/master.svg?style=svg)](https://circleci.com/gh/prometheus/prometheus/tree/master) +# Prometheus [![Build Status](https://travis-ci.org/prometheus/prometheus.svg)][travis] + +[![CircleCI](https://circleci.com/gh/prometheus/prometheus/tree/master.svg?style=shield)][circleci] +[![Docker Stars](https://img.shields.io/docker/stars/prom/prometheus.svg)][hub] +[![Docker Pulls](https://img.shields.io/docker/pulls/prom/prometheus.svg)][hub] +[![Image Size](https://img.shields.io/imagelayers/image-size/prom/prometheus/latest.svg)][imagelayers] +[![Image Layers](https://img.shields.io/imagelayers/layers/prom/prometheus/latest.svg)][imagelayers] Visit [prometheus.io](https://prometheus.io) for the full documentation, examples and guides. @@ -80,3 +86,9 @@ Refer to [CONTRIBUTING.md](CONTRIBUTING.md) ## License Apache License 2.0, see [LICENSE](LICENSE). + + +[travis]: https://travis-ci.org/prometheus/prometheus +[hub]: https://hub.docker.com/r/prom/prometheus/ +[circleci]: https://circleci.com/gh/prometheus/prometheus +[imagelayers]: https://imagelayers.io/?images=prom/prometheus:latest diff --git a/circle.yml b/circle.yml index b24c203ff..7eada8cc1 100644 --- a/circle.yml +++ b/circle.yml @@ -1,11 +1,54 @@ machine: + environment: + DOCKER_IMAGE_NAME: prom/prometheus + DOCKER_TEST_IMAGE_NAME: prom/golang-builder:1.5.3-main + REPO_PATH: github.com/prometheus/prometheus + 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: - - make docker + - promu crossbuild + - ln -s .build/linux-amd64/prometheus prometheus + - ln -s .build/linux-amd64/promtool promtool + - | + if [ -n "$CIRCLE_TAG" ]; then + make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG + else + make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME + fi + post: + - mkdir $CIRCLE_ARTIFACTS/binaries/ && cp -a .build/* $CIRCLE_ARTIFACTS/binaries/ + - docker images test: override: - - /bin/true + - 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 push $DOCKER_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 + - | + if [[ "$CIRCLE_TAG" =~ ^[0-9]+(\.[0-9]+){2}$ ]]; then + docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest" + fi + - docker push $DOCKER_IMAGE_NAME diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index a25dc9d8d..000000000 --- a/scripts/build.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash - -# 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. - -set -e - -repo_path="github.com/prometheus/prometheus" - -version=$( cat version/VERSION ) -revision=$( git rev-parse --short HEAD 2> /dev/null || echo 'unknown' ) -branch=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown' ) -host=$( hostname ) -build_date=$( TZ=UTC date +%Y%m%d-%H:%M:%S ) - -if [ "$(go env GOOS)" = "windows" ]; then - ext=".exe" -fi - -ldflags=" - -X ${repo_path}/version.Version=${version} - -X ${repo_path}/version.Revision=${revision} - -X ${repo_path}/version.Branch=${branch} - -X ${repo_path}/version.BuildUser=${USER}@${host} - -X ${repo_path}/version.BuildDate=${build_date} - ${EXTRA_LDFLAGS}" - -export GO15VENDOREXPERIMENT="1" - -echo " > prometheus" -go build -ldflags "${ldflags}" -o prometheus${ext} ${repo_path}/cmd/prometheus - -echo " > promtool" -go build -ldflags "${ldflags}" -o promtool${ext} ${repo_path}/cmd/promtool - -exit 0 diff --git a/scripts/goenv.sh b/scripts/goenv.sh deleted file mode 100755 index b665096ba..000000000 --- a/scripts/goenv.sh +++ /dev/null @@ -1,50 +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. - -goroot="$1" -gopath="$2" - -go_version_min="1.5" -go_version_install="1.5.3" - -vernum() { - printf "%03d%03d%03d" $(echo "$1" | tr '.' ' ') -} - -if command -v "go" >/dev/null; then - go_version=$(go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/') -fi - -# If we satisfy the version requirement, there is nothing to do. Otherwise -# proceed downloading and installing a go environment. -if [ $(vernum ${go_version}) -ge $(vernum ${go_version_min}) ]; then - return -fi - -export GOPATH="${gopath}" -export GOROOT="${goroot}/${go_version_install}" - -export PATH="$PATH:$GOROOT/bin" - -if [ ! -x "${GOROOT}/bin/go" ]; then - - mkdir -p "${GOROOT}" - - os=$(uname | tr A-Z a-z) - arch=$(uname -m | sed -e 's/x86_64/amd64/' | sed -e 's/i.86/386/') - - url="https://golang.org/dl" - tarball="go${go_version_install}.${os}-${arch}.tar.gz" - - wget -qO- "${url}/${tarball}" | tar -C "${GOROOT}" --strip 1 -xz -fi diff --git a/scripts/release_tarballs.sh b/scripts/release_tarballs.sh deleted file mode 100755 index b4b6b68e2..000000000 --- a/scripts/release_tarballs.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -# 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. - -set -e - -version=$(cat version/VERSION) - -for GOOS in "darwin" "freebsd" "linux" "windows"; do - for GOARCH in "amd64" "386"; do - export GOARCH - export GOOS - make build - - tarball_dir="prometheus-${version}.${GOOS}-${GOARCH}" - tarball="${tarball_dir}.tar.gz" - - if [ "$(go env GOOS)" = "windows" ]; then - ext=".exe" - fi - - echo " > $tarball" - mkdir -p "${tarball_dir}" - cp -a "prometheus${ext}" "promtool${ext}" consoles console_libraries "${tarball_dir}" - tar -czf "${tarball}" "${tarball_dir}" - rm -rf "${tarball_dir}" - rm "prometheus${ext}" "promtool${ext}" - done -done - -exit 0