snowdrop / java-buildpack-client

A simple buildpack (https://buildpacks.io/) platform implementation as a library for java..
Apache License 2.0
13 stars 7 forks source link

Updates to support Platform Spec 0.4-0.12 #59

Closed BarDweller closed 3 weeks ago

BarDweller commented 4 months ago

This PR represents a significant upgrade to the java buildpack client, which previously claimed support only for version 0.4 of the platform spec. This meant only builders that claimed compatibility with version 0.4 of the spec would run as expected. The spec has continued to evolve, most notably adding build image extension (0.10) and run image extension (0.12), and there are public builders (Paketo UBI Builder) using that spec, that will be unable to execute as intended with a 0.4 platform implementation.

An attempt has been made in this PR to tidy up the old code, splitting large executions across multiple classes, this included the configuration interface, which has been broken down into smaller composable units. As such this PR represents a breaking change to the api. We haven't released 1.0 yet, so this should be ok, and migration is relatively simple.

New to this version:

No support is currently planned for oci image layout (platform 0.12) or cache images.. which are implementation options for various revisions of the platform spec. Both are incompatible with extensions, and a primary goal for this updates was to ensure this library could build with builder images making use of extensions.

BarDweller commented 4 months ago

Heads up that the integration tests fail, because they are using jbang to run against the artifact in maven central not the artifact built by this build, so they still point at the old version, and thus cannot work.. Safe to ignore for this commit, but will need updating once the artifact is built & published to maven central

BarDweller commented 4 months ago

Slowly working through testing with Podman ..

Rootless podman:

cmoulliard commented 4 months ago

Github flows are failing. Can you fix them ? @BarDweller

BarDweller commented 4 months ago

Github flows are failing. Can you fix them ? @BarDweller

Heads up that the integration tests fail, because they are using jbang to run against the artifact in maven central not the artifact built by this build, so they still point at the old version, and thus cannot work.. Safe to ignore for this commit, but will need updating once the artifact is built & published to maven central

cmoulliard commented 2 months ago

So I can then review it ? @BarDweller

BarDweller commented 2 months ago

Added 0a7fbbd which is a fairly decent update to allow this to work with podman rootless.

This PR is now ready for review.

cmoulliard commented 1 month ago

I compiled the PR locally and got this error using JDK 21.x

[INFO]
[INFO] Snowdrop :: Java Buildpack Client :: Project ....... SUCCESS [  0.276 s]
[INFO] Snowdrop :: Java Buildpack Client :: Client ........ FAILURE [  3.234 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.555 s
[INFO] Finished at: 2024-05-27T13:11:56+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project buildpack-client: Fatal error compiling: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid' -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

The project is using a old java JDK

    <java.source>1.8</java.source>
    <java.target>1.8</java.target>

We should certainly bump it. WDYT ?
@BarDweller

cmoulliard commented 1 month ago

The main README explaining how to use ./pack.java for a sample

...
./pack.java

The samples use jbang too, but allow the version of the library to be set via an env var for use in our tests! [samples](./samples).

should also explain what to do when the image has been built

When the image has been built, run locally `podman run -i --rm -p 8080:8080 snowdrop/hello-quarkus:latest`

@BarDweller

cmoulliard commented 1 month ago

Why don't we mention end of the building process of a sample that an image has been built ?

./pack.java
...
2024-05-27T13:55:54+02:00 Reading buildpack directory item: web-application-type.toml
2024-05-27T13:55:54+02:00 Reusing tarball for layer "paketo-buildpacks/spring-boot:spring-cloud-bindings" with SHA: sha256:226bdd0803ccc2fdbfd32b27e9c850e95090f0cfd539fcf259b9dc8eaa55bb9e
2024-05-27T13:55:54+02:00 Adding cache layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
2024-05-27T13:55:54+02:00 Layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings' SHA: sha256:226bdd0803ccc2fdbfd32b27e9c850e95090f0cfd539fcf259b9dc8eaa55bb9e
2024-05-27T13:55:54+02:00 Found SBOM of type cache for at /layers/sbom/cache
2024-05-27T13:55:54+02:00 Reusing tarball for layer "buildpacksio/lifecycle:cache.sbom" with SHA: sha256:ba3d34b908554bea571a01346c79e1c942fab1c40d5069c5ab2742bbd7332880
2024-05-27T13:55:54+02:00 Adding cache layer 'buildpacksio/lifecycle:cache.sbom'
2024-05-27T13:55:54+02:00 Layer 'buildpacksio/lifecycle:cache.sbom' SHA: sha256:ba3d34b908554bea571a01346c79e1c942fab1c40d5069c5ab2742bbd7332880
2024-05-27T13:55:54+02:00 Timer: Cache ran for 1.873783544s and ended at 2024-05-27T11:55:54Z
[main] INFO dev.snowdrop.buildpack.lifecycle.phases.Exporter - Buildpack export container complete, with exit code 0
[main] INFO dev.snowdrop.buildpack.lifecycle.LifecyclePhaseFactory - - tidying up the build volumes
[main] INFO dev.snowdrop.buildpack.lifecycle.LifecyclePhaseFactory - - build volumes tidied up

@BarDweller

cmoulliard commented 1 month ago

The process to build the sample samples/hello-spring seems to work as exit process left without error and we can launch the image built but we cannot access the spring boot application

podman run -p 8080:8080 snowdrop/hello-spring:latest 
WARNING: image platform (linux/amd64) does not match the expected platform (linux/arm64)
    Calculating JVM memory based on 1606640K available memory
    For more information on this calculation, see https://paketo.io/docs/reference/java-reference/#memory-calculator
    Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx1221350K -XX:MaxMetaspaceSize=78089K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 1606640K, Thread Count: 50, Loaded Class Count: 11373, Headroom: 0%)
    Enabling Java Native Memory Tracking
Spring Cloud Bindings Enabled
Picked up JAVA_TOOL_OPTIONS: -XX:+ExitOnOutOfMemoryError -Djava.security.properties=/layers/paketo-community_ubi-java-buildpack/java-security-properties/java-security.properties -XX:ActiveProcessorCount=6 -XX:MaxDirectMemorySize=10M -Xmx1221350K -XX:MaxMetaspaceSize=78089K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.1)

