Has anyone deployed to Google Cloud Platform?

Thank you. It’s a bit longer process, but on GKE it works.

Hi! Do you know if it’s possible to deploy using Google App Engine’s standard environment? I’ve deployed a simple streamlit app with the flex environment (with minimum requirements to run it) but the standard env is way cheaper. Thank you!

Jairo
As far as I know AppEngine will still not run Streamlit for any length of time. That was certainly my experience and I abandoned that approach some months back. The issue is Websocket support and timeout.

GKE deployment is mostly straightforward, it gets more complicated if you want to use the Identity Aware proxy to secure access to your pages. We did increase the Websocket timeouts for our GKE configurations.

These two blog posts are helpful

5 Likes

Thanks for your prompt reply @knorthover ! I’ll give it a try. Btw, do you think that deployment on AWS would be easier (say, using EC2) than GCP?

It’s interesting because I’ve used the Google App Engine to deploy my simple app with a flex env and it’s worked for a couple of months. I do see however an error once in a while that may have to do with the websocket issue discussed in this forum.

Jairo
I’ve no experience with AWS. All I can tell you is that my summer intern, who has deployed apps on AWS, has just been learning about Google Cloud and tells me GCP is much easier.
Kevin

2 Likes

Hi everyone!

I’m trying to deploy in App. Engine with no luck. I have followed the comments but I get this error:

Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error! Code: APP_CONTAINER_CRASHED
2020-09-26 16:37:01.780
Warning: the config option 'server.enableCORS=false' is not compatible with 'server.enableXsrfProtection=true'.
As a result, 'server.enableCORS' is being overridden to 'true'.

More information:
In order to protect against CSRF attacks, we send a cookie with each request.
To do so, we must specify allowable origins, which places a restriction on
cross-origin resource sharing.

If cross origin resource sharing is required, please disable server.enableXsrfProtection.

Usage: streamlit run [OPTIONS] TARGET [ARGS]...

Error: Invalid value: File does not exist: app.py

Is secure to disable XsrfProtection?
There is another way?

Thanks!

1 Like

I finally manage to deploy with a docker image and App. Engine with this DockerFile:

# Create working directory
WORKDIR /app

# Copy requirements. From source, to destination.
COPY requirements.txt ./requirements.txt

# Install dependencies
RUN pip3 install -r requirements.txt

# Expose port
EXPOSE 8080

# copying all files over. From source, to destination.
COPY . /app

#Run app
CMD streamlit run --server.port 8080 --server.enableCORS false app.py

Check this video from Jesse E. Agbe

2 Likes

