diff --git a/asu/config.py b/asu/config.py index 0e1a6eb9..35b7b5ca 100644 --- a/asu/config.py +++ b/asu/config.py @@ -55,7 +55,6 @@ class Settings(BaseSettings): model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8") public_path: Path = Path.cwd() / "public" - json_path: Path = public_path / "json" / "v1" redis_url: str = "redis://localhost:6379" upstream_url: str = "https://downloads.openwrt.org" allow_defaults: bool = False diff --git a/asu/main.py b/asu/main.py index 1b012a5f..ecba45e0 100644 --- a/asu/main.py +++ b/asu/main.py @@ -30,7 +30,6 @@ app = FastAPI() app.include_router(api.router, prefix="/api/v1") -(settings.public_path / "json").mkdir(parents=True, exist_ok=True) (settings.public_path / "store").mkdir(parents=True, exist_ok=True) app.mount("/store", StaticFiles(directory=settings.public_path / "store"), name="store") @@ -167,13 +166,6 @@ def json_v1_overview(): return overview -app.mount( - "/json", - StaticFiles(directory=settings.public_path / "json"), - name="json", -) - - @app.get("//{path:path}") def api_double_slash(path: str): print(f"Redirecting double slash to single slash: {path}") diff --git a/asu/util.py b/asu/util.py index 527a562c..4a96dcf7 100644 --- a/asu/util.py +++ b/asu/util.py @@ -13,6 +13,7 @@ import hishel import nacl.signing +from fastapi import FastAPI from httpx import Response from podman import PodmanClient from podman.domain.containers import Container @@ -423,7 +424,7 @@ def parse_kernel_version(url: str) -> str: return "" -def reload_versions(app): +def reload_versions(app: FastAPI) -> bool: response = client_get(settings.upstream_url + "/.versions.json") if response.extensions["from_cache"] and app.versions: @@ -449,7 +450,7 @@ def reload_versions(app): return True -def reload_targets(app, version: str): +def reload_targets(app: FastAPI, version: str) -> bool: branch_data = get_branch(version) version_path = branch_data["path"].format(version=version) response = client_get(settings.upstream_url + f"/{version_path}/.targets.json") @@ -462,7 +463,7 @@ def reload_targets(app, version: str): return True -def reload_profiles(app, version: str, target: str): +def reload_profiles(app: FastAPI, version: str, target: str) -> bool: branch_data = get_branch(version) version_path = branch_data["path"].format(version=version) response = client_get( diff --git a/misc/asu.env b/misc/asu.env new file mode 100644 index 00000000..00299577 --- /dev/null +++ b/misc/asu.env @@ -0,0 +1,7 @@ +ALLOW_DEFAULTS=1 +CONTAINER_HOST=unix:///run/user/1000/podman/podman.sock +CONTAINER_SOCK=/run/user/1000/podman/podman.sock +PUBLIC_PATH=/home/openwrt/public/ +REDIS_URL=redis://redis/ +SERVER_STATS=stats +SQUID_CACHE=1 diff --git a/misc/snippet.conf b/misc/snippet.conf deleted file mode 100644 index 83195271..00000000 --- a/misc/snippet.conf +++ /dev/null @@ -1,7 +0,0 @@ -maximum_object_size 6 GB -cache_dir ufs /var/spool/squid 30720 16 256 -cache_mem 256 MB -maximum_object_size_in_memory 512 KB -cache_replacement_policy heap LFUDA -range_offset_limit -1 -quick_abort_min -1 KB \ No newline at end of file diff --git a/misc/squid.conf b/misc/squid.conf index f48fb6db..e046938d 100644 --- a/misc/squid.conf +++ b/misc/squid.conf @@ -1,10 +1,7 @@ -include /etc/squid/conf.d/* -http_access allow localhost -http_access deny all -http_port 3128 -coredump_dir /var/spool/squid -refresh_pattern . 0 20% 4320 -refresh_pattern ^http://downloads.cdn.openwrt.org 1440 20% 10080 -refresh_pattern ^http://downloads.openwrt.org 1440 20% 10080 -maximum_object_size 512 MB -coredump_dir /var/spool/squid +maximum_object_size 6 GB +cache_dir ufs /var/spool/squid 30720 16 256 +cache_mem 256 MB +maximum_object_size_in_memory 512 KB +cache_replacement_policy heap LFUDA +range_offset_limit -1 +quick_abort_min -1 KB diff --git a/podman-compose.yml b/podman-compose.yml index dd48a72f..fcfafd9d 100644 --- a/podman-compose.yml +++ b/podman-compose.yml @@ -1,32 +1,38 @@ -version: "3" +version: "2" volumes: redis: + grafana-storage: services: server: - image: "asu:latest" - build: - context: ./ - dockerfile: Containerfile - restart: always - environment: - - REDIS_URL=redis://redis/ + image: "docker.io/openwrt/asu:latest" + restart: unless-stopped + command: uvicorn --host 0.0.0.0 asu.main:app + env_file: asu.env + volumes: + - $PUBLIC_PATH:$PUBLIC_PATH:ro ports: - "127.0.0.1:8000:8000" depends_on: - redis worker: - image: "asu:latest" - build: - context: ./ - dockerfile: Containerfile - restart: always - command: rqworker --with-scheduler - environment: - - CONTAINER_HOST=unix://$CONTAINER_SOCK - - REDIS_URL=redis://redis/ + image: "docker.io/openwrt/asu:latest" + restart: unless-stopped + command: rqworker --logging_level INFO + env_file: asu.env + volumes: + - $PUBLIC_PATH:$PUBLIC_PATH:rw + - $CONTAINER_SOCK:$CONTAINER_SOCK:rw + depends_on: + - redis + + worker2: + image: "docker.io/openwrt/asu:latest" + restart: unless-stopped + command: rqworker --logging_level INFO + env_file: asu.env volumes: - $PUBLIC_PATH:$PUBLIC_PATH:rw - $CONTAINER_SOCK:$CONTAINER_SOCK:rw @@ -35,15 +41,32 @@ services: redis: image: "docker.io/redis/redis-stack-server" - restart: always + restart: unless-stopped volumes: - redis:/data/:rw + ports: + - "127.0.0.1:6379:6379" squid: image: "docker.io/ubuntu/squid:latest" - restart: always + restart: unless-stopped ports: - "127.0.0.1:3128:3128" volumes: - - "./misc/snippet.conf:/etc/squid/conf.d/snippet.conf:ro" + - ".squid.conf:/etc/squid/conf.d/snippet.conf:ro" - "./squid/:/var/spool/squid/:rw" + + grafana: + image: docker.io/grafana/grafana-oss + container_name: grafana + restart: unless-stopped + ports: + - "127.0.0.1:3000:3000" + depends_on: + - redis + environment: + GF_SERVER_DOMAIN: sysupgrade.openwrt.org + GF_SERVER_ROOT_URL: https://sysupgrade.openwrt.org/stats/ + GF_SERVER_SERVE_FROM_SUB_PATH: "true" + volumes: + - grafana-storage:/var/lib/grafana