javaspring-bootdockerbuildpackfly

Cloud Native Buildpacks support on fly.io for Spring Boot apps: No buildpack groups passed detection


Recently I discovered fly.io as an alternative to Heroku, where they stop to provide their free dynos from November 28th on. There's a guide for how to use Deno mit fly.io and Buildpacks, but non for Spring Boot / Java.

Also I read about the build section in the fly.toml in the docs. Their it's stated to define a builder and buildpacks like this:

[build]
  builder = "paketobuildpacks/builder:base"
  buildpacks = ["gcr.io/paketo-buildpacks/nodejs"]

So for Spring Boot I adopted that into the following config:

[build]
  builder = "paketobuildpacks/builder:base"
  buildpacks = ["gcr.io/paketo-buildpacks/spring-boot"]

But when I run fly deploy the builder is loaded correctly but inside the DETECTING phase I run into the following error:

$ fly deploy
==> Verifying app config
--> Verified app config
==> Building image
Remote builder fly-builder-little-silence-4534 ready
==> Building image with Buildpacks
--> docker host: 20.10.12 linux x86_64
base: Pulling from paketobuildpacks/builder
b5da66d4625a: Pulling fs layer
...
4f4fb700ef54: Pull complete
Digest: sha256:bbc26d8b7fe183a1d59fba3e19b55d7a1e647de0bbf5aa14be98e328c4b7d777
Status: Downloaded newer image for paketobuildpacks/builder:base
base-cnb: Pulling from paketobuildpacks/run
b5da66d4625a: Already exists
80857de9da00: Already exists
239caa1e3c6f: Pull complete
ed65ad332a5e: Pull complete
4fe6ac7cc235: Pull complete
Digest: sha256:cfc9b596bedc7bead1b3714a69dffa1fb17fcb1f7bba5c3faadb40c0b6f5acbd
Status: Downloaded newer image for paketobuildpacks/run:base-cnb
latest: Pulling from paketo-buildpacks/spring-boot
3301de03cfeb: Pull complete
Digest: sha256:a6551c90f9af0719233ff4a97408a8ea8054e90f776b592dcbc7f37c03c9518c
Status: Downloaded newer image for gcr.io/paketo-buildpacks/spring-boot:latest
===> DETECTING
ERROR: No buildpack groups passed detection.
ERROR: Please check that you are running against the correct path.
ERROR: failed to detect: no buildpacks participating
Error failed to fetch an image or build from source: executing lifecycle: failed with status code: 20

