I needed to create a quick proof of concept (PoC) using Streamlit but had two constraints:
- Self-host instead of using Streamlit community cloud
- Control access to the deployed website
With this in mind, containerizing and hosting on Azure was the solution. This repository provides a boilerplate to fast-track this with the following implementations:
- Containerized Streamlit app with a blank
app.py
file (just add your code). - GitHub workflow to build and publish the image to
ghcr.io
. - Terraform code to manage infrastructure on Azure.
- GitHub workflow to execute Terraform apply & destroy infrastructure.
I hope this helps you to ship more 🚀
Streamlit is an open-source Python library that makes it easy to create interactive web applications for machine learning and data science projects.
Description | Cost (Per month) |
---|---|
B1 ($0.075/hour) tier for Azure App Service costing | $54.79 |
Standard tier with LRS for Azure Storage Account costing (10K+ operations cost excluded as minimal usage) | $0.0184 |
GitHub Workflows (if private repo, check pricing) | $0 |
Total | $54.81 |
Disclaimer: Estimation only. Pricing might change; please refer to the official documentation at the time of evaluation.
- Hosting: Azure App Service.
- Deployment: GitHub Actions
- Interactive web-based frontend.
- Python-based backend.
- GitHub Container Registry to store the image.
This project requires an Azure subscription to run, Get started
-
Create a repository from this template repo.
-
Open a shell and run
azure login
-
Update the subject field within your repository naming in infra/scripts/credential.json
-
Execute infra/scripts/initialize.sh and capture output fields
-
Setting up the environment:
- Navigate to your repository on GitHub.
- Go to “Settings” > “Environments”.
- Create a new environment 'production'
-
Adding Secrets:
- Navigate to your repository on GitHub.
- Go to “Settings” > “Environments” > Select “production”.
- Go to "Environment secrets" and select "Add environment secret"
- Add the following secrets using the output of step 4: AZURE_ENTRA_ID_CLIENT_ID, AZURE_ENTRA_ID_TENANT_ID & AZURE_SUBSCRIPTION_ID
To begin, make sure you have the Dev containers extension installed and have Docker running. Check out Devcontainers for context.
- Clone this repo and open it in Visual Studio Code.
- You should see this notification pop up:
Select _Reopen in Container_ and the devcontainer will be loaded.
This will prepare your dev environment with the required tooling.
This will open this repo in Visual Studio Code using a link. Press below:
This project is licensed under the MIT License - see the LICENSE file for details.