Has anyone deployed to Google Cloud Platform?

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

Hi all, I am trying to deploy to GCP App Engine. Currently I deployed to Streamlitā€™s Community Cloud and it handles secrets easily by adding to the config. Should I change st.secrets references in my code to use managed secret service like GCP Secrets Manager for the GCP deployment? Thank you!