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

Split dockerfile to build container and runtime container #561

Closed
wants to merge 1 commit into from

Conversation

defect
Copy link
Contributor

@defect defect commented Jun 27, 2017

So, after rebuilding the container for the Nth time i started toying with the idea of breaking out the building parts of the process into it's own container since we don't really need activator/sbt/etc. to run collins once the zip has been produced.

This creates a Dockerfile.build which sets up the basic build toolchain and should in my mind make it easier and quicker to get started with building collins. For instance, after creating the build container we can build the zip by running

~/W/t/collins (split_dockerfiles) >time docker run -v $(pwd)/target:/build/target b97efa2bb6dc ./scripts/package.sh
[..]
docker run b97efa2bb6dc ./scripts/package.sh  0.03s user 0.03s system 0% cpu 1:49.67 total

which should be a lot quicker than building from scratch since we already have the dependencies and toolchain. If we're making a lot of changes we can have a container re-compiling on changes by running

~/W/t/collins (split_dockerfiles) >docker run -it -v $(pwd)/app:/build/app 5f787656d457 activator
[info] Loading project definition from /build/project
[info] Set current project to collins (in build file:/build/)
[collins] $ ~ compile
[info] Compiling 331 Scala sources and 9 Java sources to /build/target/scala-2.11/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.7. Compiling...
[info]   Compilation completed in 13.051 s
[success] Total time: 74 s, completed Jun 27, 2017 9:46:21 PM
1. Waiting for source changes... (press enter to interrupt)
[info] Compiling 1 Scala source to /build/target/scala-2.11/classes...
[success] Total time: 5 s, completed Jun 27, 2017 9:46:43 PM
2. Waiting for source changes... (press enter to interrupt)

The final "runtime" container becomes a lot simpler too.

I haven't really tried all different use-cases here, but I thought I'd ask for some feedback. Does this make sense at all?

@tumblr/collins @byxorna @michaeljs1990 Thoughts?

@michaeljs1990
Copy link
Contributor

Smaller image size is always a big plus. I know our version of this image has gotten pretty large I think almost up to 1G now. It's a little strange to me to have the container depend on the output of another container but I think as long as it has a script or makefile for generating the image it should be fine.

Copy link
Contributor

@byxorna byxorna left a comment

Choose a reason for hiding this comment

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

This will break the docker build on the hub, because the target zip won't be compiled. How can this be changed to not break existing automated builds on dockerhub, and maintain the oneshot behavior of "docker build ." doing the needful?

support
vendor
project/target
project/project
target/collins
target/scala-2.11
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 just glob this?

@michaeljs1990
Copy link
Contributor

https://docs.docker.com/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds seems to be the new hotness but not sure how bleeding edge you want to go with a solution.

@byxorna
Copy link
Contributor

byxorna commented Jul 2, 2017

@michaeljs1990 if docker hub supports multistage builds, I'd rather do that! Keep in mind, we need to ensure we don't break other downstreams that may depend on tooling we pull into the image during build (ex for runtime tools like curl) that may change when you strip down the build to remove the sdk

@defect
Copy link
Contributor Author

defect commented Jul 8, 2017

Good point about the automated builds! I'll check the multi-stage build stuff out. I haven't used that yet, but it looks pretty neat.

I'm not quite sure how to handle downstream images that use tools that just happen to be in our current image since we install a lot of stuff for building. If we have a more streamlined image for deployment, should we just include some of the tools that seems like nice-to-haves? Say, curl/wget, netcat, ipmitool and friends?

EDIT:

Multi-stage builds are a new feature in Docker 17.05

Oh wow, that's newer than i thought :P

EDIT 2: Looks like multistage support on the docker hub isn't that far away: docker/hub-feedback#1039

@byxorna byxorna mentioned this pull request Jul 11, 2017
@defect
Copy link
Contributor Author

defect commented Oct 20, 2017

Closing in favor of #562 which seems more promising :)

@defect defect closed this Oct 20, 2017
Sign up for free to 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.

3 participants