Solution

  • As a common user of Cloud Native Buildpacks (CNB) I found it strange that the fly.io docs stated to define a buildpacks parameter at all. Since one of the many benefits of CNB is that they are detecting what your app needs in order to be build. Including every needed buildpack. So it would only make sense to define the builder, which then detects the buildpacks needed.

    And that's also the solution here. You simple need to omit the buildpacks setting in the build configuration. The builder tag is all we need:

    [build]
      builder = "paketobuildpacks/builder:base"
    

    This should activate the Buildpacks detection for your project correctly and trigger a successful deployment on fly.io. It will also push the image straight to fly.io Docker registry at registry.fly.io/microservice-api-spring-boot. Here's a example output for a fly deploy:

    $ fly deploy
    ==> Verifying app config
    --> Verified app config
    ==> Building image
    Remote builder fly-builder-little-silence-4534 ready
    ==> Building image with Buildpacks
    --> docker host: 20.10.12 linux x86_64
    base: Pulling from paketobuildpacks/builder
    Digest: sha256:bbc26d8b7fe183a1d59fba3e19b55d7a1e647de0bbf5aa14be98e328c4b7d777
    Status: Image is up to date for paketobuildpacks/builder:base
    base-cnb: Pulling from paketobuildpacks/run
    Digest: sha256:cfc9b596bedc7bead1b3714a69dffa1fb17fcb1f7bba5c3faadb40c0b6f5acbd
    Status: Image is up to date for paketobuildpacks/run:base-cnb
    ===> DETECTING
    10 of 24 buildpacks participating
    paketo-buildpacks/ca-certificates   3.3.0
    paketo-buildpacks/bellsoft-liberica 9.6.1
    paketo-buildpacks/syft              1.18.0
    paketo-buildpacks/maven             6.7.0
    paketo-buildpacks/executable-jar    6.4.0
    paketo-buildpacks/apache-tomcat     7.5.0
    paketo-buildpacks/apache-tomee      1.2.0
    paketo-buildpacks/liberty           2.1.1
    paketo-buildpacks/dist-zip          5.3.0
    paketo-buildpacks/spring-boot       5.18.0
    ===> ANALYZING
    Previous image with name "registry.fly.io/microservice-api-spring-boot:cache" not found
    ===> RESTORING
    ===> BUILDING
    
    Paketo CA Certificates Buildpack 3.3.0
      https://github.com/paketo-buildpacks/ca-certificates
      Launch Helper: Contributing to layer
        Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
    
    Paketo BellSoft Liberica Buildpack 9.6.1
      https://github.com/paketo-buildpacks/bellsoft-liberica
      Build Configuration:
        $BP_JVM_JLINK_ARGS           --no-man-pages --no-header-files --strip-debug --compress=1  configure custom link arguments (--output must be omitted)
        $BP_JVM_JLINK_ENABLED        false                                                        enables running jlink tool to generate custom JRE
        $BP_JVM_TYPE                 JRE                                                          the JVM type - JDK or JRE
        $BP_JVM_VERSION              11                                                           the Java version
      Launch Configuration:
        $BPL_DEBUG_ENABLED           false                                                        enables Java remote debugging support
        $BPL_DEBUG_PORT              8000                                                         configure the remote debugging port
        $BPL_DEBUG_SUSPEND           false                                                        configure whether to suspend execution until a debugger has attached
        $BPL_HEAP_DUMP_PATH                                                                       write heap dumps on error to this path
        $BPL_JAVA_NMT_ENABLED        true                                                         enables Java Native Memory Tracking (NMT)
        $BPL_JAVA_NMT_LEVEL          summary                                                      configure level of NMT, summary or detail
        $BPL_JFR_ARGS                                                                             configure custom Java Flight Recording (JFR) arguments
        $BPL_JFR_ENABLED             false                                                        enables Java Flight Recording (JFR)
        $BPL_JMX_ENABLED             false                                                        enables Java Management Extensions (JMX)
        $BPL_JMX_PORT                5000                                                         configure the JMX port
        $BPL_JVM_HEAD_ROOM           0                                                            the headroom in memory calculation
        $BPL_JVM_LOADED_CLASS_COUNT  35% of classes                                               the number of loaded classes in memory calculation
        $BPL_JVM_THREAD_COUNT        250                                                          the number of threads in memory calculation
        $JAVA_TOOL_OPTIONS                                                                        the JVM launch flags
        Using buildpack default Java version 11
      BellSoft Liberica JDK 11.0.16: Contributing to layer
        Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.16.1+1/bellsoft-jdk11.0.16.1+1-linux-amd64.tar.gz
        Verifying checksum
        Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jdk
        Adding 127 container CA certificates to JVM truststore
        Writing env.build/JAVA_HOME.override
        Writing env.build/JDK_HOME.override
      BellSoft Liberica JRE 11.0.16: Contributing to layer
        Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.16.1+1/bellsoft-jre11.0.16.1+1-linux-amd64.tar.gz
        Verifying checksum
        Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jre
        Adding 127 container CA certificates to JVM truststore
        Writing env.launch/BPI_APPLICATION_PATH.default
        Writing env.launch/BPI_JVM_CACERTS.default
        Writing env.launch/BPI_JVM_CLASS_COUNT.default
        Writing env.launch/BPI_JVM_SECURITY_PROVIDERS.default
        Writing env.launch/JAVA_HOME.default
        Writing env.launch/JAVA_TOOL_OPTIONS.append
        Writing env.launch/JAVA_TOOL_OPTIONS.delim
        Writing env.launch/MALLOC_ARENA_MAX.default
      Launch Helper: Contributing to layer
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/active-processor-count
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/java-opts
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jvm-heap
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/link-local-dns
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/memory-calculator
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/security-providers-configurer
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jmx
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/jfr
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/security-providers-classpath-9
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/debug-9
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/nmt
        Creating /layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/openssl-certificate-loader
      Java Security Properties: Contributing to layer
        Writing env.launch/JAVA_SECURITY_PROPERTIES.default
        Writing env.launch/JAVA_TOOL_OPTIONS.append
        Writing env.launch/JAVA_TOOL_OPTIONS.delim
    
    Paketo Buildpack for Syft 1.18.0
      https://github.com/paketo-buildpacks/syft
        Downloading from https://github.com/anchore/syft/releases/download/v0.55.0/syft_0.55.0_linux_amd64.tar.gz
        Verifying checksum
        Writing env.build/SYFT_CHECK_FOR_APP_UPDATE.default
    
    Paketo Maven Buildpack 6.7.0
      https://github.com/paketo-buildpacks/maven
      Build Configuration:
        $BP_MAVEN_BUILD_ARGUMENTS  -Dmaven.test.skip=true --no-transfer-progress package  the arguments to pass to Maven
        $BP_MAVEN_BUILT_ARTIFACT   target/*.[ejw]ar                                       the built application artifact explicitly.  Supersedes $BP_MAVEN_BUILT_MODULE
        $BP_MAVEN_BUILT_MODULE                                                            the module to find application artifact in
        $BP_MAVEN_DAEMON_ENABLED   false                                                  use maven daemon
        $BP_MAVEN_POM_FILE         pom.xml                                                the location of the main pom.xml file, relative to the application root
        $BP_MAVEN_SETTINGS_PATH                                                           the path to a Maven settings file
      Apache Maven 3.8.6: Contributing to layer
        Downloading from https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.tar.gz
        Verifying checksum
        Expanding to /layers/paketo-buildpacks_maven/maven
        Creating cache directory /home/cnb/.m2
      Compiled Application: Contributing to layer
        Executing mvn --batch-mode -Dmaven.test.skip=true --no-transfer-progress package
          [INFO] Scanning for projects...
          [INFO]
          [INFO] -------< org.springframework.boot:microservice-api-spring-boot >--------
          [INFO] Building microservice-api-spring-boot 2.7.2
          [INFO] --------------------------------[ jar ]---------------------------------
          [INFO]
          [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ microservice-api-spring-boot ---
          [INFO] Using 'UTF-8' encoding to copy filtered resources.
          [INFO] Using 'UTF-8' encoding to copy filtered properties files.
          [INFO] Copying 1 resource
          [INFO] Copying 0 resource
          [INFO]
          [INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ microservice-api-spring-boot ---
          [INFO] Changes detected - recompiling the module!
          [INFO] Compiling 6 source files to /workspace/target/classes
          [INFO] /workspace/src/main/java/de/jonashackt/springbootvuejs/configuration/WebSecurityConfiguration.java: /workspace/src/main/java/de/jonashackt/springbootvuejs/configuration/WebSecurityConfiguration.java uses or overrides a deprecated API.
          [INFO] /workspace/src/main/java/de/jonashackt/springbootvuejs/configuration/WebSecurityConfiguration.java: Recompile with -Xlint:deprecation for details.
          [INFO]
          [INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ microservice-api-spring-boot ---
          [INFO] Not copying test resources
          [INFO]
          [INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ microservice-api-spring-boot ---
          [INFO] Not compiling test sources
          [INFO]
          [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ microservice-api-spring-boot ---
          [INFO] Tests are skipped.
          [INFO]
          [INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ microservice-api-spring-boot ---
          [INFO] Building jar: /workspace/target/microservice-api-spring-boot-2.7.2.jar
          [INFO]
          [INFO] --- spring-boot-maven-plugin:2.7.2:repackage (repackage) @ microservice-api-spring-boot ---
          [INFO] Replacing main artifact with repackaged archive
          [INFO] ------------------------------------------------------------------------
          [INFO] BUILD SUCCESS
          [INFO] ------------------------------------------------------------------------
          [INFO] Total time:  10.274 s
          [INFO] Finished at: 2022-09-12T10:49:04Z
          [INFO] ------------------------------------------------------------------------
    
      Removing source code
      Restoring application artifact
    
    Paketo Executable JAR Buildpack 6.4.0
      https://github.com/paketo-buildpacks/executable-jar
      Class Path: Contributing to layer
        Writing env/CLASSPATH.delim
        Writing env/CLASSPATH.prepend
      Process types:
        executable-jar: java org.springframework.boot.loader.JarLauncher (direct)
        task:           java org.springframework.boot.loader.JarLauncher (direct)
        web:            java org.springframework.boot.loader.JarLauncher (direct)
    
    Paketo Buildpack for Spring Boot 5.18.0
      https://github.com/paketo-buildpacks/spring-boot
      Build Configuration:
        $BP_SPRING_CLOUD_BINDINGS_DISABLED   false  whether to contribute Spring Boot cloud bindings support
      Launch Configuration:
        $BPL_SPRING_CLOUD_BINDINGS_DISABLED  false  whether to auto-configure Spring Boot environment properties from bindings
        $BPL_SPRING_CLOUD_BINDINGS_ENABLED   true   Deprecated - whether to auto-configure Spring Boot environment properties from bindings
      Creating slices from layers index
        dependencies (50.6 MB)
        spring-boot-loader (283.6 KB)
        snapshot-dependencies (0.0 B)
        application (71.5 KB)
      Launch Helper: Contributing to layer
        Creating /layers/paketo-buildpacks_spring-boot/helper/exec.d/spring-cloud-bindings
      Spring Cloud Bindings 1.10.0: Contributing to layer
        Downloading from https://repo.spring.io/release/org/springframework/cloud/spring-cloud-bindings/1.10.0/spring-cloud-bindings-1.10.0.jar
        Verifying checksum
        Copying to /layers/paketo-buildpacks_spring-boot/spring-cloud-bindings
      Web Application Type: Contributing to layer
        Servlet web application detected
        Writing env.launch/BPL_JVM_THREAD_COUNT.default
      4 application slices
      Image labels:
        org.opencontainers.image.title
        org.opencontainers.image.version
        org.springframework.boot.version
    ===> EXPORTING
    Adding layer 'paketo-buildpacks/ca-certificates:helper'
    Adding layer 'paketo-buildpacks/bellsoft-liberica:helper'
    Adding layer 'paketo-buildpacks/bellsoft-liberica:java-security-properties'
    Adding layer 'paketo-buildpacks/bellsoft-liberica:jre'
    Adding layer 'paketo-buildpacks/executable-jar:classpath'
    Adding layer 'paketo-buildpacks/spring-boot:helper'
    Adding layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
    Adding layer 'paketo-buildpacks/spring-boot:web-application-type'
    Adding 5/5 app layer(s)
    Adding layer 'launcher'
    Adding layer 'config'
    Adding layer 'process-types'
    Adding label 'io.buildpacks.lifecycle.metadata'
    Adding label 'io.buildpacks.build.metadata'
    Adding label 'io.buildpacks.project.metadata'
    Adding label 'org.opencontainers.image.title'
    Adding label 'org.opencontainers.image.version'
    Adding label 'org.springframework.boot.version'
    Setting default process type 'web'
    Saving registry.fly.io/microservice-api-spring-boot:cache...
    *** Images (28a69cfce36e):
          registry.fly.io/microservice-api-spring-boot:cache
          registry.fly.io/microservice-api-spring-boot:deployment-01GCRMZ79R99H9RRXFK7H47X3B
    Adding cache layer 'paketo-buildpacks/bellsoft-liberica:jdk'
    Adding cache layer 'paketo-buildpacks/syft:syft'
    Adding cache layer 'paketo-buildpacks/maven:application'
    Adding cache layer 'paketo-buildpacks/maven:cache'
    Adding cache layer 'paketo-buildpacks/maven:maven'
    --> Building image done
    ==> Pushing image to fly
    The push refers to repository [registry.fly.io/microservice-api-spring-boot]
    1dc94a70dbaa: Pushed
    ...
    4a641e21953d: Pushed
    deployment-01GCRMZ79R99H9RRXFK7H47X3B: digest: sha256:5e77e023b3862ec1edffcee1d78c5b23a5ae6957f6028da0bff16e4b7fd5264f size: 4702
    --> Pushing image done
    image: registry.fly.io/microservice-api-spring-boot:deployment-01GCRMZ79R99H9RRXFK7H47X3B
    image size: 296 MB
    ==> Creating release
    --> release v4 created
    
    --> You can detach the terminal anytime without stopping the deployment
    ==> Monitoring deployment
    
     1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]
    --> v4 deployed successfully