Git Product home page Git Product logo

docker-layered-fatjar's Introduction

docker-layered-fatjar

Create re-usable Docker layered images from java fat-jar apps.

Motivation

Deploying fat-jar scala/java applications to kubernetes requires creating a docker image that normally endups being very big since it has to include at least a JVM runtime and your fat-jar file.

However, most of the time, your application code is only a tiny fraction of what makes up the fat-jar. Most likely all other content just comes from the libraries and transitive dependencies your project has. Nevertheless, even if you only make a simple change on your codebase, the whole fat-jar files gets generated again, which means the docker image also has to be generated again.

Re-creating the image and pushing to a container registry becomes problematic since each time you are building and sending another >700M image. Even if your image includes only a distroless JVM runtime plus your application fat-jar, you endup re-using almost nothing.

This project is intended to help you split the fat-jar into reusable docker layers, so that building and pushing to a Container Registry will reuse all other layers that had not changed.

How

This program will expand a fatjar and use the du utility to find directories that are over a size threshold (default 2M) and create a separate jar for each of those directories.

It can also be given a list of explicit directories to separate into a layer using the --add-layer option. See --help.

It's also possible to create a layer containing only the fatjar toplevel files which will change only if you edit /application.conf for example.

Installation

  • If you already have Nix installed, you can run it directly using:
# Run directly using this project flake.
nix run github:vic/docker-layered-fatjar -- --help

# Or install it locally if you prefer. Installed binary is named: layers-from-fatjar
nix profile install github:vic/docker-layered-fatjar
layers-from-fatjar --help
  • If you dont have Nix, you can still download the bin/layers-from-fatjar script and make sure your system has this dependencies installed

Usage

The following will split fatjar.jar file and build a docker image named myapp:layered

nix run github:vic/docker-layered-fatjar -- --docker-build fatjar.jar -- --tag myapp:layered

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.