Skip to content

Commit 0dca644

Browse files
authored
Feat: local Streamlit setup (#90)
2 parents 42f5856 + 4e4d606 commit 0dca644

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1032
-419
lines changed

.devcontainer/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
FROM caltrans/pems:app
22

33
COPY . .
4+
45
# install devcontainer requirements
56
RUN pip install -e .[dev,test]
67

78
# install docs requirements
89
RUN pip install --no-cache-dir -r docs/requirements.txt
10+
11+
# install streamlit requirements
12+
RUN pip install --no-cache-dir -r streamlit_app/requirements.txt

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "caltrans/pems",
33
"dockerComposeFile": ["../compose.yml"],
44
"service": "dev",
5-
"forwardPorts": ["docs:8000", "kibana:5601"],
5+
"forwardPorts": ["docs:8000"],
66
"workspaceFolder": "/caltrans/app",
77
"postStartCommand": ["/bin/bash", "bin/reset_db.sh"],
88
"postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"],

.env.sample

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,7 @@ DJANGO_DB_RESET=true
88
DJANGO_STORAGE_DIR=.
99
DJANGO_DB_FILE=django.db
1010

11-
# uncomment to start the elasticstack services with compose
12-
# COMPOSE_PROFILES=elasticstack
13-
14-
# Version of Elastic products
15-
ELASTIC_STACK_VERSION=8.16.1
16-
17-
# Set to 'basic' or 'trial' to automatically start the 30-day trial
18-
ELASTIC_LICENSE=basic
19-
20-
# SAMPLE Predefined Key only to be used in POC environments
21-
ELASTIC_ENCRYPTION_KEY=c34d38b3a14956121ff2170e5030b471551370178f43e5626eec58b04a30fae2
22-
23-
# Set the cluster name
24-
ELASTIC_CLUSTER=eslocal
25-
26-
# Increase or decrease based on the available host memory (in bytes)
27-
ELASTIC_MEM_LIMIT=2147483648
28-
29-
# Password for the 'elastic' user (at least 6 characters)
30-
ELASTIC_PASSWORD=elastic
31-
32-
# Password for the 'kibana_system' user (at least 6 characters)
33-
KIBANA_PASSWORD=kibana
34-
35-
# Increase or decrease based on the available host memory (in bytes)
36-
KIBANA_MEM_LIMIT=1073741824
11+
# Streamlit
12+
STREAMLIT_LOCAL_PORT=8501
13+
# options: hidden, sidebar
14+
STREAMLIT_NAV=hidden

.github/workflows/tests-pytest.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
cache-dependency-path: "**/pyproject.toml"
3030

3131
- name: Install Python dependencies
32-
run: pip install -e .[test]
32+
run: |
33+
pip install -e .[test]
34+
pip install -r streamlit_app/requirements.txt
3335
3436
- name: Run setup
3537
run: ./bin/init.sh

.streamlit/config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[browser]
2+
gatherUsageStats = false
3+
4+
[theme]
5+
base = "light"

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@
2727
"DJANGO_DEBUG": "false",
2828
"DJANGO_STATICFILES_STORAGE": "django.contrib.staticfiles.storage.StaticFilesStorage"
2929
}
30+
},
31+
{
32+
"name": "Streamlit, yes sidebar",
33+
"type": "debugpy",
34+
"request": "launch",
35+
"module": "streamlit",
36+
"args": ["run", "streamlit_app/main.py"],
37+
"env": {
38+
"PYTHONBUFFERED": "1",
39+
"PYTHONWARNINGS": "default",
40+
"STREAMLIT_NAV": "sidebar"
41+
}
42+
},
43+
{
44+
"name": "Streamlit, no sidebar",
45+
"type": "debugpy",
46+
"request": "launch",
47+
"module": "streamlit",
48+
"args": ["run", "streamlit_app/main.py"],
49+
"env": {
50+
"PYTHONBUFFERED": "1",
51+
"PYTHONWARNINGS": "default",
52+
"STREAMLIT_NAV": "hidden"
53+
}
3054
}
3155
]
3256
}

