Skip to content

Conversation

@euanh
Copy link
Contributor

@euanh euanh commented Jul 3, 2018

make check will now regenerate the .pb.go files and fail if the results are different from what is checked into the repository.

@euanh
Copy link
Contributor Author

euanh commented Jul 3, 2018

@fcrisciani As discussed in #2193. I can hook this up to the main build target if you prefer.

@fcrisciani
Copy link

@euanh wondering if from a CI point of view, makes sense to separate the protobuf generation as a separate workflow and run it in parallel with the rest of them after the builder. what do you think?

Makefile Outdated
dockerbuildargs ?= --target dev - < Dockerfile
dockerargs ?= --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork
dockerargs ?= --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork ${dockerargs_extra}
dockerargs_extra ?=

Choose a reason for hiding this comment

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

don't see this as being used, is it still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, as I said in the commit message it's there to make it easy to add extra arguments to the docker command line, for instance to bind mount an extra volume on a development machine.

working_directory: ~/go/src/github.com/docker/libnetwork
docker:
- image: 'circleci/golang:1.10'
- image: 'circleci/golang:1.10.2'

Choose a reason for hiding this comment

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

this image is irrelevant, everything is built within a container, we can probably take something smaller also

Copy link
Contributor Author

@euanh euanh Jul 4, 2018

Choose a reason for hiding this comment

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

Yes. It would be better not to have Go in the base image at all, so there is no chance that a new build job accidentally uses it.

The image we use comes from here: https://github.com/circleci-public/circleci-dockerfiles. There isn't a minimal image in that repo. We could try https://hub.docker.com/r/circleci/slim-base/ but I don't know if it's actively maintained. CircleCI requires a few utilities in the image https://circleci.com/docs/2.0/custom-images so we could make an Alpine-based image, but then we would have to maintain it.

@euanh euanh force-pushed the protobuf-check branch 2 times, most recently from c252f7f to b7413ec Compare July 4, 2018 12:54
@euanh
Copy link
Contributor Author

euanh commented Jul 4, 2018

@fcrisciani I can put it in a separate workflow if you prefer. However keeping it in make check could make it more likely that you will run it on your own machine before submitting.

@fcrisciani
Copy link

@euanh it's ok to keep it then in the check, and the rename of the workflow makes sense.
Something seems still to not work properly in the check

@euanh
Copy link
Contributor Author

euanh commented Jul 6, 2018

@fcrisciani Yes, I haven't pushed my fix for check yet. It's broken here because in CI we don't copy the .git directory into the libnetworkbuild container, so my approach of rebuilding the .pb.go files and then running git diff won't work. (We copy rather than bind mounting because we are using the docker executor, for which bind mounts are disallowed: https://discuss.circleci.com/t/why-circleci-2-0-does-not-support-mounting-folders/11605)

@selansen
Copy link
Contributor

selansen commented Jul 6, 2018

we specifically made that change for circle2.0 (coping the source) for the same reason you mentioned above. If you want to copy other files (.git), you can make changes in .dockerignore file and remove .git from the file. that will help you.

@euanh
Copy link
Contributor Author

euanh commented Jul 6, 2018

@selansen Yes, however adding .git to the build container means copying an ever-growing amount of extra data - currently 27MB. It would be better if we didn't have to do that.

@fcrisciani
Copy link

fcrisciani commented Jul 6, 2018

@euanh what if the CI will generate the protobuf in a tmp directory and then you do the diff from there?

@euanh
Copy link
Contributor Author

euanh commented Jul 6, 2018

@fcrisciani That's what I have. :) It's currently just implemented with a rather ugly rule which I'm tidying up.

@fcrisciani
Copy link

@euanh no git diff, but diff

@euanh
Copy link
Contributor Author

euanh commented Jul 6, 2018

@fcrisciani Yes, I meant that's what I have at the moment on my machine, but I haven't pushed it yet.

@euanh euanh force-pushed the protobuf-check branch from b7413ec to 62f83b3 Compare July 6, 2018 16:51
@euanh
Copy link
Contributor Author

euanh commented Jul 6, 2018

The top change overloads the .protoc -> .pb.go rule to have a 'check mode'. The command line is duplicated but that's easy to fix. Having an if statement in there at all is a bit ugly - I also had a version which built the .pb.go files to /tmp by overriding the GOGO_OUTDIR. After that I could just loop over them and compare.

%.pb.go: %.proto
@if [ ${PROTOC_CHECK} ]; then \
protoc -I=. -I=/go/src -I=/go/src/github.com/gogo/protobuf -I=/go/src/github.com/gogo/protobuf/protobuf --gogo_out=/tmp $< ; \
diff -q $@ /tmp/$@ >/dev/null || (echo "👹 $@ is out of date; please run 'make protobuf' and check in updates" && exit 1) ; \

Choose a reason for hiding this comment

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

what if we pass the --gogo_out path directly as an ENV variable like we do for dockerbuildargs (https://github.com/docker/libnetwork/pull/2217/files#diff-1d37e48f9ceff6d8030570cd36286a61L9)
that way we don't need PROTOC_CHECK, locally you will always want to regenerate them eventually.

Choose a reason for hiding this comment

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

or you can also use the notion of the CIRCLE_CI env variable that is already passed and set at the top of the makefile the output path so no need to specify other env variables

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 would prefer for make check to work in the same way whether you run it in CircleCI or on your own machine, so I can't use the CIRCLE_CI variable.

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 also tried passing --gogo_out path as a variable, but then you still have to decide whether or not to run diff so it doesn't help much.

euanh added 4 commits July 10, 2018 17:01
Signed-off-by: Euan Harris <euan.harris@docker.com>
Add documentation and move protobuf target into Build section

Signed-off-by: Euan Harris <euan.harris@docker.com>
Outside the build container, run: make protobuf
Inside the build container, run: make protobuf-local

Signed-off-by: Euan Harris <euan.harris@docker.com>
'make check' will now fail if the files produced by re-running protoc
differ from those which are checked into the repository.

Signed-off-by: Euan Harris <euan.harris@docker.com>
Copy link

@fcrisciani fcrisciani left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants