Enhance Dockerfile for local building#1002
Conversation
Added a caching layer in the docker build for compiling all of the vendor dependencies, drops compilation time to about 15s Added support in Dockerfile for passing BUILD_VERSION and USE_RELEASE to build.sh Add compile-with-docker target Split out how we get the git commit SHA so it's reusable for docker image tag
|
|
| CMD ["--help"] | ||
|
|
||
| COPY ./ /go/src/github.com/contiv/netplugin/ | ||
| # build the vendor dependencies |
There was a problem hiding this comment.
Since it's not obvious (apparently lol) why this is being done manually as a separate step, could you update the comment here to explain that this is for caching purposes because vendored code takes a long time to compile?
|
I pulled a compile target last minute as thought wasn't needed, need to restore, will add comments as well |
|
rechecked make |
|
build PR |
|
Now that #999 is merged, you can remove that |
| @@ -0,0 +1,13 @@ | |||
| #!/bin/bash | |||
|
|
|||
There was a problem hiding this comment.
Can we get a
set -euo pipefailhere? I think we should include it in every new script by default.
| if [ -n "$(git status --porcelain --untracked-files=no)" ]; then | ||
| GIT_COMMIT="$GIT_COMMIT-unsupported" | ||
| fi | ||
| echo $GIT_COMMIT |
There was a problem hiding this comment.
Inconsistent indentation on lines 8 and 9 vs. 4-7
Check out shfmt if you want an easy way to automatically tidy up scripts. We use this on auth_proxy and install
There was a problem hiding this comment.
wth is are tabs doing in there :/
| RUN GOPATH=/go/ \ | ||
| BUILD_VERSION="${BUILD_VERSION}" \ | ||
| USE_RELEASE="${USE_RELEASE}" \ | ||
| make compile \ |
There was a problem hiding this comment.
If you are compiling netplugin as part of docker build then you should add atleast checks here. Otherwise, we may not catching errors. If the idea is to make a quick build knowing that there are no code changes (for releases), then can Dockerfile only compile vendor directory and build the container. User can decide to skip tests when running the make using docker exec command
There was a problem hiding this comment.
I have checks for docker based build as a backlog item but this isn't replacing other ways to build so it's not required (yet), and this PR is long enough already.
I was planning to have a separate Dockerfile that does the checks after compile which I think matches development flow better and will be faster to iterate. Also, will allow choice as to when to run the checks based on which target is being run in the Makefile.
There was a problem hiding this comment.
Please add the development Dockerfile here (root directory) and move the one with no checks to a release directory. Please take care of it in a later PR
|
I will also check for changes due to PR1000 merging |
3766099 to
27a0a57
Compare
go-winio is now safe to include in compile strict bash checks and fix indents getGitCommit.sh switch docker build from USE_RELEASE to NIGHTLY_BUILD
27a0a57 to
1097d2a
Compare
|
build pr |
|
do you want me to pull apart the getGitCommit as separate PR @unclejack @dseevr ? |
|
It's required for this PR to be merged and function so it seems fine to me as it is |
|
when squash merging this please use the PR description as the commit msg (instead of the first commit msg) |
| docker build \ | ||
| --build-arg NIGHTLY_RELEASE=${NIGHTLY_RELEASE} \ | ||
| --build-arg BUILD_VERSION=${BUILD_VERSION} \ | ||
| -t netplugin:$${BUILD_VERSION:-devBuild}-$$(./scripts/getGitCommit.sh) . |
There was a problem hiding this comment.
devbuild not devBuild
|
build pr |
|
@unclejack PTAL and merge if it looks good |
| RUN GOPATH=/go/ \ | ||
| BUILD_VERSION="${BUILD_VERSION}" \ | ||
| USE_RELEASE="${USE_RELEASE}" \ | ||
| make compile \ |
There was a problem hiding this comment.
Please add the development Dockerfile here (root directory) and move the one with no checks to a release directory. Please take care of it in a later PR
| ARG BUILD_VERSION="" | ||
| ARG NIGHTLY_RELEASE="" | ||
|
|
||
| RUN GOPATH=/go/ \ |
There was a problem hiding this comment.
This Dockerfile should call make deps at some point to add the tools used to check if the source is fine to the image.
The executed command should include the checks target to run it before the build. This should reject code which doesn't meet the requirements.
| # fully prepares code for pushing to branch, includes building binaries | ||
| run-build: deps checks clean compile | ||
|
|
||
| compile-with-docker: |
There was a problem hiding this comment.
Could you set up these tasks like this, please?
host-compile-with-docker: -what we have in this target
compile-with-docker: - a wrapper which builds this in the Vagrant VM (e.g.: vagrant ssh netplugin-node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-compile-with-docker"')
It should be possible to invoke these targets on the host and on the VMs.
|
@chrisplo: Can you get rid of the merge commit and integrate the changes into their corresponding commits, please? |

Added a caching layer in the docker build for compiling all of the
vendor dependencies, drops compilation time to about 15s
Added support in Dockerfile for passing BUILD_VERSION and
NIGHTLY_RELEASE to build.sh
Add compile-with-docker target
Split out how we get the git commit SHA so it's reusable for docker
image tag