使用Python运行时在Google App Engine中安装Java
我是Google App Engine的新手.我使用python运行时创建了一个新项目,并使用Flask公开了一些API端点.其中一种方法使用依赖于Java(8+)的python库(tabula-py).当我在本地运行时,一切正常,但是,部署到gcloud后失败了.有关在App Engine中设置Java的任何提示?我无法通过Requirements.txt安装它
I am new to the Google App Engine. I created a new project with a python runtime and used Flask to expose some API endpoints. One of the methods uses a python library(tabula-py) which has dependency on Java (8+). When I ran locally everything worked but, this is failing after deploying to gcloud. Any tips on setting up Java in the App Engine? I can't install it through the requirements.txt
非常感谢!
关于,阿比(Abhi)
Regards, Abhi
GAE在默认情况下仅具有您在 app.yaml
中指定的运行时的容器中运行您的应用程序.但是,您可以使用Python和Java 设置自定义运行时来运行您的应用程序.
GAE runs your apps in containers that by default only have the runtime that you specify in the app.yaml
. However, you can set a custom runtime with Python and Java to run your application with.
为此,您必须使用 GAE Flexible 环境,并在 Dockerfile
中定义如下内容:
In order to do so you must use the GAE Flexible environment and define something like the following in the Dockerfile
:
### 1. Get Linux
FROM alpine:3.7
### 2. Get Java via the package manager
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
### 3. Get Python, PIP
RUN apk add --no-cache python3 \
&& python3 -m ensurepip \
&& pip3 install --upgrade pip setuptools \
&& rm -r /usr/lib/python*/ensurepip && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
ENV FLASK_APP main.py
ENV FLASK_RUN_HOST 0.0.0.0
ENV FLASK_RUN_PORT 8080
### Get Flask for the app
RUN pip install --trusted-host pypi.python.org flask
####
#### OPTIONAL : 4. SET JAVA_HOME environment variable, uncomment the line below if you need it
#ENV JAVA_HOME="/usr/lib/jvm/java-1.8-openjdk"
####
EXPOSE 8080
ADD main.py /
CMD ["flask", "run"]
我测试了自定义运行时,它对我有用,但由于某些原因,导入无法在我的环境中(甚至在本地)失败,因此我无法测试tabula-py库.但是,我认为它应该可以工作.
I tested the custom runtime and it worked for me, but I wasn't able to test the tabula-py library because for some reason, the import fails in my environment (even locally). However, I believe it should work.
作为参考,我将 Dockerfile
基于
查看更多