Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you deploy a Streamlit app on App Engine (GCP)?

I am aiming to deploy a simple web-app written with Sreamlit, e.g.

app.py

import streamlit as st
st.title('Hello World!')

I can run this on my local machine by running streamlit run app.py in my command line.

However, I'm not sure how to modify the app.yaml file in GCP's App Engine to deploy this.

Any advice?

like image 234
Myccha Avatar asked Jan 01 '23 11:01

Myccha


1 Answers

You can use App Engine flexible environment for that as you can specify a custom runtime. The steps to follow will be:

  1. Create the Dockerfile:

    FROM python:3.7
    EXPOSE 8080
    WORKDIR /app
    COPY requirements.txt ./requirements.txt
    RUN pip3 install -r requirements.txt
    COPY . .
    CMD streamlit run app.py --server.port 8080
    

    I have updated the Dockerfile as App Engine flex requires that the server listens on port 8080.

  2. Create the requirements.txt file with the needed dependencies:

    streamlit
    
  3. Create the app.yaml file:

    runtime: custom
    env: flex
    

    Both the app.yaml and the Dockerfile must be in the same folder. The above app.yaml settings are very basic, more information can be found in the documentation.

Then to deploy you need to use the following gcloud command:gcloud app deploy

like image 57
bhito Avatar answered Jan 13 '23 13:01

bhito