partial deployment

This commit is contained in:
2025-09-28 22:53:09 -04:00
parent 9bb763a053
commit 0acfd16d96
13 changed files with 201 additions and 7 deletions

View File

@@ -1,2 +1,3 @@
__pycache__/
*/__pycache__/
*/__pycache__/
data/

View File

@@ -5,4 +5,9 @@ COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["fastapi", "run", "main.py"]
EXPOSE 80
HEALTHCHECK --interval=10s --timeout=5s --retries=3 --start-period=10s \
CMD python healthcheck.py http://localhost/api/ || exit 1
CMD ["fastapi", "run", "main.py", "--port", "80", "--proxy-headers"]

24
api/healthcheck.py Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/env python3
import httpx
from sys import argv
def main():
if len(argv) > 1:
try_addr = argv[1]
else:
try_addr = "http://localhost/api/"
try:
r = httpx.get(try_addr)
except:
print("No server at address or port.")
quit(1)
if r.is_success:
print(f"Success. {r.status_code}")
quit(0)
else:
print(f"Fail!!! {r.status_code}")
quit(1)
if __name__ == "__main__":
main()

View File

@@ -2,6 +2,9 @@
from fastapi import FastAPI
from sys import argv
from exceptions import bad_key
from repos.api_keys import ApiKeyRepo
from routers.prefixes import prefix_router
from routers.tickets import ticket_router
@@ -16,6 +19,12 @@ if argv[1] == "run":
else:
app = FastAPI(title="TAM3 API Server")
@app.get("/api/")
def remote_check(api_key: str = ""):
if not ApiKeyRepo().check_api(api_key):
return {"status": "healthy", "auth": False, "whoami": "TAM3 Server"}
return {"status": "healthy", "auth": True, "whoami": "TAM3 Server"}
app.include_router(prefix_router)
app.include_router(ticket_router)
app.include_router(basket_router)

View File

@@ -21,10 +21,13 @@ def get_one_prefix(api_key: str, prefix_name: str):
@prefix_router.post("/")
def post_one_prefix(api_key: str, p: Prefix):
def post_one_prefix(api_key: str, p: Prefix | list[Prefix]):
if not ApiKeyRepo().check_api(api_key):
raise bad_key
rep_detail = PrefixRepo().add_one(p)
if type(p) is list:
rep_detail = PrefixRepo().add_list(p)
elif type(p) is Prefix:
rep_detail = PrefixRepo().add_one(p)
return {"detail": rep_detail}