2

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

Thanks a lot!

Regards, Abhi

1 Answer 1

1

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.

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"]

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.

For reference, I based my Dockerfile on the one in this answer

1
  • Hi Jose, Thank you very much. This helped setting my Java in the container.
    – Abhizoro
    Commented Jan 28, 2020 at 23:29

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.