Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ RUN pdm sync --prod --no-editable
EXPOSE 8000

RUN touch /first_run
# run alembic here because we are not forwarding the DB
# no start.sh script because need to disable websocket timeouts
ENTRYPOINT ["/bin/sh", "-c", "if [ -f /first_run ]; then pdm run alembic upgrade head; rm /first_run; fi; exec pdm run app"]
39 changes: 0 additions & 39 deletions create.sh

This file was deleted.

4 changes: 4 additions & 0 deletions deploy_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docker-compose stop api
docker-compose rm -f api
docker rmi masterbase-api --force
docker-compose up -d api
69 changes: 69 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: '3.8'

services:
db:
build:
context: .
dockerfile: Dockerfile.db
container_name: db
environment:
POSTGRES_USER: MEGASCATTERBOMB
POSTGRES_PASSWORD: masterbase
POSTGRES_DB: demos
networks:
masterbase-network-dev:
ipv4_address: 172.20.1.10
ports:
- "8050:5432"

api:
build:
context: .
dockerfile: Dockerfile.api
args:
DEVELOPMENT: ${DEVELOPMENT}
container_name: api
environment:
STEAM_API_KEY: ${STEAM_API_KEY}
POSTGRES_USER: MEGASCATTERBOMB
POSTGRES_PASSWORD: masterbase
POSTGRES_HOST: 172.20.1.10
POSTGRES_PORT: 5432
networks:
masterbase-network-dev:
ipv4_address: 172.20.1.20
ports:
- "8000:8000"

prometheus:
image: prom/prometheus:latest
container_name: prometheus
volumes:
- ./prometheus.yaml:/etc/prometheus/prometheus.yaml
command:
- '--config.file=/etc/prometheus/prometheus.yaml'
networks:
masterbase-network-dev:
ipv4_address: 172.20.1.30
ports:
- "9090:9090"

grafana:
image: grafana/grafana:latest
container_name: grafana
depends_on:
- prometheus
networks:
masterbase-network-dev:
ipv4_address: 172.20.1.40
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin

networks:
masterbase-network-dev:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
4 changes: 4 additions & 0 deletions masterbase/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import requests
import uvicorn
from litestar import Litestar, MediaType, Request, WebSocket, get, post
from litestar.contrib.prometheus import PrometheusConfig, PrometheusController
from litestar.exceptions import HTTPException, PermissionDeniedException
from litestar.handlers import WebsocketListener
from litestar.response import Redirect, Stream
Expand Down Expand Up @@ -362,10 +363,12 @@ def provision_handler(request: Request) -> str:
</html>
"""

prometheus_config = PrometheusConfig()

app = Litestar(
on_startup=startup_registers,
route_handlers=[
PrometheusController,
session_id,
close_session,
DemoHandler,
Expand All @@ -377,6 +380,7 @@ def provision_handler(request: Request) -> str:
analyst_list_demos,
report_player,
],
middleware=[prometheus_config.middleware],
on_shutdown=shutdown_registers,
opt={"DEVELOPMENT": bool(os.getenv("DEVELOPMENT"))},
)
Expand Down
8 changes: 8 additions & 0 deletions prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global:
scrape_interval: 15s

scrape_configs:
- job_name: 'api'
metrics_path: '/metrics'
static_configs:
- targets: ['localhost:8000']
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ dependencies = [
"toml>=0.10.2",
"requests>=2.31.0",
"pydantic>=2.5.3",
"litestar[standard]>=2.8.3",
"litestar[standard,prometheus]>=2.8.3",
"alembic>=1.13.1",
"psycopg2-binary>=2.9.9",
"asyncpg>=0.29.0",
"greenlet>=3.0.3",
"uvicorn>=0.27.1",
"numpy>=1.26.4",
"prometheus-client>=0.20.0",
]
requires-python = ">=3.11,<3.13"
readme = "README.md"
Expand Down