From f504de8013136ba8ec3954d21cea21fae5dce0ad Mon Sep 17 00:00:00 2001 From: sh0rez Date: Fri, 2 Aug 2019 20:09:19 +0200 Subject: [PATCH] chore(packaging): Release pipeline (#840) This PR sets up an automated release pipeline to cross compile build artifacts and publish them to github. mitchellh/gox is used for building, ghr for publishing --- .circleci/config.yml | 18 +++++++++++++++++- .gitignore | 1 + Makefile | 19 ++++++++++++++++++- loki-build-image/Dockerfile | 6 ++++-- tools/release | 9 +++++++++ tools/release-note.md | 25 +++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 4 deletions(-) create mode 100755 tools/release create mode 100644 tools/release-note.md diff --git a/.circleci/config.yml b/.circleci/config.yml index a3c3d94aaaff..e0882e5ca3dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,10 @@ version: 2 .tags: &tags # tags need to be explicitely defined (whitelist) tags: {only: "/.*/"} +.only-tags: &only-tags + <<: *tags + branches: { ignore: "/.*/" } + .tag-or-master: &tag-or-master branches: { only: master } <<: *tags @@ -49,6 +53,10 @@ workflows: requires: [ lint, test ] filters: { <<: *tag-or-master } + - publish/binaries: + requires: [ lint, test ] + filters: { <<: *only-tags } + - deploy: requires: - publish/loki @@ -68,7 +76,7 @@ workflows: # https://circleci.com/blog/circleci-hacks-reuse-yaml-in-your-circleci-config-with-yaml/ .defaults: &defaults docker: - - image: grafana/loki-build-image:0.4.0 + - image: grafana/loki-build-image:0.5.0 working_directory: /go/src/github.com/grafana/loki .machine: &machine @@ -203,6 +211,14 @@ jobs: name: docker-driver command: make docker-driver-push + publish/binaries: + <<: *defaults + steps: + - checkout + - run: + name: github release + command: make BUILD_IN_CONTAINER=false publish + deploy: <<: *defaults steps: diff --git a/.gitignore b/.gitignore index a9a40e0fb4fe..8d2250ea16e7 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ cmd/loki-canary/loki-canary /loki-canary dlv rootfs/ +dist diff --git a/Makefile b/Makefile index 2eaa7bec173a..c05b5e4b25a4 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ .PHONY: push-images push-latest save-images load-images promtail-image loki-image build-image .PHONY: bigtable-backup, push-bigtable-backup .PHONY: benchmark-store + +SHELL = /usr/bin/env bash ############# # Variables # ############# @@ -17,7 +19,7 @@ IMAGE_NAMES := $(foreach dir,$(DOCKER_IMAGE_DIRS),$(patsubst %,$(IMAGE_PREFIX)%, # make BUILD_IN_CONTAINER=false target # or you can override this with an environment variable BUILD_IN_CONTAINER ?= true -BUILD_IMAGE_VERSION := 0.4.0 +BUILD_IMAGE_VERSION := 0.5.0 # Docker image info IMAGE_PREFIX ?= grafana @@ -168,6 +170,20 @@ cmd/promtail/promtail-debug: $(APP_GO_FILES) pkg/promtail/server/ui/assets_vfsda CGO_ENABLED=0 go build $(DEBUG_GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) +############# +# Releasing # +############# +# concurrency is limited to 4 to prevent CircleCI from OOMing. Sorry +GOX = gox $(GO_FLAGS) -parallel=4 -output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -arch="amd64 arm64 arm" -os="linux" +dist: clean + CGO_ENABLED=0 $(GOX) ./cmd/loki + CGO_ENABLED=0 $(GOX) -osarch="darwin/amd64 windows/amd64 freebsd/amd64" ./cmd/promtail ./cmd/logcli + gzip dist/* + pushd dist && sha256sum * > SHA256SUMS && popd + +publish: dist + ./tools/release + ######## # Lint # ######## @@ -193,6 +209,7 @@ clean: rm -rf cmd/loki-canary/loki-canary rm -rf .cache rm -rf cmd/docker-driver/rootfs + rm -rf dist/ go clean ./... ######### diff --git a/loki-build-image/Dockerfile b/loki-build-image/Dockerfile index 9b149fda87d6..fd5cf172165c 100644 --- a/loki-build-image/Dockerfile +++ b/loki-build-image/Dockerfile @@ -18,7 +18,7 @@ FROM golang:1.11.4-stretch RUN apt-get update && \ apt-get install -qy \ musl \ - file unzip jq \ + file unzip jq gettext\ protobuf-compiler libprotobuf-dev \ libsystemd-dev && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* @@ -31,7 +31,9 @@ RUN go get \ github.com/gogo/protobuf/protoc-gen-gogoslick \ github.com/gogo/protobuf/gogoproto \ github.com/go-delve/delve/cmd/dlv \ - golang.org/x/tools/cmd/goyacc && \ + golang.org/x/tools/cmd/goyacc \ + github.com/mitchellh/gox \ + github.com/tcnksm/ghr && \ rm -rf /go/pkg /go/src ENV GOCACHE=/go/cache diff --git a/tools/release b/tools/release new file mode 100755 index 000000000000..180778a53b11 --- /dev/null +++ b/tools/release @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +ghr \ + -t "${GITHUB_TOKEN}" \ + -u "${CIRCLE_PROJECT_USERNAME}" \ + -r "${CIRCLE_PROJECT_REPONAME}" \ + -c "${CIRCLE_SHA1}" \ + -b="$(cat ./tools/release-note.md | envsubst)" \ + -delete -draft \ + "${CIRCLE_TAG}" ./dist/ diff --git a/tools/release-note.md b/tools/release-note.md new file mode 100644 index 000000000000..58317f1c0d80 --- /dev/null +++ b/tools/release-note.md @@ -0,0 +1,25 @@ +This is release `${CIRCLE_TAG}` of Loki. + +### Notable changes: +:warning: **ADD RELEASE NOTES HERE** :warning: + +### Installation: +The components of Loki are currently distributed in plain binary form and as Docker container images. Choose what fits your use-case best. + +#### Binary: +```bash +# download a binary (adapt app, os and arch as needed) +$ curl -fSL -o "/usr/local/bin/loki.gz" "https://github.com/grafana/loki/releases/download/${CIRCLE_TAG}/loki-linux-amd64.gz" +$ gunzip "/usr/local/bin/loki.gz" + +# make sure it is executable +$ chmod a+x "/usr/local/bin/loki" +``` + +#### Docker container: +* https://hub.docker.com/r/grafana/loki +* https://hub.docker.com/r/grafana/promtail +```bash +$ docker pull "grafana/loki:${CIRCLE_TAG}" +$ docker pull "grafana/promtail:${CIRCLE_TAG}" +```