-
Notifications
You must be signed in to change notification settings - Fork 445
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
Separate Docker Layers for Dependencies and App jars. #1310
Conversation
I working on making this better by giving up magic (hardcoded organization) and use solution suggested by #1267 (comment) |
We could add an intermediate task (e.g. |
src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Outdated
Show resolved
Hide resolved
It is reused in Docker/stage and and Docker/dockerCommands. This intermediate step helps with cyclic dependency.
Thanks to @nigredo-tori tips the newest version fixes all three problems from above. The pull request is almost complete apart from this issues:
After making sure its on the right track I'll implement code for branches other than |
src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Outdated
Show resolved
Hide resolved
src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Outdated
Show resolved
Hide resolved
src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Outdated
Show resolved
Hide resolved
Creation date shouldn't matter at all:
|
Latest changes solve all previous problems, questions and review remarks. Some changes were required in Dockerfile now:
|
src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Outdated
Show resolved
Hide resolved
src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Outdated
Show resolved
Hide resolved
src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! The implementation looks solid, docs and tests look good to me.
Two small remarks that would be nice to have fixed. When the failing docker tests
are green (you can ignore the windows ones, we have to deal with those soon).
then this is good to merge from my perspective.
Thanks @nigredo-tori for the guidance and well done comments 🤗
I'm looking at failing tests on my computer. |
This test assumes the way the files are mapped to the staging directory, and we're changing that, so we should definitely change the expectations. Preferably in a way that eliminates that assumption. For example, we can replace
with dockerBuildCommand := Seq(
"docker", "build", "-t", "docker-build-command-test:0.1.0",
(baseDirectory.value / "docker-test").getAbsolutePath
) and move the However, this highlights two more potential issues. This change is breaking for people with custom build commands (only if they use a non-standard |
To have it consistent with the past we can try to limit power of grouping function to include None as default layer. |
Thanks for the good discussion 😃 I tried to give my opinion on this, but my docker production knowledge is rather limited, so bare with me 😬 stage dir and default layer
AFAIK if the user wants the old behaviour, then this would be enough dockerLayerGrouping := (_ => None) and everything will be layered out in staging as before. For me this would be what @nigredo-tori described as
The complexity from this PR seams reasonable to me, so I would accept the extra maintenance required to check layered and non-layered. #854 introduce the failing build-command test. The purpose of this was not have a Long term
I'm open for suggestions 😄 This issue is open for years and this is the fourth attempt, which is looking promising to me. Docker changes so fast, I have lost faith in "long-term" solutions for docker 😞 as this constantly break or required lot of workarounds (server vs. api version, chowning, flags ). ConclusionI would like to go for this solution as this solves a long standing pain point for docker users. Change the |
Hi, sorry for delays, I had unexpected offline time. I'm going to finish this PR in upcoming days.
That is true but need to be tested.
|
I finished working on this PR. I've checked how people are using dockerPackageMappings on GitHub and created a test. Also opting-out is possible as proven in the test. |
Thanks a lot for all the time and passion you put into this @ppiotrow |
Release |
Hello guys (visualization from |
Hi @sideeffffect, as I can see the first green layers came from your source image with JRE, right? I'm looking at the source code now, should not you have Anyway, can you just upgrade your docker to support Multi Stage Builds? |
It seems docker sha digest is not deterministic between different hosts. I've run several experiments with very simple docker files on my local node and remote machine. All gave inconsistent digests. Machines differ in the
I think we need to understand literally cache mechanism description.
It will be cached only if there already exist parent-child relation between base layer and docker command. I admit this is surprise to me as I expected consistent behaviour. But this most likely has some sense in the Docker implementation. You'll still benefit from newest enhancement if you build your images on small pool of Docker hosts. |
I think that what happens is that you copy files at different points in time, and the timestamps are reflected in the layer's file system, thus having different content and hash. |
I don't think timestamp makes digest deterministic between hosts. Update: |
Was any consideration given to using The main thing though to using this is that since Additionally, to make this even more robust, if the function was Finally, any reason dockerLayerGrouping := dockerLayerGrouping.value.orElse {
case ... => 2
} In contrast to now where you have to: dockerLayerGrouping := path => dockerLayerGrouping.value(path).orElse {
if (...) {
Some(2)
} else {
None
}
} |
I've submitted a PR with my suggestions here: |
Hi, I didn't know about |
Fixes #1267
Inspired by https://phauer.com/2019/no-fat-jar-in-docker-image/
The idea is to modify docker staging directory to move application related jars from
lib
toapp-lib
directory. Then twoCOPY
operations are invoked to the same destination. Dependencies are copied first as they are rarely change.Other:
mapGenericFilesToDocker
exotic method was reimplemented to be similar to other functions aroundDockerPermissionStrategy.MultiStage
branch of code was updated. Others would need to be updated to work with new staging.Questions:
organization
filters was ok at first glance, but now I'd rather do it user configurable via project's build.sbt as suggested in the original issue.Output logs from using newly published plugin in some real project.
First
docker/publishLocal
Changing some lines of code and running
docker/publishLocal
again