如何将java-buildpack与apt-buildpack一起使用?

huangapple go评论196阅读模式
英文:

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

问题

我正在尝试在Cloud Foundry上运行一个Spring Boot应用程序,还需要安装一些需要使用apt安装的东西。

为了安装这些东西,我正在使用apt-buildpack。

已经成功的部分
当我只推送应用程序的JAR文件时,一切都按预期工作:

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

然后应用程序会成功构建和部署。

存在问题的部分
当我将apt-buildpack添加到清单中时,apt-buildpack会成功执行,但java-buildpack似乎找不到我的jar文件。它会抛出以下错误:

  1. 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. >
  2. No container can run this application. Please ensure that youve 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.
  3. Failed to compile droplet

我的manifest.yml(定义构建包和要上传的构件)大致如下:

  1. caasp_version: 4
  2. applications:
  3. - name: my-spring-boot-app
  4. path: ./target/app #包括apt.yml和my-spring-boot-app.jar的目录
  5. instances: 1
  6. memory: 2GB
  7. disk_quota: 2GB
  8. stack: cflinuxfs3
  9. buildpacks:
  10. - apt_buildpack
  11. - java_buildpack

我已经尝试过的

  • 我已经确认JAR文件和apt.yml确实被上传到容器中。
  • 将我的JAR文件重命名为aaa.jar,以确保它在apt.yml文件之前被放置。
  • 启用了java_buildpack的调试,但没有帮助我解决问题。

我的问题
我如何在使用apt-buildpack的同时构建/部署我的Spring Boot应用程序?

提前感谢您的回答 如何将java-buildpack与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:

  1. 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:

  1. 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. >
  2. No container can run this application. Please ensure that youve 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.
  3. Failed to compile droplet

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

  1. caasp_version: 4
  2. applications:
  3. - name: my-spring-boot-app
  4. path: ./target/app #Directory which includes the apt.yml and my-spring-boot-app.jar
  5. instances: 1
  6. memory: 2GB
  7. disk_quota: 2GB
  8. stack: cflinuxfs3
  9. buildpacks:
  10. - apt_buildpack
  11. - 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 如何将java-buildpack与apt-buildpack一起使用?

答案1

得分: 2

在与java-buildpack的维护者进行一些咨询后,我找到了一个解决方案。

问题在于java-buildpack要求提供一个JAR文件或者一个包含已解压JAR内容的文件夹。这意味着提供一个包含apt.yml和JAR文件的文件夹是行不通的。

我通过一个简单的bash脚本解决了这个问题,该脚本将apt.yml和JAR文件移动到一个文件夹中,然后解压JAR文件。然后可以使用cf push命令推送该文件夹。

bash脚本如下(快速而且不太美观):

  1. rm -rf "$1/target/app"
  2. mkdir "$1/target/app"
  3. cp $1/apt.yml $1/target/app/apt.yml
  4. cp $1/target/my-spring-boot-app.jar $1/target/app/my-spring-boot-app.jar
  5. cd $1/target/app
  6. jar xf my-spring-boot-app.jar

并且在构建过程之后由一个Maven插件调用:

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <artifactId>exec-maven-plugin</artifactId>
  5. <groupId>org.codehaus.mojo</groupId>
  6. <version>3.1.0</version>
  7. <executions>
  8. <execution>
  9. <id>Create /app directory</id>
  10. <phase>package</phase>
  11. <goals>
  12. <goal>exec</goal>
  13. </goals>
  14. <configuration>
  15. <executable>/bin/bash</executable>
  16. <arguments>
  17. <argument>${basedir}/scripts/create-app-directory.sh</argument>
  18. <argument>${basedir}</argument>
  19. </arguments>
  20. </configuration>
  21. </execution>
  22. </executions>
  23. </plugin>
  24. </plugins>
  25. </build>
英文:

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):

  1. rm -rf &quot;$1/target/app&quot;
  2. mkdir &quot;$1/target/app&quot;
  3. cp $1/apt.yml $1/target/app/apt.yml
  4. cp $1/target/my-spring-boot-app.jar $1/target/app/my-spring-boot-app.jar
  5. cd $1/target/app
  6. jar xfmy-spring-boot-app.jar

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

  1. &lt;build&gt;
  2. &lt;plugins&gt;
  3. &lt;plugin&gt;
  4. &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
  5. &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
  6. &lt;version&gt;3.1.0&lt;/version&gt;
  7. &lt;executions&gt;
  8. &lt;execution&gt;
  9. &lt;id&gt;Create /app directory&lt;/id&gt;
  10. &lt;phase&gt;package&lt;/phase&gt;
  11. &lt;goals&gt;
  12. &lt;goal&gt;exec&lt;/goal&gt;
  13. &lt;/goals&gt;
  14. &lt;configuration&gt;
  15. &lt;executable&gt;/bin/bash&lt;/executable&gt;
  16. &lt;arguments&gt;
  17. &lt;argument&gt;${basedir}/scripts/create-app-directory.sh&lt;/argument&gt;
  18. &lt;argument&gt;${basedir}&lt;/argument&gt;
  19. &lt;/arguments&gt;
  20. &lt;/configuration&gt;
  21. &lt;/execution&gt;
  22. &lt;/executions&gt;
  23. &lt;/plugin&gt;
  24. &lt;/plugins&gt;
  25. &lt;/build&gt;

huangapple
  • 本文由 发表于 2023年7月27日 16:11:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76777742.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定