0

I want to achieve the following: Packaging my Spring-Boot app into a Dockerimage where i can call a npx command in order to call a 3rd Party Node Library which i need in my App.

My Pom looks like this:

<build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>build-image</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <image>
                            <name>my-app</name>
                            
                            <buildpacks>
                                <buildpack>gcr.io/paketo-buildpacks/nodejs</buildpack>
                                <buildpack>gcr.io/paketo-buildpacks/java</buildpack>
                            </buildpacks>
                        </image>                           
                    </configuration>
                </plugin>
            </plugins>
        </build>

Now with mvn package the plugin will be executed, but first: it will fail with an error:

Invalid response received when loading image "pack.local/builder/ayvwrfbvbm:latest"

However if i start the whole thing via pack the Image gets created

pack build my-app --builder paketobuildpacks/builder:base --buildpack paketo-buildpacks/nodejs --buildpack paketo-buildpacks/java

But in the created image i can not call node, nor npm nor npx, since it seems these layers are not added there.

If i then add a package.json and a server.js to my App-Root it seems that the npm-install layer is added but still i can not call node nor npm nor npx from within my container.

Please someone can show me a way how to create an image that runs a spring-boot app which then can call a 3rd party npm cli via

Runtime.getRuntime().exec("npx my3rdParty-cli");
DWLabcube
  • 11
  • 1

1 Answers1

0

A few notes.

  1. When you add two buildpacks like --buildpack paketo-buildpacks/nodejs --buildpack paketo-buildpacks/java, it doesn't mean they will both run. Both will examine your code and determine if they can run, what is called the detection process, but ultimately only one of the two buildpack groups you've set will get picked to build your application.

    When you run the build at the top, it'll print a list of the buildpacks selected to execute, so you can see exactly what's executing.

    ===> DETECTING
    6 of 24 buildpacks participating
    paketo-buildpacks/ca-certificates   3.2.4
    paketo-buildpacks/bellsoft-liberica 9.4.0
    paketo-buildpacks/syft              1.13.0
    paketo-buildpacks/executable-jar    6.2.4
    paketo-buildpacks/dist-zip          5.2.4
    paketo-buildpacks/spring-boot       5.13.0
    ...
    
  2. Right now, the Node.js buildpack and Java buildpacks are separate, so you'll either get one or the other. This is why it runs Java by default, but if you add a package.json file it runs Node.js. They are independent of each other.

    There is an open issue to add Node.js into the Java buildpack group so that use cases like this can be supported.

  3. If you are trying to use Node.js/NPM at build time, you can do something like in the demo here where you use a Maven plugin to install Node.js. It'll then be available if you need to perhaps build a front-end and bundle it with your Java app.

  4. If you actually need Node.js/NPM at runtime, that's a trickier problem. 3.) isn't going to do that. You need something that would install Node.js into the actual runtime container. Having the support from 2.) would do that, but in the meantime, there are some options available. In particular, option 4.) from that link. You can use the apt-buildpack to install Node.js and then call out to it from your Java app.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • What a nice Answer! Thx a lot. I ulitmately ended up creating my own base-image via a Dockerfile and used that as my in the Configuration of the spring-boot-maven-plugin. – DWLabcube Jul 27 '22 at 06:51