问题描述
我需要从使用cf部署的python flask应用程序运行java命令.我们如何使Java运行时可用于此python flask应用程序.
I need to run java command from python flask application which is deployed using cf. How can we make java runtime available to this python flask app.
我尝试使用multi-buildpack,但是java_buildpack期望在部署应用程序时执行一些jar或war.
I tried using multi-buildpack, but java_buildpack expects some jar or war to be executed while deploying the application.
有什么方法可以使Java适用于python flask应用程序吗?
Any approach that would make java available to python flask app?
推荐答案
buildpack链中的最后一个buildpack负责确定启动您的应用程序的命令,这就是Java buildpack希望执行JAR/WAR的原因.
The last buildpack in the buildpack chain is responsible for determining a command to start your application which is why the Java buildpack expects a JAR/WAR to execute.
在撰写本文时,Java buildpack尚未提供 supply
脚本,因此在使用多buildpack支持时只能作为 last buildpack运行.看起来在将来的某个时候,Java buildpack将提供一个 supply
脚本,但这仍在进行中此处.
The Java buildpack, as of writing this, does not ship a supply
script so it can only be run as the last buildpack when using multi buildpack support. It looks like that at some point in the future the Java buildpack will provide a supply
script, but this is still being worked out here.
现在,您可以使用 apt-buildpack 并安装JRE/JDK这样.
For now, what you can do is use the apt-buildpack and install a JRE/JDK that way.
要执行此操作,请在项目文件夹的根目录中添加一个名为 apt.yml
的文件.在该文件中,放入以下内容:
To do this, add a file called apt.yml
to the root of your project folder. In that file, put the following:
---
packages:
- openjdk-8-jre
repos:
- deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu trusty main
keys:
- https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xEB9B1D8886F44E2A
这将告诉apt buildpack为Ubuntu Trusty添加一个PPA,在这里我们可以获得最新的openjdk8.它安装在/home/vcap/deps/0
下,将 java
可执行文件放在/home/vcap/deps/0/lib/jvm/java中-8-openjdk-amd64/bin/java
.
This will tell the apt buildpack to add a PPA for Ubuntu Trusty where we can get the latest openjdk8. This gets installed under /home/vcap/deps/0
, which puts the java
executable at /home/vcap/deps/0/lib/jvm/java-8-openjdk-amd64/bin/java
.
注意:不幸的是,由于Ubuntu使用 update-alternatives
的方式,因此 java
二进制文件不在路径中,因此我们无法使用将该工具放在CF应用程序容器中的路径上,因为我们没有root用户访问权限.
Note: The java
binary is unfortunately not on the path because of the way Ubuntu uses update-alternatives
and we can't use that tool to put it on the path in the CF app container because we don't have root access.
设置完毕后,您将按照常规说明使用多个buildpack.
After setting that up, you'd follow the normal instructions for using multiple buildpacks.
$ cf push YOUR-APP --no-start -b binary_buildpack
$ cf v3-push YOUR-APP -b https://github.com/cloudfoundry/apt-buildpack#v0.1.1 -b python_buildpack
注意:将来使用多个buildpack进行推送的过程可能会发生变化,而目前仍处于试验阶段的 v3-push
将会消失.
Note: The process to push using multiple buildpacks will likely change in the future and v3-push
, which is currently experimental, will go away.
注意:上面的示例为apt buildpack的硬代码版本 v0.1.1
.您应该使用最新的稳定版本,您可以在此处找到.不建议使用master分支.
Note: The example above hard codes version v0.1.1
of the apt buildpack. You should use the latest stable release, which you can find here. Using the master branch is not recommended.
这篇关于在Python Flask Cloud Foundry中添加Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!