Skip to content

Commit 65acbe2

Browse files
committed
Switch to fastapi for docs
1 parent b80350c commit 65acbe2

File tree

11 files changed

+47
-35
lines changed

11 files changed

+47
-35
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ RUN \
2424

2525
COPY root/ /
2626

27-
EXPOSE 5000
27+
EXPOSE 8000
2828
VOLUME /config

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pipeline {
3030
MULTIARCH='true'
3131
CI='true'
3232
CI_WEB='false'
33-
CI_PORT='5000'
33+
CI_PORT='8000'
3434
CI_SSL='false'
3535
CI_DELAY='30'
3636
CI_DOCKERENV='CI=1'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ docker run -d \
3535
-e DB_FILE=/config/api.db `#optional` \
3636
-e INVALIDATE_HOURS=24 `#optional` \
3737
-e PAT=token `#optional` \
38-
-p 5000:5000 \
38+
-p 8000:8000 \
3939
-v /path/to/lsio-api/config:/config \
4040
--restart unless-stopped \
4141
lscr.io/linuxserver/lsio-api:latest

jenkins-vars.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repo_vars:
1818
- MULTIARCH='true'
1919
- CI='true'
2020
- CI_WEB='false'
21-
- CI_PORT='5000'
21+
- CI_PORT='8000'
2222
- CI_SSL='false'
2323
- CI_DELAY='30'
2424
- CI_DOCKERENV='CI=1'

readme-vars.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ full_custom_readme: |
4040
-e DB_FILE=/config/api.db `#optional` \
4141
-e INVALIDATE_HOURS=24 `#optional` \
4242
-e PAT=token `#optional` \
43-
-p 5000:5000 \
43+
-p 8000:8000 \
4444
-v /path/to/lsio-api/config:/config \
4545
--restart unless-stopped \
4646
lscr.io/linuxserver/lsio-api:latest

root/app/api.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
from flask import Flask
2-
from flask import jsonify
1+
from fastapi import FastAPI
32
from keyvaluestore import KeyValueStore
3+
from models import ImagesResponse, ImagesData
44

5-
api = Flask(__name__)
5+
api = FastAPI(docs_url="/")
66

7+
@api.get("/health", summary="Get the health status")
8+
async def health():
9+
return "Success"
710

8-
@api.route("/health")
9-
def health():
10-
return jsonify("Success")
11-
12-
@api.route("/api/v1/images")
13-
def images():
11+
@api.get("/api/v1/images", response_model=ImagesResponse, summary="Get a list of images")
12+
async def images():
1413
with KeyValueStore() as kv:
15-
return api.response_class(
16-
response=kv["images"],
17-
status=200,
18-
mimetype="application/json"
19-
)
14+
return ImagesResponse(status="OK", data=ImagesData.model_validate_json(kv["images"]))
2015

2116
if __name__ == "__main__":
2217
api.run()

root/app/models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from pydantic import BaseModel
2+
3+
4+
class Image(BaseModel):
5+
name: str
6+
version: str
7+
category: str
8+
stable: bool
9+
deprecated: bool
10+
11+
class Repository(BaseModel):
12+
linuxserver: list[Image]
13+
14+
class ImagesData(BaseModel):
15+
repositories: Repository
16+
17+
class ImagesResponse(BaseModel):
18+
status: str
19+
data: ImagesData

root/app/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Flask==3.1.0
2-
gunicorn==23.0.0
1+
fastapi[standard]==0.115.8
32
PyGithub==2.5.0
43
PyYAML==6.0.2

root/app/updater.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from github import Auth
22
from github import Github
33
from keyvaluestore import KeyValueStore
4+
from models import Image, Repository, ImagesData
45

56
import datetime
6-
import json
77
import os
88
import threading
99
import time
@@ -41,23 +41,22 @@ def get_state():
4141
if "Internal" in categories:
4242
continue
4343
version = "latest" if "development_versions_items" not in readme_vars else readme_vars["development_versions_items"][0]["tag"]
44-
images.append({
45-
"name": repo.full_name.replace("linuxserver/docker-", ""),
46-
"version": version,
47-
"category": categories,
48-
"stable": version == "latest",
49-
"deprecated": False
50-
})
51-
return {"status": "OK", "data": {"repositories": {"linuxserver": images}}}
44+
images.append(Image(
45+
name=repo.full_name.replace("linuxserver/docker-", ""),
46+
version=version,
47+
category=categories,
48+
stable=version == "latest",
49+
deprecated=False
50+
))
51+
return ImagesData(repositories=Repository(linuxserver=images)).model_dump_json()
5252

5353
def update_images():
5454
with KeyValueStore(invalidate_hours=INVALIDATE_HOURS, readonly=False) as kv:
5555
if "images" in kv or CI == "1":
5656
print(f"{datetime.datetime.now()} - skipped - already updated")
5757
return
5858
print(f"{datetime.datetime.now()} - updating images")
59-
current_state = get_state()
60-
kv["images"] = json.dumps(current_state)
59+
kv["images"] = get_state()
6160
print(f"{datetime.datetime.now()} - updated images")
6261

6362
class UpdateImages(threading.Thread):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4-
exec s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 5000" \
5-
cd /app s6-setuidgid abc gunicorn api:api -b 0.0.0.0:5000 -w 4 --timeout 15 --log-level warning
4+
exec s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 8000" \
5+
cd /app s6-setuidgid abc fastapi run --workers 4 api.py

0 commit comments

Comments
 (0)