Skip to content
Open
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
24 changes: 1 addition & 23 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Upload Python Package and Docker Container
name: Upload Docker Container
permissions:
contents: read

Expand All @@ -18,28 +18,6 @@ jobs:
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry

- name: Set __version__ and poetry version
run: |
TAG="$(git describe --tags --always | awk -F"-" '{if (NF>1) {print substr($1, 2)".post"$2} else {print substr($1, 2)}}')"
echo "__version__ = \"$TAG\"" > asu/__init__.py
poetry version "$TAG"

- name: Build and publish PyPi package
if: github.event_name == 'release'
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish --build

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down
21 changes: 11 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,33 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v1
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: |
python -m pip install --upgrade poetry
poetry install
run: uv sync --extra dev

- name: Lint with ruff
run: |
poetry run ruff check .
run: uv run ruff check .

- name: Stylecheck with ruff
run: |
poetry run ruff format --check .
run: uv run ruff format --check .

- name: Test with pytest
run: |
export CONTAINER_SOCKET_PATH="/tmp/podman.sock"
podman system service --time=0 "unix://$CONTAINER_SOCKET_PATH" &
poetry run coverage run -m pytest -vv --runslow
poetry run coverage xml
uv run coverage run -m pytest -vv --runslow
uv run coverage xml

- name: Codecov
uses: codecov/codecov-action@v4
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ site/
redis/
public/
squid/
poetry.lock
json/
instance/
htmlcov/
Expand Down
18 changes: 10 additions & 8 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ FROM python:3.12-slim

WORKDIR /app/

RUN pip install poetry
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

COPY poetry.lock pyproject.toml README.md ./
# Copy dependency files
COPY pyproject.toml README.md ./

RUN poetry config virtualenvs.create false

RUN poetry install --only main --no-root --no-directory
# Install dependencies (without dev dependencies)
# Using --no-dev to exclude optional dev dependencies
RUN uv sync --frozen --no-dev || uv sync --no-dev

# Copy application code
COPY ./asu/ ./asu/

RUN poetry install --only main

CMD uvicorn --host 0.0.0.0 'asu.main:app'
# Run the application
CMD uv run uvicorn --host 0.0.0.0 'asu.main:app'
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,28 @@ pasta_options = [

### Development

After cloning this repository, install `poetry` which manages the Python
After cloning this repository, install `uv` which manages the Python
dependencies.

```bash
apt install python3-poetry
poetry install
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install dependencies
uv sync --extra dev
```

#### Running the server

```bash
poetry run fastapi dev asu/main.py
uv run fastapi dev asu/main.py
```

#### Running a worker

```bash
source .env # poetry does not load .env
poetry run rq worker
source .env
uv run rq worker
```

### API
Expand Down
10 changes: 10 additions & 0 deletions asu/package_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ def _add_if_missing(package):
build_request.packages.remove("auc")
_add_if_missing("owut")

if build_request.profile in {"tplink_archer-c6-v2"}:
_add_if_missing("ipq-wifi-tplink_archer-c6-v2")

if build_request.target in {
"mediatek/filogic",
"mediatek/mt7622",
"mediatek/mt7623",
}:
_add_if_missing("fitblk")

# 25.12 specific changes
if build_request.version.startswith("25.12"):
# Changes for https://github.com/openwrt/openwrt/commit/8a7239009c5f4b28b696042b70ed1f8f89902915
Expand Down
21 changes: 6 additions & 15 deletions asu/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from io import BytesIO
from typing import Optional

import hishel
import nacl.signing
from fastapi import FastAPI
import httpx
from httpx import Response
from podman import PodmanClient
from podman.domain.containers import Container
Expand All @@ -27,6 +27,9 @@
log: logging.Logger = logging.getLogger("rq.worker")
log.propagate = False # Suppress duplicate log messages.

# Create a shared HTTP client
_http_client = httpx.Client()


def get_redis_client(unicode: bool = True) -> redis.client.Redis:
return redis.from_url(settings.redis_url, decode_responses=unicode)
Expand All @@ -36,11 +39,8 @@ def get_redis_ts():
return get_redis_client().ts()


def client_get(url: str, ttl: int = 3600) -> Response:
return hishel.CacheClient(
storage=hishel.RedisStorage(client=get_redis_client(False), ttl=ttl),
controller=hishel.Controller(always_revalidate=True, allow_heuristics=True),
).get(url)
def client_get(url: str) -> Response:
return _http_client.get(url)


def add_timestamp(key: str, labels: dict[str, str] = {}, value: int = 1) -> None:
Expand Down Expand Up @@ -502,12 +502,6 @@ def add_versions(version_list: list, *versions: str) -> None:
log.info(f".versions.json: failed to download {response.status_code}")
return False

if response.extensions["from_cache"] and app.versions:
log.debug(".versions.json: cache hit")
return False

log.debug(".versions.json: cache miss, reloading")

versions_upstream = response.json()
upcoming_version = versions_upstream["upcoming_version"]

Expand Down Expand Up @@ -552,9 +546,6 @@ def reload_targets(app: FastAPI, version: str) -> bool:
version_path = branch_data["path"].format(version=version)
response = client_get(settings.upstream_url + f"/{version_path}/.targets.json")

if response.extensions["from_cache"] and app.targets[version]:
return False

app.targets[version] = response.json() if response.status_code == 200 else {}

return True
Expand Down
4 changes: 2 additions & 2 deletions podman-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
context: .
dockerfile: Containerfile
restart: unless-stopped
command: uvicorn --host 0.0.0.0 asu.main:app
command: uv run uvicorn --host 0.0.0.0 asu.main:app
env_file: .env
environment:
REDIS_URL: "redis://redis:6379/0"
Expand All @@ -22,7 +22,7 @@ services:
context: .
dockerfile: Containerfile
restart: unless-stopped
command: rqworker --logging_level INFO
command: uv run rqworker --logging_level INFO
env_file: .env
environment:
REDIS_URL: "redis://redis:6379/0"
Expand Down
Loading