Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build docker image in circleci pipeline #67

Merged

Conversation

alvaroaleman
Copy link
Contributor

@alvaroaleman alvaroaleman commented Feb 5, 2018

What this PR does / why we need it:

Automatically publish a docker image via CircleCI

Which issue(s) this PR fixes:
Fixes #57

Special notes for your reviewer:

Makefile Outdated
@@ -20,6 +20,13 @@ machine-controller: $(shell find cmd pkg -name '*.go') vendor

docker-image: machine-controller
docker build -t $(IMAGE_NAME) .
if git describe --tags $(shell git rev-parse HEAD)|grep -v -- '-g'; then \
$(eval IMAGE_TAG = $(shell git describe --abbrev=0 --tags)) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the tag from the circle ci environment variables: https://circleci.com/docs/2.0/env-vars/#build-details

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind - i'm an idiot. Obviously those are not suitable for the Makefile 🤦‍♂️

@alvaroaleman alvaroaleman changed the title WIP: Build docker image in circleci pipeline Build docker image in circleci pipeline Feb 6, 2018
Makefile Outdated
@@ -19,7 +21,26 @@ machine-controller: $(shell find cmd pkg -name '*.go') vendor
github.com/kubermatic/machine-controller/cmd/controller

docker-image: machine-controller
make docker-image-nodep

docker-image-nodep:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what means nodep?

Copy link
Contributor Author

@alvaroaleman alvaroaleman Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thats rather non-obvious. The reason is that make uses timestamps on files to determine if it has to rebuild something. CircleCI uses caches from any build, which means that sometimes it restores the vendor folder from an older build. The result is:

  • Make sees Gopkg.{toml,lock} are newer than the vender folder
  • -> Have to build the vendor target
  • -> Vendor target is newer than the binary ->Have to rebuild the binary

To skip all that (which makes perfect sense locally btw), I added that -nodep target

Makefile Outdated
docker build -t $(IMAGE_NAME) .
if git describe --tags $(shell git rev-parse HEAD)|grep -v -- '-g'; then \
$(eval IMAGE_TAG = $(shell git describe --abbrev=0 --tags)) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there are 2 things for me here:

  • I would rather have 1 task called push which builds the image and pushes it. - Why have 2 tasks for it?
  • I would rather use an environment variable for the tag. Parsing some output always makes me cringe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could merge the targets, but I dislike relying on CI-Implementiation-Specific env vars

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the env var, i use TAG or something within the makefile and in the pipeline i would set ENV=CIRCLE_SHA1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done that

- machine-controller

publish:
machine: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why machine instead of

    docker:
      - image: docker:stable

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that's what I found in the docs: https://circleci.com/docs/2.0/building-docker-images/#example


publish:
machine: true
steps:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify:
working_directory: /go/src/github.com/kubermatic/machine-controller
On the publish level, so you dont have to do a change-directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I tried that, makes the build instantly fails because that dir doesn' exist

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker version &&
set -u &&
docker login -u "${DOCKERHUB_USER}" -p "${DOCKERHUB_PASS}" &&
make push-nodep
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why && here?

Why not simply:

      - run: |
          make docker-image-nodep 
          ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, combined with a set -x that will do the same, I can change it

- run: >
cd /go/src/github.com/kubermatic/machine-controller &&
make docker-image-nodep &&
docker login --help &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats that for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging ;) Will remove

machine: true
steps:
- run: >
sudo mkdir -p /go/src/github.com/kubermatic/machine-controller &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sudo should not be required. If its required, we a producing this binary with wrong permissions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not required because of the binary, it is required to create the folders

@alvaroaleman
Copy link
Contributor Author

@mrIncompetent PTAL, all comments should be addressed now. You can check a successfully push in th build for 900ecc5

@alvaroaleman alvaroaleman merged commit 96bee43 into kubermatic:master Feb 7, 2018
@ghost ghost removed the review label Feb 7, 2018
@alvaroaleman alvaroaleman deleted the 57-extend-circleci-pipeline branch February 9, 2018 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend circle pipeline
2 participants