Skip to content

Commit

Permalink
Build and publish Docker image in circleci pipeline (#67)
Browse files Browse the repository at this point in the history
Fixes #57
  • Loading branch information
alvaroaleman authored Feb 7, 2018
1 parent 0d4e4d2 commit 96bee43
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
29 changes: 28 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,4 +81,10 @@ workflows:
- build:
requires:
- install-dependencies

- publish:
requires:
- build
filters:
branches:
only:
- master
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SHELL = /bin/bash

REGISTRY ?= docker.io
REGISTRY_NAMESPACE ?= kubermatic

Expand All @@ -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

0 comments on commit 96bee43

Please sign in to comment.