bin/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -eux
3+
4+
docker compose build app
5+
6+
docker compose build dev
7+
8+
docker compose build streamlit

compose.yml

Lines changed: 7 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -30,190 +30,13 @@ services:
3030
volumes:
3131
- ./:/caltrans/app
3232

33-
esconfig:
34-
profiles: ["elasticstack"]
35-
image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_STACK_VERSION}
36-
user: "0"
37-
command: ["bash", "/.local/config/setup.sh"]
38-
env_file:
39-
- .env
40-
volumes:
41-
- certs:/usr/share/elasticsearch/config/certs
42-
- ./elasticstack/esconfig:/.local/config
43-
healthcheck:
44-
test: ["CMD-SHELL", "[ -f config/certs/es01/es01.crt ]"]
45-
interval: 1s
46-
timeout: 5s
47-
retries: 120
48-
49-
es01:
50-
profiles: ["elasticstack"]
51-
depends_on:
52-
esconfig:
53-
condition: service_healthy
54-
image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_STACK_VERSION}
55-
labels:
56-
co.elastic.logs/module: elasticsearch
57-
volumes:
58-
- certs:/usr/share/elasticsearch/config/certs
59-
- esdata01:/usr/share/elasticsearch/data
60-
ports:
61-
- "9200"
62-
environment:
63-
- node.name=es01
64-
- cluster.name=${ELASTIC_CLUSTER}
65-
- discovery.type=single-node
66-
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
67-
- bootstrap.memory_lock=true
68-
- xpack.security.enabled=true
69-
- xpack.security.http.ssl.enabled=true
70-
- xpack.security.http.ssl.key=certs/es01/es01.key
71-
- xpack.security.http.ssl.certificate=certs/es01/es01.crt
72-
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
73-
- xpack.security.transport.ssl.enabled=true
74-
- xpack.security.transport.ssl.key=certs/es01/es01.key
75-
- xpack.security.transport.ssl.certificate=certs/es01/es01.crt
76-
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
77-
- xpack.security.transport.ssl.verification_mode=certificate
78-
- xpack.license.self_generated.type=${ELASTIC_LICENSE}
79-
mem_limit: ${ELASTIC_MEM_LIMIT}
80-
ulimits:
81-
memlock:
82-
soft: -1
83-
hard: -1
84-
healthcheck:
85-
test:
86-
[
87-
"CMD-SHELL",
88-
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
89-
]
90-
interval: 10s
91-
timeout: 10s
92-
retries: 120
93-
94-
kibana:
95-
profiles: ["elasticstack"]
96-
depends_on:
97-
es01:
98-
condition: service_healthy
99-
image: docker.elastic.co/kibana/kibana:${ELASTIC_STACK_VERSION}
100-
labels:
101-
co.elastic.logs/module: kibana
102-
volumes:
103-
- certs:/usr/share/kibana/config/certs
104-
- kibanadata:/usr/share/kibana/data
105-
- ./elasticstack/kibana:/usr/share/kibana/config
106-
ports:
107-
- "5601"
108-
environment:
109-
- SERVERNAME=kibana
110-
- ELASTICSEARCH_HOSTS=https://es01:9200
111-
- ELASTICSEARCH_USERNAME=kibana_system
112-
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
113-
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt
114-
- XPACK_SECURITY_ENCRYPTIONKEY=${ELASTIC_ENCRYPTION_KEY}
115-
- XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=${ELASTIC_ENCRYPTION_KEY}
116-
- XPACK_REPORTING_ENCRYPTIONKEY=${ELASTIC_ENCRYPTION_KEY}
117-
mem_limit: ${KIBANA_MEM_LIMIT}
118-
healthcheck:
119-
test:
120-
[
121-
"CMD-SHELL",
122-
"curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
123-
]
124-
interval: 10s
125-
timeout: 10s
126-
retries: 120
127-
128-
metricbeat01:
129-
profiles: ["elasticstack"]
130-
depends_on:
131-
es01:
132-
condition: service_healthy
133-
kibana:
134-
condition: service_healthy
135-
image: caltrans/pems:metricbeat01
136-
build:
137-
context: .
138-
dockerfile: ./elasticstack/metricbeat01/Dockerfile
139-
args:
140-
- ELASTIC_STACK_VERSION=${ELASTIC_STACK_VERSION}
141-
volumes:
142-
- certs:/usr/share/metricbeat/certs
143-
- metricbeatdata01:/usr/share/metricbeat/data
144-
- "/var/run/docker.sock:/var/run/docker.sock:ro"
145-
- "/sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro"
146-
- "/proc:/hostfs/proc:ro"
147-
- "/:/hostfs:ro"
148-
environment:
149-
- ELASTIC_USER=elastic
150-
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
151-
- ELASTIC_HOSTS=https://es01:9200
152-
- KIBANA_HOSTS=http://kibana:5601
153-
- LOGSTASH_HOSTS=http://logstash01:9600
154-
command:
155-
- --strict.perms=false
156-
157-
filebeat01:
158-
profiles: ["elasticstack"]
159-
depends_on:
160-
es01:
161-
condition: service_healthy
162-
image: caltrans/pems:filebeat01
163-
build:
164-
context: .
165-
dockerfile: ./elasticstack/filebeat01/Dockerfile
166-
args:
167-
- ELASTIC_STACK_VERSION=${ELASTIC_STACK_VERSION}
168-
volumes:
169-
- certs:/usr/share/filebeat/certs
170-
- filebeatdata01:/usr/share/filebeat/data
171-
- "/var/lib/docker/containers:/var/lib/docker/containers:ro"
172-
- "/var/run/docker.sock:/var/run/docker.sock:ro"
173-
environment:
174-
- ELASTIC_USER=elastic
175-
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
176-
- ELASTIC_HOSTS=https://es01:9200
177-
- KIBANA_HOSTS=http://kibana:5601
178-
- LOGSTASH_HOSTS=http://logstash01:9600
179-
command:
180-
- --strict.perms=false
181-
182-
logstash01:
183-
profiles: ["elasticstack"]
184-
depends_on:
185-
es01:
186-
condition: service_healthy
187-
kibana:
188-
condition: service_healthy
189-
image: caltrans/pems:logstash01
33+
streamlit:
19034
build:
19135
context: .
192-
dockerfile: ./elasticstack/logstash01/Dockerfile
193-
args:
194-
- ELASTIC_STACK_VERSION=${ELASTIC_STACK_VERSION}
195-
labels:
196-
co.elastic.logs/module: logstash
36+
dockerfile: streamlit_app/Dockerfile
37+
image: caltrans/pems:streamlit
38+
env_file: .env
39+
ports:
40+
- "${STREAMLIT_LOCAL_PORT:-8501}:8501"
19741
volumes:
198-
- certs:/usr/share/logstash/certs
199-
- logstashdata01:/usr/share/logstash/data
200-
- ./elasticstack/logstash01:/tmp/logstash01
201-
environment:
202-
- xpack.monitoring.enabled=false
203-
- ELASTIC_USER=elastic
204-
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
205-
- ELASTIC_HOSTS=https://es01:9200
206-
207-
volumes:
208-
certs:
209-
driver: local
210-
esdata01:
211-
driver: local
212-
kibanadata:
213-
driver: local
214-
metricbeatdata01:
215-
driver: local
216-
filebeatdata01:
217-
driver: local
218-
logstashdata01:
219-
driver: local
42+
- ./:/caltrans/app

elasticstack/esconfig/instances.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

elasticstack/esconfig/setup.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

elasticstack/filebeat01/Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)