It's 2021 and containerization has been happening for 7 years already.
In the Java space, there are several ways to package a Java application as a Docker image.
Let's discover them from the Dockerfile to the CNCF Buildpacks, mentioning the Jib way too!
1. Make your buildpack edition
Java applications containerized
and deployed
Anthony Dahanne @anthonydahanne
Confoo 2021 February 25th
2. Another Java and containerization talk ?
Yes, we’ll cover Java and containerization, but…
● We’ll discover the different options available in 2021
● We’ll see the pros and cons of the different approaches
● We’ll focus on Buildpacks, how to create them, how to use them
3. Picture Placehlder Picture Placeholder Picture Placeholder
https://github.com/anthonydahanne
Montreal JUG co-lead
Your presenter for this session
Java developer, Cloud architect, Devops guy… But also community leader!
blog.dahanne.net
@anthonydahanne
Devoxx4kids QC co-lead CNCF Eastern Canada co-organizer
4. Agenda
Intro: quick recap about containers
Containerizing Java: Dockerfile and Jib
Buildpacks: cloud native spec to containerize
Beyond the default buildpacks: customizing
Conclusion: got buildpacks? Where to
deploy them
5. ● A bunch of layers on top of the host kernel
● Isolation performed with chroot, namespaces, cgroups
○ namespaces : limit what you can see
■ pid, net, mnt, uts, ipc, user
○ cgroups : limit what you can use
■ memory, CPU, block IO, network (with iptables)
Intro: quick recap about containers
7. mvn compile com.google.cloud.tools:jib-maven-plugin:2.7.1:build and you’re done !
Containerizing Java: Jib
● Created in 2018 by Google (cloud), written in Java
● Docker-less, Dockerfile-less, java library to build OCI (and Docker) images
● Reproducible builds (all metadata such as timestamps stripped)
● Java project layering approach
○ /app/libs
○ /app/resources
○ /app/classes
○ /app/[whatever was found under src/main/jib]
8. Buildpacks: first contact, the spec and the pack CLI
● Heroku and CloudFoundry have been using them since… 2012 !
● Accepted in CNCF sandbox (2018) and then CNCF incubation (November 2020)
● Buildpacks are a spec and the combination of several concepts
○ Lifecycle
○ Builders
○ Buildpacks
○ Stacks
● The pack CLI is the default implementation, but others exist (more on that later)
9. Buildpacks: simplified high level view
builder
buildpackA
buildpackB buildpackC
stack
run image build image
bin/detect
bin/build
buildpack.toml
builder.toml
10. Buildpacks: customize an existing buildpack
● Why customize ?
○ You may want to choose a different JVM vendor or version
○ You may want to include a CA Certificate in your image
○ You may need to instruct Maven or Gradle to use an internal proxy for dependencies
○ etc.
● The Paketo buildpacks case
○ Environment variables for trivial cases (JVM version, buildpack activation flag)
○ Bindings to provide tools and configuration during build time or runtime
○ Not enough ? You can create a meta-buildpack or even a builder
11. Buildpacks: spring boot integration
● In 2020, Spring Boot made its boot maven plugin a CNCF buildpacks compliant tool
● Naturally default buildpacks are Paketo buildpacks
● mvn spring-boot:build-image and you’re done!
● Native support? Yes an environment variable away! BP_BOOT_NATIVE_IMAGE
● What about bindings? specific buildpacks to apply? Coming soon ⬇️
Bunch of features to implement to reach pack CLI functionality !
https://github.com/spring-projects/spring-boot/issues/23518
https://github.com/spring-projects/spring-boot/issues/21722
12. Buildpacks: other integrations not presented today
● Waypoint
● Github Actions
● CircleCI
● Tekton
● Skaffold
● KPack
● PaaS : Heroku, Google Cloud, Cloud Foundry, etc.
● And other CI tools
13. Conclusion: are buildpacks the right tool for you?
● You’re familiar with Dockerfiles and OK with them ? Keep on using them!
● You want something easy to use and well integrated with your Java build ? Jib
● You want several teams of developers to deliver complex images (certificates, agents, etc.) re
using the same stacks and tools ? Buildpacks definitely
14. Thank you for listening !
Links:
● Demos are on Github: https://github.com/anthonydahanne/java-applications-
containerized
● Great article comparing the Dockerfile with Buildpacks:
https://technology.doximity.com/articles/buildpacks-vs-dockerfiles
● Great article about buildpacks and spring boot:
https://blog.codecentric.de/en/2020/11/buildpacks-spring-boot/
● Official Spring boot team blog post about buildpack integrations and layered builds:
https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1