Skip to content

Feat: improve proof-of-concept app #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Feat: improve proof-of-concept app #116

wants to merge 8 commits into from

Conversation

lalver1
Copy link
Member

@lalver1 lalver1 commented May 30, 2025

WIP

Adds the stations app to the repo (before it was only a local branch) and wires up django and streamlit in an environment-dependent way so that the proof-of-concept districts app can run both locally and in the Cloud.

Currently this branch is on top of ci/cloud-infra but it will be rebased on main once PR #111 is merged.

Notes

Originally, the streamlit service was defined as a copilot Backend Service. For an initial proof-of-concept this is not a convenient service type since the service is unreachable from the internet (recall that the web service embeds streamlit in an iframe, so streamlit needs to be reachable from the internet). For this PR, we will change streamlit to a Load Balanced Web Service. As we get closer to production, the architecture will likely change to:

  • Configure web to act as a reverse proxy
    • streamlit-related iframes in web will point to a path in web but this path will be set up in the ngingx configuration to forward any requests to streamlit over the private network
  • Place streamlit in a private network (back to Backend Service) and configure it to deny all incoming traffic except for requests from the private IP address of web.

@lalver1 lalver1 self-assigned this May 30, 2025
Copy link

github-actions bot commented May 30, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pems
  settings.py
  pems/core
  context_processors.py
  streamlit_app
  main.py
Project Total  

This report was generated by python-coverage-comment-action

@lalver1 lalver1 force-pushed the feat/app-stations branch from b32158d to 31a45b5 Compare June 4, 2025 21:47
@lalver1 lalver1 force-pushed the feat/app-stations branch 4 times, most recently from 271fa52 to 394f3da Compare June 12, 2025 20:27
<h2>Map</h2>
<div class="row" style="min-height: 450px;">
<div class="col-lg-12 border">
<iframe class="streamlit-app" src="{{ streamlit_host }}/stations--stations?embed=true&district_number={{ current_district.number }}">
Copy link
Member Author

@lalver1 lalver1 Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename class to streamlit-service
Realized that the custom streamlit-app class was not necessary since it can be replaced by Bootstrap's w-100 h-100.

def streamlit_host(request):
"""Context processor to add the Streamlit host URL part to the context."""

return {"streamlit_host": settings.STREAMLIT_HOST}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider top-level streamlit context

pems/settings.py Outdated

# Streamlit settings
STREAMLIT_LOCAL_PORT = os.environ.get("STREAMLIT_LOCAL_PORT", "")
STREAMLIT_HOST = os.environ.get("STREAMLIT_HOST", f"http://localhost:{STREAMLIT_LOCAL_PORT}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collapse these 2 variables to 1

@@ -10,3 +10,8 @@ header {
}
}
}

.streamlit-app {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a class in Bootstrap already that already sets these 2 properties? if so, use that one

@@ -35,6 +35,8 @@ EXPOSE 8501

COPY streamlit_app streamlit_app

COPY .streamlit .streamlit
Copy link
Member Author

@lalver1 lalver1 Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to before COPY streamlit_app streamlit_app to take advantage of layer caching

lalver1 added 7 commits June 13, 2025 19:09
the District Stations Streamlit app is a simple proof-of-concept
that displays the traffic data collection stations in a district.
the django and streamlit apps are now wired up in a way that works
both for a local dev environment as well as a Cloud deployment.
since the web and streamlit services run on the same load balancer
in AWS, the http path defined in the manifest of each service must
be different from each other. the http path of the streamlit service
(streamlit_service) is also passed to the streamlit run command in
the entrypoint.sh script. also, the healthcheck path must be
defined in the manifest so that the service does not
continually restart.
this setup was causing an error when deploying to AWS since the Django
pems app resides in a different container. when running a local
debugger though, this error was not present since the local dev
container does have the pems app. since at this moment we are not
using Django models in the streamlit app, we are removing this ability.
copy the .streamlit directory into the streamlit service's image
so that the streamlit configuration is available to the container.
before, the configuration was only available to the local dev
container.
@lalver1 lalver1 force-pushed the feat/app-stations branch from d2549eb to 56f7ed2 Compare June 16, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant