A streamlit application designed for interacting with probabilistic flood hazards modeling data
The development container provides a consistent environment for Stormlit development with Python (via Micromamba), Node.js, AWS CLI, CDKTF, PgStac API, and PostgreSQL.
-
Install Docker Desktop:
- Windows/Mac: Download from Docker Desktop
- Linux: Follow Docker Engine installation
-
Install VS Code:
- Download from Visual Studio Code
-
Install VS Code Extensions:
- Open VS Code
- Press Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (Mac)
- Search and install "Dev Containers"
- Clone the repository:
git clone https://github.com/fema-ffrd/stormlit
cd stormlit
If not using dev containers, skip to Docker Compose Setup below. 2. Open in VS Code:
code .
- Start Dev Container:
- Press F1 or Ctrl+Shift+P
- Type "Dev Containers: Open Folder in Container"
- Select your project folder
- Wait for container build (~5-10 minutes first time)
Continue to Verify Services.
- Build Docker images for the environment.
docker compose build
- Start the application and services.
docker compose up
-
Verify services:
- Open browser: http://localhost:8080 (PgStac API)
- Open browser: http://localhost:55050 (pgAdmin)
- Login: [email protected]/admin
- Add server:
- Right click "Servers" → "Register" → "Server"
- Name: "Stormlit DB"
- Connection tab:
- Host: stormlit-pgstac
- Port: 5432
- Database: postgis
- Username: postgres
- Password: password
-
Start developing:
- Code is synced between your machine and container
- Python environment is pre-configured
- Terminal in VS Code uses the container environment
If encountering SSL errors while building the dev container environment, check if you are on a corporate VPN which does man-in-the-middle SSL inspection with certificate replacement (e.g., Zscaler). Programs running within the dev container need to "trust" the Root Certificate Authority of your VPN.
Obtain the Root CA in PEM
format, put it in a text
file with the extension .crt
, and place it in the
./devcontainer/
folder. Then, rebuild the dev
container environment. This will allow the dev container
to build without SSL errors.
Additonal configuration may be necessary to allow the
Stormlit app container to connect to online resources
without SSL errors. First, create a CA bundle by
concatenating the Root CA with, e.g., the Mozilla
certificate bundle distributed with the Python certifi
library,
and name it with a .crt
extension. Then, modify
your ./app/.env
file with environment variables
to ensure that Stormlit uses the Root CA:
REQUESTS_CA_BUNDLE=/workspace/.devcontainer/zscaler-certifi-ca-bundle.crt
SSL_CERT_FILE=/workspace/.devcontainer/zscaler-certifi-ca-bundle.crt
- Base image:
mcr.microsoft.com/devcontainers/base:jammy
- Python environment managed by Micromamba
- Node.js LTS
- AWS CLI
- CDKTF v0.20.10
- Container:
stormlit-stac-api
- URL: http://localhost:8080
- Backed by PostgreSQL with PostGIS extension and PgStac Schema
- Container:
stormlit-pgstac
- Port: 55432
- Database: postgis
- Credentials: postgres/password
- Volume: stormlit-pgstac-data
- Container:
stormlit-pgadmin
- URL: http://localhost:55050
- Login: [email protected]/admin
- Python path:
/opt/conda/envs/stormlit/bin/python
- Workspace mounted at:
/workspace
- Environment file:
/workspace/env.yml
- Python
- Ruff
- GitHub Copilot
The container automatically:
- Sets workspace ownership to vscode user
- Initializes Micromamba shell
- Activates stormlit environment
- Configures Git safe directory
All services are connected via stormlit-network
for internal communication.
- PostgreSQL data:
stormlit-pgstac-data
volume - Project files: Mounted from host at
/workspace
# In VS Code terminal
streamlit run app/main.py
Access at http://localhost:8501
- Copy the template:
cd app
cp .env.template .env
- Update
.env
with development values:
The .env.template
file in the project root contains all required environment variables with descriptions.
# In VS Code terminal
cd app
# Linting
ruff check
# Testing
pytest
# Formatting
ruff format
Stormlit uses GitHub Actions for continuous integration and deployment, with separate workflows for pull requests, development, and production environments.
When a pull request is opened against the main
or dev
branches, the following checks run automatically:
- Unit tests for both the Streamlit application and infrastructure code
- CDKTF synthesis to validate infrastructure changes
- Docker image build verification (without registry push)
- Code formatting and linting with Ruff
All checks must pass before the PR can be merged.
Pushes to the dev
branch trigger:
- Complete test suite execution
- CDKTF infrastructure synthesis
- Docker image build and push to GitHub Container Registry with the
dev
tag - Deployment to the development environment via CDKTF
Pushes to the main
branch trigger:
- Complete test suite execution
- CDKTF infrastructure synthesis
- Docker image build and push to GitHub Container Registry with the
latest
tag - Deployment to the production environment via CDKTF
The CI/CD pipeline uses the following environment variables:
AWS_REGION
: Set to us-east-1 for all deploymentsTF_VAR_stormlit_tag
: Docker image tag for stormlit image (latest
ordev
)
The CI/CD pipeline maintains the correct deployment order for infrastructure components:
- Network infrastructure
- Database resources
- Application deployment
There are no secrets or environment variables stored in the repository. Authentication with AWS is performed using OpenID Connect.
The IaC for this repository is inside the iac/
directory. This projects used the CDK for terraform with Python.
cd iac
pipenv install -d
The cdktf
command is available in the devcontainer. Once provider bindings have been installed, activate the pipenv inside the iac
directory:
pipenv shell
In order for VSCode to properly run intellisense on this code, you must change your python interpreter to this environment. To change your Python interpreter:
- Press
Ctrl+Shift+P
to open the command palette. - Type "Python: Select Interpreter" and select it.
- VSCode will then display a list of available Python interpreters. Look for the one that corresponds to the virtual environment. It should be located within the virtual environment directory.
- Select the interpreter associated with your virtual environment.
If you need to manually specify the interpreter path, you can get the correct path by running the which python
command with the pipenv environment activated.
There is only a single environment defined. This is the test environment deployed in the PTS's shared AWS account in commercial cloud. The infrastructure is deploy with the following command from the iac
directory (only in CI/CD):
cdktf deploy <stack names>
There are currently 3 stacks defined in the main.py
file:
stormlit-<environment>-network
: The base network infrastructure for the environment. This includes the VPC, subnets, internet gateway, NAT gateway, elastic IPs, and security groups.stormlit-<environment>-database
: The database infrastructure for the environment. This includes the RDS instance and secrets manager for the database credentials.stormlit-<environment>-application
: The application infrastructure for the environment. This includes the ECS cluster, IAM Roles, task definitions, services, and load balancer.
To deploy this infrastructure, you must deploy the stacks in the following order:
-
stormlit-<environment>-network
-
stormlit-<environment>-database
-
After deploying the database stack, you must manually run the migration script to initialize the database. This can be done by running the following command:
./migration/migrate.sh
Note that this script must be run from within the VPC that the database is deployed in. This can be done by SSHing into the bastion host.
Note that you will need to modify this script to include the correct database endpoint, username, password, etc. Uncomment the commented out lines and replace the values with the correct values.
-
-
stormlit-<environment>-application
You can also test a deployment with synth
during development:
cdktf synth
And destroy the environment with destroy
:
cdktf destroy <stack names>
# In VS Code terminal
cd iac
# Linting
ruff check
# Testing
pytest main-test.py
# Formatting
ruff format
The following diagram shows the architecture of the Stormlit application as deployed in the development environment. Note that production deployments will have different configurations (DNS, WAF, etc.).