Deploying Streamlit app on Google Cloud Run
# Prerequisites
- A Google Cloud account
gcloud
CLI installed on local system.Docker
installed on local system.Streamlit
application to be deployed
# Dockerizing the Streamlit App
Google Cloud Run runs containerised applications. To prepare Streamlit app for deployment, we will need to create a Docker container. Following are the steps:
- Create a
Dockerfile
: Crafting aDockerfile
that specifies the environment and dependencies required for the Streamlit app.
|
|
- Building the docker image: Using the docker command line tools, we can build the Docker image of Streamlit app.
|
|
- Testing the docker container: We can run the docker container locally to ensure that our Streamlit app works as expected within the containerised environment.
|
|
# Setup Google Cloud Run
- Open Google Cloud Console: Access the Google Cloud Console using the GCP account.
- Enable the Cloud Run API: If you haven’t already, enable the Cloud Run API for the GCP account.
- Deploy using Cloud Console: Following the Cloud Run Interface to deploy the dockerised streamlit app. We can also set environment variables and CPU limitations.
|
|
# Deploying the app
- Search for
Container Registry
and then you would be able to see the recent container image deployed.
2. Click
Deploy
and select Deploy to Cloud Run
to deploy the app.
3. The app deployment will start and take some time to finish
# Testing and Monitoring the App Deployment
After deploying the app, we can test and monitor its usage:
- Access the deployed app: Once, the deployment is complete, we receive a URL where the Streamlit app is accessible.
- Monitoring and Troubleshooting: Using the Google Cloud Console, we can monitor the app. This includes checking logs, monitoring usage, and identifying any issues that might arise.
# CI/CD
For effecient app updates, we can implement CD:
- Setting up source control: We can link our Github code repository to Google Cloud Build for automated deployments
- Configure Triggers: We can configure triggers to build and deploy our app whenever changes are pushed to the repository