英文:
How to use the java-buildpack together with the apt-buildpack?
问题
我正在尝试在Cloud Foundry上运行一个Spring Boot应用程序,还需要安装一些需要使用apt安装的东西。
为了安装这些东西,我正在使用apt-buildpack。
已经成功的部分
当我只推送应用程序的JAR文件时,一切都按预期工作:
cf push my-spring-boot-app -f manifest.yml -p my-spring-boot-app.jar
然后应用程序会成功构建和部署。
存在问题的部分
当我将apt-buildpack添加到清单中时,apt-buildpack
会成功执行,但java-buildpack
似乎找不到我的jar文件。它会抛出以下错误:
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
我的manifest.yml
(定义构建包和要上传的构件)大致如下:
caasp_version: 4
applications:
- name: my-spring-boot-app
path: ./target/app #包括apt.yml和my-spring-boot-app.jar的目录
instances: 1
memory: 2GB
disk_quota: 2GB
stack: cflinuxfs3
buildpacks:
- apt_buildpack
- java_buildpack
我已经尝试过的
- 我已经确认JAR文件和
apt.yml
确实被上传到容器中。 - 将我的JAR文件重命名为
aaa.jar
,以确保它在apt.yml
文件之前被放置。 - 启用了
java_buildpack
的调试,但没有帮助我解决问题。
我的问题
我如何在使用apt-buildpack的同时构建/部署我的Spring Boot应用程序?
提前感谢您的回答
英文:
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 theapt.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
答案1
得分: 2
在与java-buildpack的维护者进行一些咨询后,我找到了一个解决方案。
问题在于java-buildpack要求提供一个JAR文件或者一个包含已解压JAR内容的文件夹。这意味着提供一个包含apt.yml
和JAR文件的文件夹是行不通的。
我通过一个简单的bash脚本解决了这个问题,该脚本将apt.yml
和JAR文件移动到一个文件夹中,然后解压JAR文件。然后可以使用cf push
命令推送该文件夹。
bash脚本如下(快速而且不太美观):
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 xf my-spring-boot-app.jar
并且在构建过程之后由一个Maven插件调用:
<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>
英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论