My Google App Engine deployed Streamlit app is failing, due to /healthz endpoint being a reserved url route within App Engine.
(https://stackoverflow.com/questions/64237850/healthz-route-of-an-app-deployed-on-google-app-engine-returns-404)

None of the suggestions above by the others have worked for me.

Does this mean Google App Engine ( same issue occurs with Google Cloud Run as well) is not an option for deploying Streamlit Apps?
Or… is there a way to override the health endpoint name used by Streamlit ?

1 Like

I have managed to get around the healthz conflict in a rather nasty way. I also enabled session_affinity to help with websocket connections.

here is my app.yaml, ill explain the healthz fix below:

runtime: python
env: flex
# This is a horrible workaround to get streamlit working on app engine
# https://discuss.streamlit.io/t/has-anyone-deployed-to-google-cloud-platform/931/20
entrypoint: find ${VIRTUAL_ENV}/lib/python3.6/site-packages/streamlit -type f \( -iname \*.py -o -iname \*.js \) -print0 | xargs -0 sed -i 's/healthz/health-check/g' && streamlit run sim_v3.py --server.port $PORT --server.enableCORS=false

runtime_config:
  python_version: 3

manual_scaling:
  instances: 1

network:
  session_affinity: true

The hack is happening in the entrypoint command. I am finding all files in the python virtualenv dependencies folder, site-packages, that are either .py or .js and replacing healthz with health-check

If you are intending on supporting a deployed streamlit app, I suggest you avoid this solution. It will break if

  • the version of python changes in the google python runtime
  • streamlit make a change that would break this inline replacement
  • google decide to change their folder naming conventions
3 Likes

Hey Juan.

Thanks for this. Worked for me as well.

I’m getting into another issue and was wondering if I can get some guidance.

So I can do a manual gcloud app deploy, but now I want to do it in CI/CD with Cloud Build. Unfortunately the build runs, but the app does not respond on the weblink.

Here is the repo I am using for this…

Would be great if can get some guidance.

##Streamlit Deployment on Google Cloud Run (Updated July 2021)
Streamlit on GCP Cloud Run

1 Like

thanks! this helped unblock me. For anyone else stumbling onto this thread:

I was able to accomplish App Engine deployment by using a Dockerfile and this app.yaml:

runtime: custom
env: flex

instance_class: F2

network:
  session_affinity: true

Dockerfile:

FROM python:3.9.3
WORKDIR /app
EXPOSE 8080
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
RUN find /usr/local/lib/python3.9/site-packages/streamlit -type f \( -iname \*.py -o -iname \*.js \) -print0 | xargs -0 sed -i 's/healthz/health-check/g'
COPY main.py ./main.py
CMD streamlit run --server.port 8080 --browser.serverAddress 0.0.0.0 --server.enableCORS False --server.enableXsrfProtection False main.py

/healthz was an existing endpoint in streamlit that conflicted with GCP’s internal expectations, so I needed to run the sed one-liner.

Cloud Run seems to work as well, pointed to the image published to the google cloud registry associated with the most recent App Engine build (in the same project), and had it up and running quickly (image didn’t need to be rebuilt).

Digital Ocean Apps deployment worked well (started playing with it while waiting on GCP deployment with the above combo, which was taking much longer once I started using the flex environment with the Dockerfile…). For Digital Ocean, defaults from dockerhub as the app source worked great. I only needed to configure the health check from default TCP to HTTP at /health-check and it worked with the same Dockerfile above.

1 Like

Turns out the fact of streamlit running on websockets complicates autoscaling, so … I suggest you don’t deploy streamlit this way (on elastic beanstalk, cloud run, app engine, etc).

After “request timeout” is reached, or if scaling happens behind the scenes, the client may be routed to a different backend worker, meaning the app resets, state is lost, etc. leading to a bad user experience.

Deploying into a single VM on digital ocean (or the equivalent non-scaled solution on gcp/aws/azure) is the way to share (besides streamlit sharing) but can’t quite handle scaling (except vertical).

Definitely learned the hard way that the proper way to build apps that can scale on these managed platforms is to decouple front/back end. streamlit helped prototype the interface / experience but can’t be what I use to go to production. As far as I can tell, the only way to scale is to go the “binder” route (kubernetes under the hood) and assign a single VM to each user, which can get expensive quickly.

1 Like

Hi @monchier! - I know this is a very old post but right now I think I have the same issue trying to setup an envoy-based proxy for my Streamlit app. Do you mind sharing a little bit about the way you set it up? Specially, I’m using Gloo Edge and haven’t been able to pass through the “Please wait…” screen.
Thanks in advance!

I have created an Article how to deploy a streamlit app successfully on GCP using Cloud Run services:

1 Like

Thanks @CommodoreBeard! Your solution worked for me deploying at Google Cloud Run.

Hello, I’m facing the same issue after deploying my web app in app engine.
I have a time out after 40 to 50 minutes of running the app in a browser! Any updates on this topic ?
Thanks in advance.

Despite all recommendations I couldn’t get it working on AppEngine flex.
Getting same error:
ERROR: (gcloud.app.deploy) Error Response: [4] An internal error occurred while processing task /app-engine-flex/flex_await_healthy/flex_await_healthy>2022-11-29T07:55:05.850Z21335.wa.2: Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the ‘app_start_timeout_sec’ setting in the ‘readiness_check’ section.

I tried this Dockerfile:

FROM python:3.9.3
WORKDIR /app
EXPOSE 8080
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
RUN find /usr/local/lib/python3.9/site-packages/streamlit -type f \( -iname \*.py -o -iname \*.js \) -print0 | xargs -0 sed -i 's/healthz/health-check/g'
COPY main.py ./main.py
CMD streamlit run --server.port 8080 --browser.serverAddress 0.0.0.0 --server.enableCORS False --server.enableXsrfProtection False main.py

also tried std runtime (‘python’)

Hello, @Shrike

Could you please share the app.yaml configuration file?
Is your error related to a timeout after running the app in the browser?

Kind regards.

Hi, we tried different configs but the error was the same all the time, it happens at end of running gcloud app deploy
app.yaml:

runtime: custom
env: flex
instance_class: B2
network:
  session_affinity: true