Creating Spring Boot Docker Images With Paketo Buildpacks
In recent years, containerization has become the de facto standard for deploying applications. It offers numerous benefits, such as improved scalability, portability, and ease of management. However, packaging applications into containers can be a complex task, especially when it comes to configuring and managing dependencies. This is where buildpacks come into play. In this blog, we will explore Java buildpacks and demonstrate how to package a Java application using buildpacks.
What are Buildpacks?
Buildpacks are an innovative technology that allows developers to quickly and easily create containerized applications without having to write a Dockerfile or specifying the entire system stack. They provide a modular, reusable way for app authors to define and package their application’ .
Buildpacks are a set of scripts and configuration files that automate the process of packaging applications into containers. They provide a standardized way to handle dependencies, build artifacts, and runtime configuration. Buildpacks are typically used in platforms like Cloud Foundry, Heroku, and Kubernetes to simplify the deployment process.
Java Buildpacks:
Java buildpacks are specifically designed to package Java applications into containers. They handle tasks such as downloading and configuring the Java runtime, managing dependencies (e.g., JAR files), and setting up the necessary environment variables. Java buildpacks are highly customizable, allowing developers to define their own buildpacks or modify existing ones to suit their specific requirements.
Containerizing Java Application using Buildpacks
To illustrate how to package a Java application using buildpacks, let’s consider a SpringBoot web application built with Maven. Here are the steps involved:
Step 1: Create a Java web application
Go to https://start.spring.io and create a sample project by selecting maven as build tool and download the project.
Step 2) Open the project in IDE.
Extract the project and open the project in your choice of IDE.
If you look at the pom.xml file, It contains spring-boot-maven-plugin. This plugin supports the buildpacks out of the box
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Code language: Java (java)
Step 3) Building the project
in build the spring boot application file , we run following command which produces the jar file
mvn clean package.
Code language: Java (java)
To build the docker container of the application using buildpacks , we need to run following command.
mvn spring-boot:build-image
Code language: Java (java)
Now, when you run mvn spring-boot:build-image
, it will generate an OCI compliant image using Buildpacks (it’ll automatically detect that you want to use them based on your project configuration). You can then push this image to a container registry like Docker Hub
The command will use the paketo buildpacks/builder:base builder image to build the application and create a container image.
[INFO] --- spring-boot-maven-plugin:3.1.3:build-image (default-cli) @ springboot-buildpacks-example ---
[INFO] Building image 'docker.io/library/springboot-buildpacks-example:0.0.1-SNAPSHOT'
....
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 87%
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 88%
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 91%
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 93%
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 94%
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
[INFO] > Pulled builder image 'paketobuildpacks/builder@sha256:17ea21162ba8c7717d3ead3ee3836a368aced7f02f2e59658e52029bd6d149e7'
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 6%
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 29%
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 37%
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 37%
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 100%
[INFO] > Pulled run image 'paketobuildpacks/run@sha256:1af9935d8987fd52b2266d288200c9482d1dd5529860bbf5bc2d248de1cb1a38'
[INFO] > Executing lifecycle version v0.16.5
[INFO] > Using build cache volume 'pack-cache-223490516329.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] ===> ANALYZING
[INFO] [creator] Image with name "docker.io/library/springboot-buildpacks-example:0.0.1-SNAPSHOT" not found
[INFO] [creator] ===> DETECTING
[INFO] [creator] 6 of 26 buildpacks participating
[INFO] [creator] paketo-buildpacks/ca-certificates 3.6.3
[INFO] [creator] paketo-buildpacks/bellsoft-liberica 10.2.6
[INFO] [creator] paketo-buildpacks/syft 1.32.1
[INFO] [creator] paketo-buildpacks/executable-jar 6.7.4
[INFO] [creator] paketo-buildpacks/dist-zip 5.6.4
[INFO] [creator] paketo-buildpacks/spring-boot 5.26.1
[INFO] [creator] ===> RESTORING
[INFO] [creator] ===> BUILDING
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for CA Certificates 3.6.3
[INFO] [creator] https://github.com/paketo-buildpacks/ca-certificates
[INFO] [creator] Launch Helper: Contributing to layer
[INFO] [creator] Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for BellSoft Liberica 10.2.6
[INFO] [creator] https://github.com/paketo-buildpacks/bellsoft-liberica
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_JVM_JLINK_ARGS --no-man-pages --no-header-files --strip-debug --compress=1 configure custom link arguments (--output must be omitted)
[INFO] [creator] $BP_JVM_JLINK_ENABLED false enables running jlink tool to generate custom JRE
[INFO] [creator] $BP_JVM_TYPE JRE the JVM type - JDK or JRE
[INFO] [creator] $BP_JVM_VERSION 17 the Java version
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_DEBUG_ENABLED false enables Java remote debugging support
[INFO] [creator] $BPL_DEBUG_PORT 8000 configure the remote debugging port
[INFO] [creator] $BPL_DEBUG_SUSPEND false configure whether to suspend execution until a debugger has attached
[INFO] [creator] $BPL_HEAP_DUMP_PATH write heap dumps on error to this path
[INFO] [creator] $BPL_JAVA_NMT_ENABLED true enables Java Native Memory Tracking (NMT)
[INFO] [creator] $BPL_JAVA_NMT_LEVEL summary configure level of NMT, summary or detail
[INFO] [creator] $BPL_JFR_ARGS configure custom Java Flight Recording (JFR) arguments
[INFO] [creator] $BPL_JFR_ENABLED false enables Java Flight Recording (JFR)
[INFO] [creator] $BPL_JMX_ENABLED false enables Java Management Extensions (JMX)
[INFO] [creator] $BPL_JMX_PORT 5000 configure the JMX port
[INFO] [creator] $BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
[INFO] [creator] $BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
[INFO] [creator] $BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
[INFO] [creator] $JAVA_TOOL_OPTIONS the JVM launch flags
[INFO] [creator] Using Java version 17 extracted from MANIFEST.MF
[INFO] [creator] BellSoft Liberica JRE 17.0.7: Contributing to layer
[INFO] [creator] Downloading from https://github.com/bell-sw/Liberica/releases/download/17.0.7+7/bellsoft-jre17.0.7+7-linux-amd64.tar.gz
[INFO] [creator] Verifying checksum
[INFO] [creator] Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jre
[INFO] [creator] Adding 137 container CA certificates to JVM truststore
[INFO] [creator] Writing env.launch/BPI_APPLICATION_PATH.default
[INFO] [creator] Writing env.launch/BPI_JVM_CACERTS.default
[INFO] [creator] Writing env.launch/BPI_JVM_CLASS_COUNT.default
[INFO] [creator] Writing env.launch/BPI_JVM_SECURITY_PROVIDERS.default
[INFO] [creator] Writing env.launch/JAVA_HOME.default
[INFO] [creator] Writing env.launch/JAVA_TOOL_OPTIONS.append
[INFO] [creator] Writing env.launch/JAVA_TOOL_OPTIONS.delim
[INFO] [creator] Writing env.launch/MALLOC_ARENA_MAX.default
[INFO] [creator] Launch Helper: Contributing to layer
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/active-processor-count
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/java-opts
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jvm-heap
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/link-local-dns
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/memory-calculator
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/security-providers-configurer
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jmx
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jfr
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/security-providers-classpath-9
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/debug-9
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/nmt
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/openssl-certificate-loader
[INFO] [creator] Java Security Properties: Contributing to layer
[INFO] [creator] Writing env.launch/JAVA_SECURITY_PROPERTIES.default
[INFO] [creator] Writing env.launch/JAVA_TOOL_OPTIONS.append
[INFO] [creator] Writing env.launch/JAVA_TOOL_OPTIONS.delim
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Syft 1.32.1
[INFO] [creator] https://github.com/paketo-buildpacks/syft
[INFO] [creator] Downloading from https://github.com/anchore/syft/releases/download/v0.84.0/syft_0.84.0_linux_amd64.tar.gz
[INFO] [creator] Verifying checksum
[INFO] [creator] Writing env.build/SYFT_CHECK_FOR_APP_UPDATE.default
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Executable JAR 6.7.4
[INFO] [creator] https://github.com/paketo-buildpacks/executable-jar
[INFO] [creator] Class Path: Contributing to layer
[INFO] [creator] Writing env/CLASSPATH.delim
[INFO] [creator] Writing env/CLASSPATH.prepend
[INFO] [creator] Process types:
[INFO] [creator] executable-jar: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator] task: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator] web: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Spring Boot 5.26.1
[INFO] [creator] https://github.com/paketo-buildpacks/spring-boot
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_SPRING_CLOUD_BINDINGS_DISABLED false whether to contribute Spring Boot cloud bindings support
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_SPRING_CLOUD_BINDINGS_DISABLED false whether to auto-configure Spring Boot environment properties from bindings
[INFO] [creator] $BPL_SPRING_CLOUD_BINDINGS_ENABLED true Deprecated - whether to auto-configure Spring Boot environment properties from bindings
[INFO] [creator] Creating slices from layers index
[INFO] [creator] dependencies (18.0 MB)
[INFO] [creator] spring-boot-loader (269.4 KB)
[INFO] [creator] snapshot-dependencies (0.0 B)
[INFO] [creator] application (40.8 KB)
[INFO] [creator] Launch Helper: Contributing to layer
[INFO] [creator] Creating /layers/paketo-buildpacks_spring-boot/helper/exec.d/spring-cloud-bindings
[INFO] [creator] Spring Cloud Bindings 1.13.0: Contributing to layer
[INFO] [creator] Downloading from https://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-bindings/1.13.0/spring-cloud-bindings-1.13.0.jar
[INFO] [creator] Verifying checksum
[INFO] [creator] Copying to /layers/paketo-buildpacks_spring-boot/spring-cloud-bindings
[INFO] [creator] Web Application Type: Contributing to layer
[INFO] [creator] Servlet web application detected
[INFO] [creator] Writing env.launch/BPL_JVM_THREAD_COUNT.default
[INFO] [creator] 4 application slices
[INFO] [creator] Image labels:
[INFO] [creator] org.opencontainers.image.title
[INFO] [creator] org.opencontainers.image.version
[INFO] [creator] org.springframework.boot.version
[INFO] [creator] ===> EXPORTING
[INFO] [creator] Adding layer 'paketo-buildpacks/ca-certificates:helper'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:helper'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:java-security-properties'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:jre'
[INFO] [creator] Adding layer 'paketo-buildpacks/executable-jar:classpath'
[INFO] [creator] Adding layer 'paketo-buildpacks/spring-boot:helper'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:31 min
[INFO] Finished at: 2023-09-08T22:56:26+12:00
[INFO] ------------------------------------------------------------------------
Code language: Java (java)
We can verify that creation of docker image with following command.
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
springboot-buildpacks-example 0.0.1-SNAPSHOT e3bac6bd3efd 43 years ago 276MB
Code language: Java (java)
Customizing the container building
If you look at log of container building , you can see that it uses packeto buildpacks base image and Bellsoft liberica JRE version 17.
Customizing the buildpack Image
paketobuildpacks/builder:base
is based on Ubuntu 18.04.If you want to build the docker image with Ubuntu 22.04 OS as the base OS, you need to use the paketobuildpacks/builder-jammy-base
image.
You can find all available packeto builders here
In your spring-boot-maven-plugin you can specify the image name in configuration like below.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder-jammy-base</builder>
</image>
</configuration>
</plugin>
Code language: Java (java)
Now, when you run mvn spring-boot:build-image, it will generate an OCI compliant image using Ubuntu 22.04 image.
[INFO] > Pulled builder image 'paketobuildpacks/builder-jammy-base@sha256:7d1400ff2bfcccb0afb44030fbf05d3f945fb4bf6430d914b893522ffbc5dc3f'
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run-jammy-base:latest' 10%
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run-jammy-base:latest' 24%
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run-jammy-base:latest' 35%
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run-jammy-base:latest' 49%
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run-jammy-base:latest' 100%
[INFO] > Pulled run image 'paketobuildpacks/run-jammy-base@sha256:d346a10e37c8c4792edbb6bbef644565a3d2a6d24646665160d3ec34a60583e4'
[INFO] > Executing lifecycle version v0.17.0
[INFO] > Using build cache volume 'pack-cache-223490516329.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] ===> ANALYZING
[INFO] [creator] Timer: Analyzer started at 2023-09-09T04:43:41Z
[INFO] [creator] Restoring data for SBOM from previous image
[INFO] [creator] Timer: Analyzer ran for 5.8012ms and ended at 2023-09-09T04:43:41Z
[INFO] [creator] ===> DETECTING
[INFO] [creator] Timer: Detector started at 2023-09-09T04:43:41Z
[INFO] [creator] 6 of 26 buildpacks participating
[INFO] [creator] paketo-buildpacks/ca-certificates 3.6.3
[INFO] [creator] paketo-buildpacks/bellsoft-liberica 10.2.9
[INFO] [creator] paketo-buildpacks/syft 1.35.0
[INFO] [creator] paketo-buildpacks/executable-jar 6.7.4
[INFO] [creator] paketo-buildpacks/dist-zip 5.6.4
[INFO] [creator] paketo-buildpacks/spring-boot 5.27.1
[INFO] [creator] Timer: Detector ran for 360.9362ms and ended at 2023-09-09T04:43:42Z
[INFO] [creator] ===> RESTORING
[INFO] [creator] Timer: Restorer started at 2023-09-09T04:43:42Z
[INFO] [creator] Restoring metadata for "paketo-buildpacks/ca-certificates:helper" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/bellsoft-liberica:helper" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/bellsoft-liberica:java-security-properties" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/bellsoft-liberica:jdk" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/syft:syft" from cache
[INFO] [creator] Restoring metadata for "paketo-buildpacks/spring-boot:web-application-type" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/spring-boot:helper" from app image
[INFO] [creator] Restoring metadata for "paketo-buildpacks/spring-boot:spring-cloud-bindings" from app image
[INFO] [creator] Restoring data for "paketo-buildpacks/bellsoft-liberica:jdk" from cache
[INFO] [creator] Restoring data for "paketo-buildpacks/syft:syft" from cache
[INFO] [creator] Restoring data for SBOM from cache
[INFO] [creator] Timer: Restorer ran for 1.2712048s and ended at 2023-09-09T04:43:43Z
[INFO] [creator] ===> BUILDING
[INFO] [creator] Timer: Builder started at 2023-09-09T04:43:43Z
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for CA Certificates 3.6.3
[INFO] [creator] https://github.com/paketo-buildpacks/ca-certificates
[INFO] [creator] Launch Helper: Reusing cached layer
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for BellSoft Liberica 10.2.9
[INFO] [creator] https://github.com/paketo-buildpacks/bellsoft-liberica
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_JVM_JLINK_ARGS --no-man-pages --no-header-files --strip-debug --compress=1 configure custom link arguments (--output must be omitted)
[INFO] [creator] $BP_JVM_JLINK_ENABLED false enables running jlink tool to generate custom JRE
[INFO] [creator] $BP_JVM_TYPE JRE the JVM type - JDK or JRE
[INFO] [creator] $BP_JVM_VERSION 17 the Java version
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_DEBUG_ENABLED false enables Java remote debugging support
[INFO] [creator] $BPL_DEBUG_PORT 8000 configure the remote debugging port
[INFO] [creator] $BPL_DEBUG_SUSPEND false configure whether to suspend execution until a debugger has attached
[INFO] [creator] $BPL_HEAP_DUMP_PATH write heap dumps on error to this path
[INFO] [creator] $BPL_JAVA_NMT_ENABLED true enables Java Native Memory Tracking (NMT)
[INFO] [creator] $BPL_JAVA_NMT_LEVEL summary configure level of NMT, summary or detail
[INFO] [creator] $BPL_JFR_ARGS configure custom Java Flight Recording (JFR) arguments
[INFO] [creator] $BPL_JFR_ENABLED false enables Java Flight Recording (JFR)
[INFO] [creator] $BPL_JMX_ENABLED false enables Java Management Extensions (JMX)
[INFO] [creator] $BPL_JMX_PORT 5000 configure the JMX port
[INFO] [creator] $BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
[INFO] [creator] $BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
[INFO] [creator] $BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
[INFO] [creator] $JAVA_TOOL_OPTIONS the JVM launch flags
[INFO] [creator] Using Java version 17 extracted from MANIFEST.MF
[INFO] [creator] BellSoft Liberica JRE 17.0.8: Contributing to layer
[INFO] [creator] Downloading from https://github.com/bell-sw/Liberica/releases/download/17.0.8.1+1/bellsoft-jre17.0.8.1+1-linux-amd64.tar.gz
[INFO] [creator] Verifying checksum
[INFO] [creator] Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jre
[INFO] [creator] Adding 137 container CA certificates to JVM truststore
[INFO] [creator] Writing env.launch/BPI_APPLICATION_PATH.default
[INFO] [creator] Writing env.launch/BPI_JVM_CACERTS.default
[INFO] [creator] Writing env.launch/BPI_JVM_CLASS_COUNT.default
[INFO] [creator] Writing env.launch/BPI_JVM_SECURITY_PROVIDERS.default
[INFO] [creator] Writing env.launch/JAVA_HOME.default
[INFO] [creator] Writing env.launch/JAVA_TOOL_OPTIONS.append
[INFO] [creator] Writing env.launch/JAVA_TOOL_OPTIONS.delim
[INFO] [creator] Writing env.launch/MALLOC_ARENA_MAX.default
[INFO] [creator] Launch Helper: Contributing to layer
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/active-processor-count
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/java-opts
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jvm-heap
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/link-local-dns
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/memory-calculator
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/security-providers-configurer
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jmx
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jfr
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/security-providers-classpath-9
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/debug-9
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/nmt
[INFO] [creator] Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/openssl-certificate-loader
[INFO] [creator] Java Security Properties: Contributing to layer
[INFO] [creator] Writing env.launch/JAVA_SECURITY_PROPERTIES.default
[INFO] [creator] Writing env.launch/JAVA_TOOL_OPTIONS.append
[INFO] [creator] Writing env.launch/JAVA_TOOL_OPTIONS.delim
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Syft 1.35.0
[INFO] [creator] https://github.com/paketo-buildpacks/syft
[INFO] [creator] Downloading from https://github.com/anchore/syft/releases/download/v0.88.0/syft_0.88.0_linux_amd64.tar.gz
[INFO] [creator] Verifying checksum
[INFO] [creator] Writing env.build/SYFT_CHECK_FOR_APP_UPDATE.default
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Executable JAR 6.7.4
[INFO] [creator] https://github.com/paketo-buildpacks/executable-jar
[INFO] [creator] Class Path: Contributing to layer
[INFO] [creator] Writing env/CLASSPATH.delim
[INFO] [creator] Writing env/CLASSPATH.prepend
[INFO] [creator] Process types:
[INFO] [creator] executable-jar: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator] task: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator] web: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Spring Boot 5.27.1
[INFO] [creator] https://github.com/paketo-buildpacks/spring-boot
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_SPRING_CLOUD_BINDINGS_DISABLED false whether to contribute Spring Boot cloud bindings support
[INFO] [creator] $BP_SPRING_CLOUD_BINDINGS_VERSION 1 default version of Spring Cloud Bindings library to contribute
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_SPRING_CLOUD_BINDINGS_DISABLED false whether to auto-configure Spring Boot environment properties from bindings
[INFO] [creator] $BPL_SPRING_CLOUD_BINDINGS_ENABLED true Deprecated - whether to auto-configure Spring Boot environment properties from bindings
[INFO] [creator] Creating slices from layers index
[INFO] [creator] dependencies (18.0 MB)
[INFO] [creator] spring-boot-loader (269.4 KB)
[INFO] [creator] snapshot-dependencies (0.0 B)
[INFO] [creator] application (40.9 KB)
[INFO] [creator] Launch Helper: Contributing to layer
[INFO] [creator] Creating /layers/paketo-buildpacks_spring-boot/helper/exec.d/spring-cloud-bindings
[INFO] [creator] Spring Cloud Bindings 2.0.2: Contributing to layer
[INFO] [creator] Downloading from https://repo1.maven.org/maven2/org/springframework/cloud/spring-cloud-bindings/2.0.2/spring-cloud-bindings-2.0.2.jar
[INFO] [creator] Verifying checksum
[INFO] [creator] Copying to /layers/paketo-buildpacks_spring-boot/spring-cloud-bindings
[INFO] [creator] Web Application Type: Contributing to layer
[INFO] [creator] Servlet web application detected
[INFO] [creator] Writing env.launch/BPL_JVM_THREAD_COUNT.default
[INFO] [creator] 4 application slices
[INFO] [creator] Image labels:
[INFO] [creator] org.opencontainers.image.title
[INFO] [creator] org.opencontainers.image.version
[INFO] [creator] org.springframework.boot.version
[INFO] [creator] Timer: Builder ran for 27.0993005s and ended at 2023-09-09T04:44:10Z
[INFO] [creator] ===> EXPORTING
[INFO] [creator] Timer: Exporter started at 2023-09-09T04:44:10Z
[INFO] [creator] Reusing layer 'paketo-buildpacks/ca-certificates:helper'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:helper'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:java-security-properties'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:jre'
[INFO] [creator] Adding layer 'paketo-buildpacks/executable-jar:classpath'
[INFO] [creator] Adding layer 'paketo-buildpacks/spring-boot:helper'
[INFO] [creator] Adding layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
[INFO] [creator] Adding layer 'paketo-buildpacks/spring-boot:web-application-type'
[INFO] [creator] Adding layer 'buildpacksio/lifecycle:launch.sbom'
[INFO] [creator] Reusing 2/5 app layer(s)
[INFO] [creator] Adding 3/5 app layer(s)
[INFO] [creator] Adding layer 'buildpacksio/lifecycle:launcher'
[INFO] [creator] Adding layer 'buildpacksio/lifecycle:config'
[INFO] [creator] Reusing layer 'buildpacksio/lifecycle:process-types'
[INFO] [creator] Adding label 'io.buildpacks.lifecycle.metadata'
[INFO] [creator] Adding label 'io.buildpacks.build.metadata'
[INFO] [creator] Adding label 'io.buildpacks.project.metadata'
[INFO] [creator] Adding label 'org.opencontainers.image.title'
[INFO] [creator] Adding label 'org.opencontainers.image.version'
[INFO] [creator] Adding label 'org.springframework.boot.version'
[INFO] [creator] Setting default process type 'web'
[INFO] [creator] Timer: Saving docker.io/library/springboot-buildpacks-example:0.0.1-SNAPSHOT... started at 2023-09-09T04:44:11Z
[INFO] [creator] *** Images (ac9c1db6f7ce):
[INFO] [creator] docker.io/library/springboot-buildpacks-example:0.0.1-SNAPSHOT
[INFO] [creator] Timer: Saving docker.io/library/springboot-buildpacks-example:0.0.1-SNAPSHOT... ran for 6.9385527s and ended at 2023-09-09T04:44:18Z
[INFO] [creator] Timer: Exporter ran for 7.6843732s and ended at 2023-09-09T04:44:18Z
[INFO] [creator] Timer: Cache started at 2023-09-09T04:44:18Z
[INFO] [creator] Adding cache layer 'paketo-buildpacks/syft:syft'
[INFO] [creator] Adding cache layer 'buildpacksio/lifecycle:cache.sbom'
[INFO] [creator] Timer: Cache ran for 199.5427ms and ended at 2023-09-09T04:44:18Z
[INFO]
[INFO] Successfully built image 'docker.io/library/springboot-buildpacks-example:0.0.1-SNAPSHOT'
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:15 min
[INFO] Finished at: 2023-09-09T16:44:21+12:00
[INFO] ------------------------------------------------------------------------
Code language: Java (java)
Customizing the JDK
from the logs you can see that, packeto buildpacks by default uses liberica JRE .If you want to use JDK you can specify it via env variables.
Using JDK
in environment variables, you can specify that you want include JDK instead of JRE in container image.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder-jammy-base</builder>
<env>
<BP_JVM_TYPE>JDK</BP_JVM_TYPE>
</env>
</image>
</configuration>
</plugin>
Code language: Java (java)
Changing JDK distribution
If you want to use different JDK distribution to run your application in the container ,you have to specify corresponding JDK buildpack and as well as gcr.io/paketo-buildpacks/java
as another buildpack in the configuration.
Note
gcr.io/paketo-buildpacks/ca-certificates
gcr.io/paketo-buildpacks/syft
Sometimes I observed that even after configuring above buildpacks, image creation process hangs without showing any error message. First run
mvn clean package
command and then run mvn spring-boot:build-image
command.You can find all available packeto buildpacks for different JDK distrbutions here
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildpacks>
<buildpack>gcr.io/paketo-buildpacks/ca-certificates</buildpack>
<buildpack>gcr.io/paketo-buildpacks/adoptium</buildpack>
<buildpack>gcr.io/paketo-buildpacks/java</buildpack>
<buildpack>gcr.io/paketo-buildpacks/syft</buildpack>
</buildpacks>
</image>
</configuration>
</plugin>
Code language: Java (java)
Building ARM Image
There is no official support for building ARM docker images with buildpacks. We can use buildpack built by community member @dashaun.
You can use dashaun/builder-multiarch
builder to build ARM images. Following configuration will build ARM image if you building on ARM based system, X64(AMD64) image if you building on Intel/AMD based systems.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>dashaun/builder-multiarch</builder>
</image>
</configuration>
</plugin>
Code language: Java (java)
Note
Building Native Container Image
The Paketo Java Native Image Buildpack allows users to create an image containing a GraalVM complaint native image application.
To build spring boot application native image container
- add the native image plugins
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
Code language: Java (java)
2. Next run following maven command with native profile
mvn -Pnative spring-boot:build-image
Code language: Java (java)
The Paketo Java Native Image Buildpack by default uses Liberica native image kit to create GraalVM compatible native container image.
If you want to build the native container image with GraalVM, you need to use the configuration like below.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildpacks>
<buildpack>gcr.io/paketo-buildpacks/ca-certificates</buildpack>
<buildpack>gcr.io/paketo-buildpacks/graalvm</buildpack>
<buildpack>gcr.io/paketo-buildpacks/java</buildpack>
<buildpack>gcr.io/paketo-buildpacks/syft</buildpack>
</buildpacks>
</image>
</configuration>
</plugin>
Code language: Java (java)
You can download the source code for the project from GitHub