From 96bee434b9b6a30059bb46cb733b2baa738b3ff9 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Wed, 7 Feb 2018 18:36:50 +0100 Subject: [PATCH] Build and publish Docker image in circleci pipeline (#67) Fixes #57 --- .circleci/config.yml | 29 ++++++++++++++++++++++++++++- Makefile | 19 +++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 72b95d868..79941f8fa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,6 +45,27 @@ jobs: - restore_cache: key: vendor-{{ checksum "Gopkg.lock" }} - run: go build -o machine-controller github.com/kubermatic/machine-controller/cmd/controller + - save_cache: + key: machine-controller-{{ .Revision }} + paths: + - machine-controller + + publish: + docker: + - image: docker:stable + working_directory: /go/src/github.com/kubermatic/machine-controller + steps: + - restore_cache: + key: repo-{{ .Environment.CIRCLE_SHA1 }} + - restore_cache: + key: machine-controller-{{ .Revision }} + - setup_remote_docker + - run: apk update && apk add make bash git + - run: | + set -e + export GIT_TAG=$CIRCLE_TAG + docker login -u "${DOCKERHUB_USER}" -p "${DOCKERHUB_PASS}" + make docker-image-nodep workflows: version: 2 @@ -60,4 +81,10 @@ workflows: - build: requires: - install-dependencies - + - publish: + requires: + - build + filters: + branches: + only: + - master diff --git a/Makefile b/Makefile index 5eb2a4295..be762a72c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +SHELL = /bin/bash + REGISTRY ?= docker.io REGISTRY_NAMESPACE ?= kubermatic @@ -19,7 +21,20 @@ machine-controller: $(shell find cmd pkg -name '*.go') vendor github.com/kubermatic/machine-controller/cmd/controller docker-image: machine-controller - docker build -t $(IMAGE_NAME) . + make docker-image-nodep -push: docker-image +# This target exists because in our CI +# we do not want to restore the vendor +# folder for the push step, but we know +# for sure it is not required there +docker-image-nodep: + docker build -t $(IMAGE_NAME) . docker push $(IMAGE_NAME) + if [[ -n "$(GIT_TAG)" ]]; then \ + $(eval IMAGE_TAG = $(GIT_TAG)) \ + docker build -t $(IMAGE_NAME) . && \ + docker push $(IMAGE_NAME) && \ + $(eval IMAGE_TAG = latest) \ + docker build -t $(IMAGE_NAME) . ;\ + docker push $(IMAGE_NAME) ;\ + fi