-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3795b3b
commit ccb4f50
Showing
19 changed files
with
199 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
repos: | ||
- repo: https://github.com/ambv/black | ||
rev: 23.9.1 | ||
hooks: | ||
- id: black | ||
language_version: python3 | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.0.289 | ||
rev: v0.7.4 | ||
hooks: | ||
- id: ruff | ||
args: [--fix] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#--- BEGIN Usual Python stuff --- | ||
|
||
FROM ghcr.io/valhalla/valhalla:latest as builder | ||
LABEL [email protected] | ||
FROM ghcr.io/valhalla/valhalla:latest AS builder | ||
LABEL maintainer="Nils Nolde <[email protected]>" | ||
|
||
WORKDIR /app | ||
|
||
|
@@ -15,7 +15,7 @@ RUN apt-get update -y > /dev/null && \ | |
python3-venv \ | ||
curl > /dev/null | ||
|
||
ENV POETRY_BIN /root/.local/bin/poetry | ||
ENV POETRY_BIN=/root/.local/bin/poetry | ||
|
||
RUN curl -sSL https://install.python-poetry.org | python && \ | ||
$POETRY_BIN config virtualenvs.create false && \ | ||
|
@@ -46,8 +46,8 @@ RUN cd /usr/local/bin && \ | |
for f in valhalla*; do rm $f; done && \ | ||
cd .. && mv $preserve ./bin | ||
|
||
FROM ubuntu:24.04 as runner_base | ||
MAINTAINER Nils Nolde <[email protected]> | ||
FROM ubuntu:24.04 AS runner_base | ||
LABEL maintainer="Nils Nolde <[email protected]>" | ||
|
||
# install Valhalla stuff | ||
RUN apt-get update > /dev/null && \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from routing_packager_app.logger import LOGGING_CONFIG | ||
|
||
bind = "0.0.0.0:5000" | ||
workers = 1 | ||
worker_class = "uvicorn.workers.UvicornWorker" | ||
logconfig_dict = LOGGING_CONFIG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from fastapi import APIRouter | ||
|
||
from .routes import users, jobs | ||
from .routes import jobs, logs, users | ||
|
||
api_v1_router = APIRouter() | ||
api_v1_router.include_router(jobs.router, prefix="/jobs", tags=["jobs"]) | ||
api_v1_router.include_router(users.router, prefix="/users", tags=["users"]) | ||
api_v1_router.include_router(logs.router, prefix="/logs", tags=["logs"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from fastapi.responses import PlainTextResponse | ||
from fastapi.security import HTTPBasicCredentials | ||
from sqlmodel import Session | ||
from starlette.status import ( | ||
HTTP_400_BAD_REQUEST, | ||
HTTP_401_UNAUTHORIZED, | ||
) | ||
|
||
from ...auth.basic_auth import BasicAuth | ||
from ...config import SETTINGS | ||
from ...db import get_db | ||
from ..models import LogType, User | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/{log_type}", response_class=PlainTextResponse) | ||
def get_logs( | ||
log_type: LogType, | ||
lines: int | None = None, | ||
db: Session = Depends(get_db), | ||
auth: HTTPBasicCredentials = Depends(BasicAuth), | ||
): | ||
# first authenticate | ||
req_user = User.get_user(db, auth) | ||
if not req_user: | ||
raise HTTPException(HTTP_401_UNAUTHORIZED, "Not authorized to read logs.") | ||
|
||
# figure out the type of logs | ||
log_file = SETTINGS.get_logging_dir() / f"{log_type.value}.log" | ||
|
||
try: | ||
with open(log_file) as fh: | ||
if lines is None: | ||
return fh.read() | ||
line_count = len([1 for _ in fh.readlines()]) | ||
start_i = line_count - lines if line_count > lines else 0 | ||
response = "" | ||
fh.seek(0) | ||
for i, line in enumerate(fh.readlines()): | ||
if i < start_i: | ||
continue | ||
response += line | ||
return response | ||
|
||
except: # noqa | ||
return HTTP_400_BAD_REQUEST(f"Unable to open {log_file}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ class BaseSettings(_BaseSettings): | |
|
||
DESCRIPTION_PATH: Path = BASE_DIR.joinpath("DESCRIPTION.md") | ||
|
||
### APP ### | ||
# APP ### | ||
ADMIN_EMAIL: str = "[email protected]" | ||
ADMIN_PASS: str = "admin" | ||
# TODO: clarify if there's a need to restrict origins | ||
|
@@ -30,15 +30,15 @@ class BaseSettings(_BaseSettings): | |
|
||
ENABLED_PROVIDERS: list[str] = list(CommaSeparatedStrings("osm")) | ||
|
||
### DATABASES ### | ||
# DATABASES ### | ||
POSTGRES_HOST: str = "localhost" | ||
POSTGRES_PORT: int = 5432 | ||
POSTGRES_DB: str = "gis" | ||
POSTGRES_USER: str = "admin" | ||
POSTGRES_PASS: str = "admin" | ||
REDIS_URL: str = "redis://localhost" | ||
|
||
### SMTP ### | ||
# SMTP ### | ||
SMTP_HOST: str = "localhost" | ||
SMTP_PORT: int = 1025 | ||
SMTP_FROM: str = "[email protected]" | ||
|
@@ -79,6 +79,19 @@ def get_tmp_data_dir(self) -> Path: | |
|
||
return tmp_data_dir | ||
|
||
def get_logging_dir(self) -> Path: | ||
""" | ||
Gets the path where logs are stored for both worker and builder/app | ||
""" | ||
tmp_data_dir = self.TMP_DATA_DIR | ||
if os.path.isdir("/app") and not os.getenv("CI", None): # pragma: no cover | ||
tmp_data_dir = Path("/app/tmp_data") | ||
log_dir = tmp_data_dir / "logs" | ||
|
||
log_dir.mkdir(exist_ok=True) | ||
|
||
return log_dir | ||
|
||
|
||
class ProdSettings(BaseSettings): | ||
model_config = SettingsConfigDict(case_sensitive=True, env_file=ENV_FILE, extra="ignore") | ||
|
@@ -108,7 +121,6 @@ class TestSettings(BaseSettings): | |
|
||
# decide which settings we'll use | ||
SETTINGS: Optional[BaseSettings] = None | ||
print("LOADING SETTINGS") | ||
env = os.getenv("API_CONFIG", "prod") | ||
if env == "prod": # pragma: no cover | ||
SETTINGS = ProdSettings() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.