Skip to content

Add a fmt build target and make use of a go build cache. - #1558

Merged
thaJeztah merged 2 commits into
docker:masterfrom
ijc:build-tweaks
Dec 17, 2018
Merged

Add a fmt build target and make use of a go build cache.#1558
thaJeztah merged 2 commits into
docker:masterfrom
ijc:build-tweaks

Conversation

@ijc

@ijcijc commented Dec 10, 2018

Copy link
Copy Markdown
Contributor

A couple of (unrelated) tweaks to the build.

Firstly add a make -f dockerfile.Makefile fmt target which runs gofmt on all the non-vendored Go code as a developer convenience.

Secondly add (optional, but defaulted on) support for using a go build cache when using the dockerfile.Makefile targets. This speeds up repeated builds for me by 6x (over 1m to less than 10s), according to time make build -f docker.Makefile DOCKER_BUILDKIT=1 GO_BUILD_CACHE=y (or =n).

Signed-off-by: Ian Campbell <ijc@docker.com>
@codecov-io

codecov-io commented Dec 10, 2018

Copy link
Copy Markdown

Codecov Report

Merging #1558 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

@@ Coverage Diff @@## master #1558 +/- ##
==========================================
- Coverage 55.24% 55.23% -0.02% 
==========================================
Files 289 289 Lines 19381 19391 +10 ==========================================
+ Hits 10707 10710 +3 - Misses 7978 7984 +6 - Partials 696 697 +1

@silvin-lubecki

Copy link
Copy Markdown
Contributor

I'm not sure about the fmt target, which I think should be an IDE configuration for all golangs projects.
But 👍 for the go build cache.

@ijc

ijc commented Dec 10, 2018

Copy link
Copy Markdown
ContributorAuthor

The main benefit of the fmt target is it always uses the right version of gofmt from within the container (which matches the lint target etc), whereas an IDE might be picking up a different one from the host system.

Comment threaddocker.Makefile Outdated
Comment threaddocker.Makefile Outdated
With a docker build cache already primed with the build image I am seeing
`time make build -f docker.Makefile DOCKER_BUILDKIT=1 GO_BUILD_CACHE=n` takes
more than 1 minute.
By contrast `time make build -f docker.Makefile DOCKER_BUILDKIT=1
GO_BUILD_CACHE=y` takes less than 10s with a hot cache irrespective of whether
the source tree has changed
Signed-off-by: Ian Campbell <ijc@docker.com>
@ijc

ijc commented Dec 14, 2018

Copy link
Copy Markdown
ContributorAuthor

Is this mergeable @thaJeztah@silvin-lubecki or are there other changes you'd like to see?

Comment threadMakefile

.PHONY: fmt
fmt:
go list -f {{.Dir}} ./... | xargs gofmt -w -s -d

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh, actually; do we need to exclude vendor here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Not according to my testing when I wrote it:

$ go list -f {{.Dir}} ./... | grep vendor
$

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting; wonder why it's needed in the other parts of the Makefile then 🤔. Maybe if they're running from inside a different directory

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I believe it wasn't always the case with older versions of the go tooling. I suspect the two places which grep the vendor dir out are just out of date, but they both also want to exclude e2e so there isn't a whole lot of worthwhile cleanup to be done.

@silvin-lubeckisilvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

@thaJeztahthaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@thaJeztah
thaJeztah merged commit 298c423 into docker:masterDec 17, 2018
@GordonTheTurtleGordonTheTurtle added this to the 19.03.0 milestone Dec 17, 2018
@ijc
ijc deleted the build-tweaks branch January 7, 2019 15:39
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@ijc@codecov-io@silvin-lubecki@thaJeztah@GordonTheTurtle