Skip to content

Commit

Permalink
pipeline: publish to docker hub (#229)
Browse files Browse the repository at this point in the history
* pipeline: publish to docker hub

E.g., for v2.3.1, publish :2.3.1 :2.3 :2
For v2.3.1-pre1, publish only :2.3.1-pre1

Also fixes dockerfile to use golang1.13
  • Loading branch information
nickatsegment authored Sep 24, 2019
1 parent f581b8e commit 1fdf2cc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ jobs:
command: |
make -f Makefile.release publish-github
publish-dockerhub:
docker:
- image: circleci/golang:1.13
steps:
- checkout
- attach_workspace: { at: . }
- setup_remote_docker
- run:
name: Release
command: |
docker login -u $DOCKER_USER -p $DOCKER_PASS
make -f Makefile.release publish-dockerhub
workflows:
version: 2
test-dist-publish:
Expand Down Expand Up @@ -129,3 +142,14 @@ workflows:
# release only on tag push events like vX[.Y.Z...][-whatever]
tags:
only: /v[0-9]+(\.[0-9]+)*(-[a-zA-Z0-9-]+)?/
- publish-dockerhub:
context: docker-publish
requires:
- dist
filters:
# never publish from a branch event
branches:
ignore: /.*/
# release only on tag push events like vX[.Y.Z...][-whatever]
tags:
only: /v[0-9]+(\.[0-9]+)*(-[a-zA-Z0-9-]+)?/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11-alpine AS build
FROM golang:1.13-alpine AS build

WORKDIR /go/src/github.com/segmentio/chamber
COPY . .
Expand Down
17 changes: 2 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This makefile is meant for humans

VERSION := $(shell git describe --tags --always --dirty="-dev")
VERSION_NO_V := $(shell git describe --tags --always --dirty="-dev" | sed 's/^v//')
VERSION_MAJOR_MINOR_PATCH := $(shell git describe --tags --always --dirty="-dev" | sed 's/^v\([0-9]*.[0-9]*.[0-9]*\).*/\1/')
VERSION_MAJOR_MINOR := $(shell git describe --tags --always --dirty="-dev" | sed 's/^v\([0-9]*.[0-9]*\).*/\1/')
VERSION_MAJOR := $(shell git describe --tags --always --dirty="-dev" | sed 's/^v\([0-9]*\).*/\1/')
Expand Down Expand Up @@ -39,18 +40,4 @@ dist/chamber-$(VERSION)-linux-amd64: | dist/
dist/chamber-$(VERSION)-windows-amd64.exe: | dist/
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -mod=vendor $(LDFLAGS) -o $@

docker-image: docker-image-$(VERSION)

docker-image-$(VERSION):
docker build \
-t segment/chamber:$(VERSION_MAJOR_MINOR_PATCH) \
-t segment/chamber:$(VERSION_MAJOR_MINOR) \
-t segment/chamber:$(VERSION_MAJOR) \
.

docker-image-publish: docker-image
docker push segment/chamber:$(VERSION_MAJOR_MINOR_PATCH)
docker push segment/chamber:$(VERSION_MAJOR_MINOR)
docker push segment/chamber:$(VERSION_MAJOR)

.PHONY: clean all linux docker-image docker-image-$(VERSION) docker-image-publish build
.PHONY: clean all linux
14 changes: 14 additions & 0 deletions Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include Makefile
ifneq (,$(findstring -,$(VERSION)))
GITHUB_RELEASE_FLAGS := "--pre-release"
PACKAGECLOUD_NAME_SUFFIX := "-prerelease"
DOCKERHUB_TAG_PREFIX := "prerelease-"
endif

PACKAGECLOUD_DEB_DISTROS := \
Expand Down Expand Up @@ -110,6 +111,18 @@ publish-packagecloud-rpm: dist/chamber_$(VERSION)_amd64.rpm packagecloud.conf.js
grep -v 'with token:' ; \
done

publish-dockerhub:
docker build \
-t segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR_MINOR_PATCH) \
-t segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR_MINOR) \
-t segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR) \
-t segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_NO_V) \
.
docker push segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR_MINOR_PATCH)
docker push segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR_MINOR)
docker push segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR)
docker push segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_NO_V)

dist: dist/chamber-$(VERSION)-darwin-amd64 dist/chamber-$(VERSION)-linux-amd64 dist/chamber-$(VERSION)-windows-amd64.exe dist/chamber_$(VERSION)_amd64.deb dist/chamber_$(VERSION)_amd64.rpm dist/chamber-$(VERSION).sha256sums

dist/chamber-$(VERSION).sha256sums: dist/chamber-$(VERSION)-darwin-amd64 dist/chamber-$(VERSION)-linux-amd64 dist/chamber-$(VERSION)-windows-amd64.exe dist/chamber_$(VERSION)_amd64.deb dist/chamber_$(VERSION)_amd64.rpm
Expand All @@ -131,4 +144,5 @@ dist/chamber_$(VERSION)_amd64.rpm: dist/nfpm-$(VERSION).yaml dist/chamber-$(VERS
publish-github-rpm \
publish-github-deb \
publish-github-darwin \
publish-dockerhub \
github-release

0 comments on commit 1fdf2cc

Please sign in to comment.