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

docker: introduce more layers for smaller images #1267

Open
yanns opened this issue Oct 14, 2019 · 4 comments · May be fixed by #1268

Comments

@yanns
Copy link
Contributor

@yanns yanns commented Oct 14, 2019

Expected behaviour

sbt docker:stage could generate a Dockerfile with multiple layers:

  • one for the OS with JRE
  • one for the dependencies
  • one for the resources
  • one for the code

The idea is to generate layers that do not change frequently and to re-use them.
For example, if we change just a line of code, only the last layer has to be pushed.

Actual behaviour

sbt docker:stage generate a Dockerfile with multiple layers:

  • one for the OS with JRE
  • one for all the application needs (dependencies, resources, code)

Information

https://phauer.com/2019/no-fat-jar-in-docker-image/

@nigredo-tori

This comment has been minimized.

Copy link
Collaborator

@nigredo-tori nigredo-tori commented Oct 14, 2019

Actually dragging that information all the way from JavaAppPackaging looks ugly, and will probably break a lot... As an alternative, we can add something like

val dockerGroupFiles = settingKey[String => Int](
  "Order file mappings. Lower order means the file would be a part of an earlier layer"
)
// ...
// Flat by default.
dockerGroupFiles := Function.const(0)

And then in the user code (if required):

dockerGroupFiles := {
  case m if m.startsWith("lib/my.organization") => 1
  case _ => 0
}

and group the files by that. This is far easier to add and support, and more flexible.

  • one for the resources
  • one for the code

That would be even harder to add than the rest, since we wouldn't be able to just packageBin things... With the approach I have outlined above, this would be achievable by factoring out the resources to a separate subproject (so that they are in a different JAR), and then tweaking dockerGroupFiles as needed.

Disclaimer: I don't actually use DockerPlugin, and I probably won't be the one to implement that.

@CremboC

This comment has been minimized.

Copy link

@CremboC CremboC commented Oct 14, 2019

I was actually going to open this exact same issue when I saw that blog post on Reddit.

I am going to attempt @nigredo-tori 's solution tomorrow. Only caveats that I have almost zero experience with sbt plugins and/or docker. So this is going to be interesting.

@CremboC CremboC linked a pull request that will close this issue Oct 15, 2019
@muuki88

This comment has been minimized.

Copy link
Contributor

@muuki88 muuki88 commented Oct 24, 2019

Related issues and PRS

@muuki88

This comment has been minimized.

Copy link
Contributor

@muuki88 muuki88 commented Oct 24, 2019

Thanks @nigredo-tori for your input. I had similar intentions (#368) and this is the most flexible and less sbt magic heavy option I came up with as well.

Thanks @CremboC for tackeling this 😎 You will make a lot of people very happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.