2024-05-27 12:00:33.731  INFO 1 --- [           main] d.snowdrop.hellospring.DemoApplication   : Starting DemoApplication v0.0.3-SNAPSHOT using Java 17.0.11 on f29b53a91395 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
2024-05-27 12:00:33.743  INFO 1 --- [           main] d.snowdrop.hellospring.DemoApplication   : No active profile set, falling back to default profiles: default
2024-05-27 12:00:36.915  INFO 1 --- [           main] d.snowdrop.hellospring.DemoApplication   : Started DemoApplication in 5.086 seconds (JVM running for 7.029)

Native Memory Tracking:

Total: reserved=1790302718, committed=140655102
       malloc: 33327614 #83096
       mmap:   reserved=1756975104, committed=107327488

-                 Java Heap (reserved=1251999744, committed=35651584)
                            (mmap: reserved=1251999744, committed=35651584) 

-                     Class (reserved=67501386, committed=2227530)
                            (classes #4093)
                            (  instance classes #3770, array classes #323)
                            (malloc=392522 #8050) (peak=392866 #8053) 
                            (mmap: reserved=67108864, committed=1835008) 
                            (  Metadata:   )
                            (    reserved=67108864, committed=11730944)
                            (    used=11582800)
                            (    waste=148144 =1.26%)
                            (  Class space:)
                            (    reserved=67108864, committed=1835008)
                            (    used=1722936)
                            (    waste=112072 =6.11%)

-                    Thread (reserved=20032144, committed=993936)
                            (thread #19)
                            (stack: reserved=19972096, committed=933888)
                            (malloc=35400 #142) (peak=47432 #158) 
                            (arena=24648 #43) (peak=252544 #41)

-                      Code (reserved=254051016, committed=9999048)
                            (malloc=418504 #2977) (at peak) 
                            (mmap: reserved=253632512, committed=9580544) 

-                        GC (reserved=93456297, committed=48318377)
                            (malloc=13125545 #1729) (peak=13125585 #1730) 
                            (mmap: reserved=80330752, committed=35192832) 

-                  Compiler (reserved=1825676, committed=1825676)
                            (malloc=9812 #193) (peak=39124 #194) 
                            (arena=1815864 #16) (peak=21649792 #19)

-                  Internal (reserved=241043, committed=241043)
                            (malloc=204179 #3521) (peak=205413 #3528) 
                            (mmap: reserved=36864, committed=36864) 

-                    Symbol (reserved=3454000, committed=3454000)
                            (malloc=3085360 #64410) (at peak) 
                            (arena=368640 #1) (at peak)

-    Native Memory Tracking (reserved=1347744, committed=1347744)
                            (malloc=18208 #304) (peak=18792 #311) 
                            (tracking overhead=1329536)

-        Shared class space (reserved=16777216, committed=12357632)
                            (mmap: reserved=16777216, committed=12357632) 

-               Arena Chunk (reserved=12337480, committed=12337480)
                            (malloc=12337480 #497) (peak=22063224 #560) 

-                   Tracing (reserved=345, committed=345)
                            (malloc=345 #9) (at peak) 

-                 Arguments (reserved=171, committed=171)
                            (malloc=171 #5) (at peak) 

-                    Module (reserved=49760, committed=49760)
                            (malloc=49760 #649) (at peak) 

-                 Safepoint (reserved=8192, committed=8192)
                            (mmap: reserved=8192, committed=8192) 

-           Synchronization (reserved=43176, committed=43176)
                            (malloc=43176 #543) (peak=43280 #544) 

-            Serviceability (reserved=672, committed=672)
                            (malloc=672 #6) (at peak) 

-                 Metaspace (reserved=67171792, committed=11793872)
                            (malloc=62928 #33) (at peak) 
                            (mmap: reserved=67108864, committed=11730944) 

-      String Deduplication (reserved=704, committed=704)
                            (malloc=704 #8) (at peak) 

-           Object Monitors (reserved=4160, committed=4160)
                            (malloc=4160 #20) (at peak) 

in a separate terminal
curl -v http://localhost:8080/hello
*   Trying [::1]:8080...
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1:8080...
* connect to 127.0.0.1 port 8080 failed: Connection refused
* Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server
* Closing connection
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server

@BarDweller

BarDweller commented 1 month ago

The project is using a old java JDK

    <java.source>1.8</java.source>
    <java.target>1.8</java.target>

We should certainly bump it. WDYT ? @BarDweller

iirc, 1.8 was being used to ensure the created library would be consumable by projects running on java 8 jvms.. I'd need to dig to look into why, but that isn't something that will be addressed in this PR.

BarDweller commented 1 month ago

The process to build the sample samples/hello-spring seems to work as exit process left without error and we can launch the image built but we cannot access the spring boot application

podman run -p 8080:8080 snowdrop/hello-spring:latest 
WARNING: image platform (linux/amd64) does not match the expected platform (linux/arm64)
    Calculating JVM memory based on 1606640K available memory
    For more information on this calculation, see https://paketo.io/docs/reference/java-reference/#memory-calculator
    Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx1221350K -XX:MaxMetaspaceSize=78089K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 1606640K, Thread Count: 50, Loaded Class Count: 11373, Headroom: 0%)
    Enabling Java Native Memory Tracking
Spring Cloud Bindings Enabled
Picked up JAVA_TOOL_OPTIONS: -XX:+ExitOnOutOfMemoryError -Djava.security.properties=/layers/paketo-community_ubi-java-buildpack/java-security-properties/java-security.properties -XX:ActiveProcessorCount=6 -XX:MaxDirectMemorySize=10M -Xmx1221350K -XX:MaxMetaspaceSize=78089K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.1)

2024-05-27 12:00:33.731  INFO 1 --- [           main] d.snowdrop.hellospring.DemoApplication   : Starting DemoApplication v0.0.3-SNAPSHOT using Java 17.0.11 on f29b53a91395 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
2024-05-27 12:00:33.743  INFO 1 --- [           main] d.snowdrop.hellospring.DemoApplication   : No active profile set, falling back to default profiles: default
2024-05-27 12:00:36.915  INFO 1 --- [           main] d.snowdrop.hellospring.DemoApplication   : Started DemoApplication in 5.086 seconds (JVM running for 7.029)

Native Memory Tracking:

Total: reserved=1790302718, committed=140655102
       malloc: 33327614 #83096
       mmap:   reserved=1756975104, committed=107327488

-                 Java Heap (reserved=1251999744, committed=35651584)
                            (mmap: reserved=1251999744, committed=35651584) 

-                     Class (reserved=67501386, committed=2227530)
                            (classes #4093)
                            (  instance classes #3770, array classes #323)
                            (malloc=392522 #8050) (peak=392866 #8053) 
                            (mmap: reserved=67108864, committed=1835008) 
                            (  Metadata:   )
                            (    reserved=67108864, committed=11730944)
                            (    used=11582800)
                            (    waste=148144 =1.26%)
                            (  Class space:)
                            (    reserved=67108864, committed=1835008)
                            (    used=1722936)
                            (    waste=112072 =6.11%)

-                    Thread (reserved=20032144, committed=993936)
                            (thread #19)
                            (stack: reserved=19972096, committed=933888)
                            (malloc=35400 #142) (peak=47432 #158) 
                            (arena=24648 #43) (peak=252544 #41)

-                      Code (reserved=254051016, committed=9999048)
                            (malloc=418504 #2977) (at peak) 
                            (mmap: reserved=253632512, committed=9580544) 

-                        GC (reserved=93456297, committed=48318377)
                            (malloc=13125545 #1729) (peak=13125585 #1730) 
                            (mmap: reserved=80330752, committed=35192832) 

-                  Compiler (reserved=1825676, committed=1825676)
                            (malloc=9812 #193) (peak=39124 #194) 
                            (arena=1815864 #16) (peak=21649792 #19)

-                  Internal (reserved=241043, committed=241043)
                            (malloc=204179 #3521) (peak=205413 #3528) 
                            (mmap: reserved=36864, committed=36864) 

-                    Symbol (reserved=3454000, committed=3454000)
                            (malloc=3085360 #64410) (at peak) 
                            (arena=368640 #1) (at peak)

-    Native Memory Tracking (reserved=1347744, committed=1347744)
                            (malloc=18208 #304) (peak=18792 #311) 
                            (tracking overhead=1329536)

-        Shared class space (reserved=16777216, committed=12357632)
                            (mmap: reserved=16777216, committed=12357632) 

-               Arena Chunk (reserved=12337480, committed=12337480)
                            (malloc=12337480 #497) (peak=22063224 #560) 

-                   Tracing (reserved=345, committed=345)
                            (malloc=345 #9) (at peak) 

-                 Arguments (reserved=171, committed=171)
                            (malloc=171 #5) (at peak) 

-                    Module (reserved=49760, committed=49760)
                            (malloc=49760 #649) (at peak) 

-                 Safepoint (reserved=8192, committed=8192)
                            (mmap: reserved=8192, committed=8192) 

-           Synchronization (reserved=43176, committed=43176)
                            (malloc=43176 #543) (peak=43280 #544) 

-            Serviceability (reserved=672, committed=672)
                            (malloc=672 #6) (at peak) 

-                 Metaspace (reserved=67171792, committed=11793872)
                            (malloc=62928 #33) (at peak) 
                            (mmap: reserved=67108864, committed=11730944) 

-      String Deduplication (reserved=704, committed=704)
                            (malloc=704 #8) (at peak) 

-           Object Monitors (reserved=4160, committed=4160)
                            (malloc=4160 #20) (at peak) 

in a separate terminal
curl -v http://localhost:8080/hello
*   Trying [::1]:8080...
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1:8080...
* connect to 127.0.0.1 port 8080 failed: Connection refused
* Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server
* Closing connection
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server

@BarDweller

There is no application to access.. the spring boot code contains no resources for you to access, and never has. It has only ever been there to test that the library can build the application successfully.

BarDweller commented 1 month ago

The main README explaining how to use ./pack.java for a sample

...
./pack.java

The samples use jbang too, but allow the version of the library to be set via an env var for use in our tests! [samples](./samples).

should also explain what to do when the image has been built

When the image has been built, run locally `podman run -i --rm -p 8080:8080 snowdrop/hello-quarkus:latest`

@BarDweller

The readme is talking about how to run the sample of code provided, and links to the samples by way for further examples of using jbang.. in the case of the supplied code fragment.. we cannot tell someone how to run an image built from code we do not know, and the intent & meaning for this part of the README has not been changed by this PR. If you think this needs addressing, please raise an Issue.

BarDweller commented 1 month ago

Why don't we mention end of the building process of a sample that an image has been built ?

./pack.java
...
2024-05-27T13:55:54+02:00 Reading buildpack directory item: web-application-type.toml
2024-05-27T13:55:54+02:00 Reusing tarball for layer "paketo-buildpacks/spring-boot:spring-cloud-bindings" with SHA: sha256:226bdd0803ccc2fdbfd32b27e9c850e95090f0cfd539fcf259b9dc8eaa55bb9e
2024-05-27T13:55:54+02:00 Adding cache layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
2024-05-27T13:55:54+02:00 Layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings' SHA: sha256:226bdd0803ccc2fdbfd32b27e9c850e95090f0cfd539fcf259b9dc8eaa55bb9e
2024-05-27T13:55:54+02:00 Found SBOM of type cache for at /layers/sbom/cache
2024-05-27T13:55:54+02:00 Reusing tarball for layer "buildpacksio/lifecycle:cache.sbom" with SHA: sha256:ba3d34b908554bea571a01346c79e1c942fab1c40d5069c5ab2742bbd7332880
2024-05-27T13:55:54+02:00 Adding cache layer 'buildpacksio/lifecycle:cache.sbom'
2024-05-27T13:55:54+02:00 Layer 'buildpacksio/lifecycle:cache.sbom' SHA: sha256:ba3d34b908554bea571a01346c79e1c942fab1c40d5069c5ab2742bbd7332880
2024-05-27T13:55:54+02:00 Timer: Cache ran for 1.873783544s and ended at 2024-05-27T11:55:54Z
[main] INFO dev.snowdrop.buildpack.lifecycle.phases.Exporter - Buildpack export container complete, with exit code 0
[main] INFO dev.snowdrop.buildpack.lifecycle.LifecyclePhaseFactory - - tidying up the build volumes
[main] INFO dev.snowdrop.buildpack.lifecycle.LifecyclePhaseFactory - - build volumes tidied up

@BarDweller

Because we never have tested this, and this PR doesn't alter that.

The library returns an exit code, and really, the pack.java is just there to check it all works.

The library should not be mentioning anything, you are viewing the trace logs & info logs output by the lib, which confirm it did its job correctly.. the exit code tells the caller if it worked, and its up to the caller to decide what to do with that status.. in this case, the caller is pack.java, which takes that exit code and makes it its own, which should cause the integration test to fail if the library invocation failed. If you want to raise an Issue to make the sample pack.java also output human friendly messages, go ahead..

cmoulliard commented 1 month ago

There is no application to access.. the spring boot code contains no resources for you to access, and never has. It has only ever been there to test that the library can build the application successfully.

Ok. So we will in a separate PR improve the Spring Boot example or add a README to mention what is the purpose of this sample then

cmoulliard commented 1 month ago

If you want to raise an Issue to make the sample pack.java also output human friendly messages, go ahead..

Will do that :-)

BarDweller commented 3 weeks ago

Tests are green, review comments have been met, and @cmoulliard has indicated via zulip that this is good to merge..