Search code examples
javaspring-bootcloud-foundrybuildpack

How to use the java-buildpack together with the apt-buildpack?


What I am trying to accomplish
I'm trying to get a Spring Boot application running on Cloud Foundry, which also need some things that need to be installed with apt.

To install said things, I'm using the apt-buildpack.

What works
When I push just the JAR for the application everything works as expected:

cf push my-spring-boot-app -f manifest.yml -p my-spring-boot-app.jar

The app then gets successfully built and deployed.

What doesn't work
When I add the apt-buildpack to the manifest, the apt-buildpack is then successfully executed but the java-buildpack doesn't seem to find my jar. It throws the following error:

ERROR Compile failed with exception #<RuntimeError: No container can run this application. Please ensure that you’ve pushed a valid JVM artifact or artifacts using the -p command line argument or path manifest entry. Information about valid JVM artifacts can be found at https://github.com/cloudfoundry/java-buildpack#additional-documentation. >
No container can run this application. Please ensure that you’ve pushed a valid JVM artifact or artifacts using the -p command line argument or path manifest entry. Information about valid JVM artifacts can be found at https://github.com/cloudfoundry/java-buildpack#additional-documentation. 
Failed to compile droplet

My manifest.yml (which defines the buildpacks and the artifact(s) to upload) looks something like this:

caasp_version: 4
applications:
  - name: my-spring-boot-app
    path: ./target/app #Directory which includes the apt.yml and my-spring-boot-app.jar
    instances: 1
    memory: 2GB
    disk_quota: 2GB
    stack: cflinuxfs3
    buildpacks:
      - apt_buildpack
      - java_buildpack

What I've already tried

  • I've already confirmed that the JAR, aswell as the apt.yml, are indeed uploaded into the container.
  • Renamed my JAR to aaa.jar to ensure it is placed before the apt.yml file.
  • Enabled debugging for the java_buildpack, which I did not help me.

My question
How can I build/deploy my Spring Boot application while also using the apt-buildpack?

Thanks in advance for any answers :)


Solution

  • After some consultation with the maintainers of the java-buildpack, I've found a solution.

    The problem is that the java-buildpack expects either a JAR or a folder with the contents of the exploded JAR. That means supplying a folder with the apt.yml and the JAR won't work.

    I've solved this with a simple bash script that moves the apt.yml and JAR into a folder and then explodes the jar. This folder can then be pushed with cf push.

    The bash script looks like this(fast and ugly):

    rm -rf "$1/target/app"
    mkdir "$1/target/app"
    cp $1/apt.yml $1/target/app/apt.yml
    cp $1/target/my-spring-boot-app.jar $1/target/app/my-spring-boot-app.jar
    
    cd $1/target/app
    jar xfmy-spring-boot-app.jar
    

    and gets called by a Maven plugin after the build process:

        <build>
            <plugins>
                <plugin>
                    <artifactId>exec-maven-plugin</artifactId>
                    <groupId>org.codehaus.mojo</groupId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <id>Create /app directory</id>
                            <phase>package</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>/bin/bash</executable>
                                <arguments>
                                    <argument>${basedir}/scripts/create-app-directory.sh</argument>
                                    <argument>${basedir}</argument>
                                </arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>