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

Enhance Dockerfile for local building #1002

Merged
merged 5 commits into from
Oct 13, 2017

Conversation

chrisplo
Copy link
Contributor

@chrisplo chrisplo commented Oct 10, 2017

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

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
@chrisplo
Copy link
Contributor Author

  • added "${BUILD_VERSION:-devBuild}-" to the tag, otherwise detail output below is the same:
    examples:

BUILD_VERSION=1.2.3 make compile-with-docke
Successfully tagged netplugin:1.2.3-ecb31d87-unsupported

make compile-with-docker
Successfully tagged netplugin:devBuild-ecb31d87-unsupported

Detail with version info:

make compile-with-docker

scripts/build.sh
Version: 1.0.0-beta-10-10-2017.17-00-47.UTC
GitCommit: ecb31d8-unsupported
BuildTime: 10-10-2017.17-00-47.UTC

Successfully tagged netplugin:ecb31d87-unsupported
USE_RELEASE=y BUILD_VERSION=1.2.3 make compile-with-docker

Version: 1.2.3
GitCommit: ecb31d8-unsupported
BuildTime: 10-10-2017.17-01-36.UTC

Successfully tagged netplugin:ecb31d87-unsupported
USE_RELEASE=y make compile-with-docker

Version: 1.0.0-beta
GitCommit: ecb31d8-unsupported
BuildTime: 10-10-2017.17-02-52.UTC

Successfully tagged netplugin:ecb31d87-unsupported
BUILD_VERSION=1.2.3 make compile-with-docker

Version: 1.2.3-10-10-2017.16-58-15.UTC
GitCommit: ecb31d8-unsupported
BuildTime: 10-10-2017.16-58-15.UTC

Successfully tagged netplugin:ecb31d87-unsupported

@chrisplo
Copy link
Contributor Author

make build was successfull as well

Dockerfile Outdated

ENTRYPOINT ["netplugin"]
CMD ["--help"]

COPY ./ /go/src/github.com/contiv/netplugin/
# build the vendor dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

@chrisplo
Copy link
Contributor Author

I pulled a compile target last minute as thought wasn't needed, need to restore, will add comments as well

@chrisplo
Copy link
Contributor Author

chrisplo commented Oct 10, 2017

rechecked make compile-with-docker and

$ docker run --entrypoint ls netplugin:devBuild-c18b3301-unsupported /etc/bash_completion.d/netctl
/etc/bash_completion.d/netctl

@chrisplo
Copy link
Contributor Author

build PR

@dseevr
Copy link
Contributor

dseevr commented Oct 12, 2017

Now that #999 is merged, you can remove that grep -v and such

@@ -0,0 +1,13 @@
#!/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.

Can we get a

set -euo pipefail

here? I think we should include it in every new script by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, thx

if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
GIT_COMMIT="$GIT_COMMIT-unsupported"
fi
echo $GIT_COMMIT
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wth is are tabs doing in there :/

Dockerfile Outdated
RUN GOPATH=/go/ \
BUILD_VERSION="${BUILD_VERSION}" \
USE_RELEASE="${USE_RELEASE}" \
make compile \
Copy link
Member

@gkvijay gkvijay Oct 12, 2017

Choose a reason for hiding this comment

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

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

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 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.

Copy link
Member

Choose a reason for hiding this comment

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

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

@chrisplo
Copy link
Contributor Author

I will also check for changes due to PR1000 merging

@chrisplo chrisplo force-pushed the dockerfile_compile_update branch 2 times, most recently from 3766099 to 27a0a57 Compare October 12, 2017 18:55
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
@dseevr
Copy link
Contributor

dseevr commented Oct 12, 2017

build pr

@chrisplo
Copy link
Contributor Author

do you want me to pull apart the getGitCommit as separate PR @unclejack @dseevr ?

@dseevr
Copy link
Contributor

dseevr commented Oct 12, 2017

It's required for this PR to be merged and function so it seems fine to me as it is

@chrisplo
Copy link
Contributor Author

chrisplo commented Oct 12, 2017

when squash merging this please use the PR description as the commit msg (instead of the first commit msg)

Makefile Outdated
docker build \
--build-arg NIGHTLY_RELEASE=${NIGHTLY_RELEASE} \
--build-arg BUILD_VERSION=${BUILD_VERSION} \
-t netplugin:$${BUILD_VERSION:-devBuild}-$$(./scripts/getGitCommit.sh) .
Copy link
Contributor Author

Choose a reason for hiding this comment

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

devbuild not devBuild

@dseevr
Copy link
Contributor

dseevr commented Oct 12, 2017

build pr

@dseevr
Copy link
Contributor

dseevr commented Oct 13, 2017

@unclejack PTAL and merge if it looks good

Dockerfile Outdated
RUN GOPATH=/go/ \
BUILD_VERSION="${BUILD_VERSION}" \
USE_RELEASE="${USE_RELEASE}" \
make compile \
Copy link
Member

Choose a reason for hiding this comment

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

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


RUN GOPATH=/go/ \
Copy link
Contributor

Choose a reason for hiding this comment

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

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@unclejack
Copy link
Contributor

@chrisplo: Can you get rid of the merge commit and integrate the changes into their corresponding commits, please?

@unclejack
Copy link
Contributor

The merge commit is fine in this case. This particular PR will get squashed on merge.

@chrisplo chrisplo merged commit 5732e53 into contiv:master Oct 13, 2017
@chrisplo chrisplo deleted the dockerfile_compile_update branch October 27, 2017 00:41
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.

None yet

4 participants