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

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

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应用程序?

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

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 如何将java-buildpack与apt-buildpack一起使用?

答案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 &quot;$1/target/app&quot;
mkdir &quot;$1/target/app&quot;
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:

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

确定