question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Split dependencies into two layers(silent and mutable)

See original GitHub issue

Now Jib separates your application into multiple layers: dependencies, resources and classes, but still a question here. dependencies layer is still very big. We can split dependencies layer. Why create a new layer for dependencies? I did some research about dependencies in Java application. Some jars are very big, for example groovy jar, hibernate jar etc. These jars are very big but stable, and developers don’t change their versions frequently. The developers change the company internal artifacts regularly, or changed by SNAPSHOT automatically. For example, a Spring Boot Application is almost 30+M, if we create a layer with following artifacts included, the original dependencies layer will be 5M almost, an new 25M layer(silent dependencies layer) could be stable for a long time. if the developer changes internal artifact version, only push the 5M layer(mutable dependencies layer), not original 30M layer again.

In Java, another consideration is SNAPSHOT. During development and testing phases, most guys use SNAPSHOT version. These jars will be changed regularly from continue integration system. For some case, for example, security jars always were delivered as SNAPSHOT version. 100K SNAPSHOT jar will make you rebuild the dependencies layer.

We can introduce a silent dependencies layer and group stable & big jars according to groupId and artifact wild match, or mutable dependencies layer. jib-maven-plugin Configuration:

<silentDependencies>org.springframework:*, org.hibernate:*, *:commons-*, org.webjars:*</silentDependencies>
<mutableDependencies>com.yourcompany:*,*:*:*-SNAPSHOT</mutableDependencies>

the Dockerfile will copy slient jars into a new layer

COPY silent-libs /app/libs/
COPY mutable-libs /app/libs

all artifacts should be in libs directory to make dependencies check easy.

The followings are some very popular artifacts size information for references, and of course the developers can add other jars. for a spring boot application, almost silent dependencies layer is almost 80+% in size, and mutable dependencies layer almost 20-% in size.

Spring Framework related

  • spring all: spring & spring boot & spring cloud = 12M
  • reactor all: 3M

Apache

  • apache commons all: 1.8M

JVM languages

  • groovy: 4.7M
  • jruby: 10M
  • kotlin all: 3.5M
  • scala: 5.7M

web server

  • tomcat all: 3.6M
  • jetty all: 2.4
  • undertow all: 3M

Java EE

  • javax.*: stable, size is small
  • javaee: 2M

Driver & client

  • Oracle: ojdbc8.jar 4M
  • MySQL: 2M
  • H2 Database: 2M
  • postgresql: 0.7M
  • sqlserver: 0.9M
  • kafka: 7.5M

Misc

  • hibernate: 7.6M
  • jackson all: 2M
  • webjars: font-awesome(7.6M), bootstrap(1.0M), jquery(1.5M)
  • byte-buddy: 2.9M
  • aspectj: aspectj* 3M
  • snappy-java: 1.1M
  • netty all: 2.3M
  • freemarker: 1.5 M
  • thymeleaf: 1.0 M
  • bouncycastle: 4M

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:21 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
chanseokohcommented, Jun 11, 2020

FYI @velo @liqweed @linux-china @ivan-gammel @stigkj @d5nguyenvan @Mart-Bogdan @Ameausoone @steven-sheehy @mdiskin @yamass

The Jib Extension Framework is now available with the latest Jib versions. You can easily extend and tailor the Jib plugins behavior to your liking.

We’ve written a general-purpose layer-filter extension that enables fine-grained layer control, including deleting files and moving files into new layers.

For general information about using and writing extensions, take a look at the Jib Extensions repo.

2reactions
linux-chinacommented, Jun 15, 2018

@coollog I added consideration for SNAPSHOT version in Java, and these jars should be considered as mutable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug descriptions — spotbugs 4.7.3 documentation
A mutable public field is defined inside a public enum, thus can be changed by malicious code or by accident from another package....
Read more >
Mocking is a Code Smell - Medium
Mutable state dependencies: Code that shares mutable state with other code, e.g., can change properties on a shared object. If relative timing ...
Read more >
rollup.js
Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library...
Read more >
4. Writing Great Code - The Hitchhiker's Guide to Python [Book]
Special cases aren't special enough to break the rules. ... the most natural way to separate these two layers is to regroup all...
Read more >
Splitting Borrows - The Rustonomicon
For instance, mutable slices expose a split_at_mut function that consumes the slice and returns two mutable slices. One for everything to the left...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found