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 checks in container #1012

Merged
merged 1 commit into from
Oct 18, 2017
Merged

Conversation

chrisplo
Copy link
Contributor

@chrisplo chrisplo commented Oct 16, 2017

Before the only option was to spin up a VM to run code checks, which is
expensive in terms of time.

Add Dockerfile-check to provide a container build for a runtime
environment that supports go tool vet, gofmt, and golint

Add script 'code_checks_in_docker.sh' intended to be run inside the
Dockerfile-check container that runs make checks which in turn runs a
variety of go code checks against packages passed in.

Checks are reordered so more severe issues (e.g. functional) are
resolved before less severe ones (e.g. formatting).

Some checks are upated to be simpler and faster because the command
accept multiple directories and recurse automatically.

Drive-by:

  • removed some trailing whitespace
  • found another binary to exclude in dockerignore
  • variables for go check commands not needed, they are only refernced
    once and require a visual lookup to find what the command actually
    is

Signed-off-by: Chris Plock chrisplo@cisco.com

@chrisplo chrisplo changed the title Build checks in container, blocked on #1008 #1009 Build checks in container, blocked on #1008 #1007 Oct 16, 2017
@chrisplo chrisplo changed the title Build checks in container, blocked on #1008 #1007 Build checks in container, blocked on #1008 #1007 #1009 Oct 16, 2017
Makefile Outdated
tar: compile-with-docker
docker run --rm netplugin-build:$(NETPLUGIN_CONTAINER_TAG) \
-C /go/src/github.com/contiv/netplugin netplugin-version \
| tar -x netplugin-version
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use docker cp here. Piping can break if there's any Docker regression.

Copy link
Contributor Author

@chrisplo chrisplo Oct 16, 2017

Choose a reason for hiding this comment

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

From the docs: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-

At this point there has never been a container, only an image, so there is no way I could use docker cp (without docker run, then docker cp, then docker rm)

Copy link
Contributor

Choose a reason for hiding this comment

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

@chrisplo: You can use docker create to create a container without running. You can remove it with docker rm.

Relying on the stdout isn't recommended. There have been regressions in the past with relying on piping from stdout and piping via stdin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, I'll update with create/cp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually did this in #1008, and removed this section as we don't depend on it for this PR

Makefile Outdated
docker run --rm netplugin-build:$(NETPLUGIN_CONTAINER_TAG) \
-C /go/src/github.com/contiv/netplugin netplugin-version \
| tar -x netplugin-version
docker run --rm netplugin-build:$(NETPLUGIN_CONTAINER_TAG) \
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same as above - it should be done using docker cp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did this in #1008, and removed this section as we don't depend on it for this PR

@@ -0,0 +1,19 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep using the Makefile checks for now. This script would get blown away soon.

Dockerfile-check Outdated
WORKDIR /go/src/github.com/contiv/netplugin/
ENTRYPOINT ["/code_checks.sh"]

RUN go get github.com/tools/godep github.com/aktau/github-release \
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use https://github.com/contiv/netplugin/blob/master/scripts/deps by invoking the right Makefile target.

@chrisplo chrisplo changed the title Build checks in container, blocked on #1008 #1007 #1009 Build checks in container, blocked on #1008 #1009 Oct 16, 2017
@chrisplo chrisplo force-pushed the build_checks_in_container branch 2 times, most recently from 01da373 to 8b4fa20 Compare October 16, 2017 22:04
@chrisplo chrisplo changed the title Build checks in container, blocked on #1008 #1009 Build checks in container Oct 16, 2017
Dockerfile-check Outdated
@@ -0,0 +1,15 @@
ARG TAG=latest
Copy link
Contributor

Choose a reason for hiding this comment

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

General comments on this file:

We do something similar already in auth_proxy, take a look at Dockerfile.checks

In general, we want to COPY in the code to be checked as one of the last operations in the Dockerfile (for caching reasons). Bindmounting + SELinux = nightmare land, and it also prevents the use of docker-machine in general

Copy link
Contributor Author

Choose a reason for hiding this comment

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

COPY is at the end, though this ARG was leftover from an earlier incantation (for FROM) I'll remove

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, you're COPYing in the script, that's fine...

What I'm saying is we need to COPY in all the code to be checked, e.g.,:

COPY ./ /go/src/github.com/contiv/netplugin

We shouldn't use a bindmount on line 95 in Makefile

@@ -0,0 +1,19 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to whatever script we end up using, these tools are slooooooow unless you exclude vendor. PTAL at https://github.com/contiv/auth_proxy/blob/6340df9b07a1723e2419069ebb5c0d5be6850a2e/scripts/checks_in_container.sh#L10-L11

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, I borrowed PKG_DIRS which already filtered out vendor
EXCLUDE_DIRS := bin docs Godeps scripts vagrant vendor install
PKG_DIRS := $(filter-out $(EXCLUDE_DIRS),$(subst /,,$(sort $(dir $(wildcard */)))))

Dockerfile-check Outdated

WORKDIR /go/src/github.com/contiv/netplugin/

RUN go get github.com/tools/godep github.com/aktau/github-release \
Copy link
Contributor

Choose a reason for hiding this comment

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

Is github.com/aktau/github-release here intentionally? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was copied, removed!

Before the only option was to spin up a VM to run code checks, which is
expensive in terms of time.

Add Dockerfile-check to provide a container build for a runtime
environment that supports go tool vet, gofmt, and golint

Add script 'code_checks_in_docker.sh' intended to be run inside the
Dockerfile-check container that runs `make checks` which in turn runs a
variety of go code checks against packages passed in.

Checks are reordered so more severe issues (e.g. functional) are
resolved before less severe ones (e.g. formatting).

Some checks are upated to be simpler and faster because the command
accept multiple directories and recurse automatically.

Drive-by:
* removed some trailing whitespace
* added more exclusions in dockerignore
* variables for go check commands not needed, they are only refernced
  once and require a visual lookup to find what the command actually
  is

Signed-off-by: Chris Plock <chrisplo@cisco.com>
@dseevr dseevr requested a review from unclejack October 17, 2017 21:19
@dseevr
Copy link
Contributor

dseevr commented Oct 17, 2017

@unclejack PTAL and merge if it looks good to you

@chrisplo
Copy link
Contributor Author

build pr

@rchirakk
Copy link
Contributor

LGTM, thx for fixing vet/lint/fmt.
another option for quick build/check is "make run-build"

@chrisplo
Copy link
Contributor Author

build PR

1 similar comment
@chrisplo
Copy link
Contributor Author

build PR

@chrisplo chrisplo merged commit e48a518 into contiv:master Oct 18, 2017
@chrisplo chrisplo deleted the build_checks_in_container branch October 18, 2017 20:11
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.

4 participants