When I try to build an oci image from an already built self-executing jar file on my local machine using
pack build my/image --path target/my-app-0.0.1-SNAPSHOT.jar --builder paketobuildpacks/builder:base
it runs successfully giving me almost the same build packs output (regarding tools discovery etc.) as if I would run mvn spring-boot:build-image which seems to also build the jar file before it hands over the image build to build packs.
Now I am trying to do the same with the buildpacks tekton task which is available on the tekton hub.
The task is executing /cnb/lifecycle/creator directly from within the buildpacks container. One of the parameters used is "-app" which takes a directory of the application files.
If I am specifying my jar-file here it fails with an error that the value of this parameter has to be a directory.
If I am passing the mvn build target directory containing the jar file it doesn't recognize the project type and also fails.
The workaround I came up with for the moment is that I unzip the jar file into a separate direcory which I pass as the value for the -app parameter to /cnb/lifecycle/creator.
This way I can successfully build a spring boot app image with tekton buildpacks task but I still would like to know what causes the error or what exactly happens when I define the jar file as the "--path" parameter on the "pack"-cli which in turn creates a buildpack container running the /cnb/lifecycle/creator binary.
Somehow it seems to be no problem here to specify the jar file directly instead of a directory containing the application files.
If I am specifying my jar-file here it fails with an error that the value of this parameter has to be a directory.
Correct. I'll explain more about this below.
If I am passing the mvn build target directory containing the jar file it doesn't recognize the project type and also fails.
Yes, in a nutshell, this isn't what the buildpacks expect. More on that below as well.
The workaround I came up with for the moment is that I unzip the jar file into a separate direcory which I pass as the value for the -app parameter to /cnb/lifecycle/creator.
This isn't the workaround :) it's the solution.
When you pack build --path my.jar
or when you build with Spring Boot build tools, it takes your JAR and passes the extracted files through to the buildpack. The buildpack never sees your JAR, it sees your exploded JAR in a directory. To mimic what pack/SB build tools are doing, you want to extract the JAR contents and pass that through also.
This way I can successfully build a spring boot app image with tekton buildpacks task but I still would like to know what causes the error or what exactly happens when I define the jar file as the "--path" parameter on the "pack"-cli which in turn creates a buildpack container running the /cnb/lifecycle/creator binary.
There are two formats that Paketo's Java buildpacks will recognize:
The latter will run the build tool, produce a JAR/WAR, and then behave exactly like option 1).
Most applications will work with one of these two formats. For example, Spring Boot apps, Dist Zip apps, or anything that produces a standard WAR file.
There is a third format that is partially supported. That is a directory of JAR files. One of the output formats that Quarkus supports uses this format. We also support searching that directory for a single executable JAR, which will run with java -jar
. There are still some buildpacks that don't work with this format though, so I wouldn't recommend this approach unless you know you specifically need it.
The tool you use to build your image doesn't matter so much as how you pass the files into the tool. With pack, it's the --path
flag. With Spring Boot build tools, it's not configurable, the tools handle it automatically. With Tekton, it's the -app
flag. Then pass in one of the sets of files I mentioned above & run the build. The buildpacks should pass detection and build your image.