Skip to content

Commit

Permalink
Merge pull request #407 from SelfhostedPro/develop
Browse files Browse the repository at this point in the history
v0.0.7-hf1 Release
  • Loading branch information
SelfhostedPro authored May 31, 2021
2 parents 73389df + f15bf48 commit 9dead84
Show file tree
Hide file tree
Showing 11 changed files with 13,404 additions and 21,668 deletions.
16 changes: 15 additions & 1 deletion backend/api/actions/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from os import stat
from fastapi import HTTPException
from fastapi.responses import StreamingResponse

Expand Down Expand Up @@ -30,6 +31,7 @@
import docker
import aiodocker
import asyncio
import aiostream


"""
Expand Down Expand Up @@ -283,7 +285,7 @@ def launch_app(
failed_app = dclient.containers.get(name)
failed_app.remove()
raise HTTPException(
status_code=e.status_code, detail=e.explanation.decode("utf-8")
status_code=e.status_code, detail=e.explanation
)

print(
Expand Down Expand Up @@ -514,6 +516,18 @@ async def stat_generator(request, app_name):
# so there's no point in checking more often than that
await asyncio.sleep(1)

async def all_stat_generator(request):
async with aiodocker.Docker() as docker:
containers = []
_containers = await docker.containers.list()
for _app in _containers:
if _app._container["State"] == "running":
containers.append(_app)
loops = [stat_generator(request, app._container["Names"][0][1:]) for app in containers]
async with aiostream.stream.merge(*loops).stream() as merged:
async for event in merged:
yield event


async def process_app_stats(line, app_name):
cpu_total = 0.0
Expand Down
5 changes: 4 additions & 1 deletion backend/api/actions/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ def get_compose(name):
volumes = []
services = {}
compose = open(file)
loaded_compose = yaml.load(compose, Loader=yaml.SafeLoader)
try:
loaded_compose = yaml.load(compose, Loader=yaml.SafeLoader)
except yaml.scanner.ScannerError as exc:
raise HTTPException(422, f"{exc.problem_mark.line}:{exc.problem_mark.column} - {exc.problem}")
if loaded_compose.get("volumes"):
for volume in loaded_compose.get("volumes"):
volumes.append(volume)
Expand Down
8 changes: 6 additions & 2 deletions backend/api/routers/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def update_container(app_name, Authorize: AuthJWT = Depends()):
auth_check(Authorize)
return actions.app_update(app_name)

@router.get("/stats")
async def all_sse_stats(request: Request, Authorize: AuthJWT = Depends()):
auth_check(Authorize)
stat_generator = actions.all_stat_generator(request)
return EventSourceResponse(stat_generator)

@router.get("/{app_name}")
def get_container_details(app_name, Authorize: AuthJWT = Depends()):
Expand Down Expand Up @@ -65,7 +70,6 @@ def deploy_app(template: schemas.DeployForm, Authorize: AuthJWT = Depends()):
auth_check(Authorize)
return actions.deploy_app(template=template)


@router.get("/{app_name}/logs")
async def logs(app_name: str, request: Request, Authorize: AuthJWT = Depends()):
auth_check(Authorize)
Expand All @@ -77,4 +81,4 @@ async def logs(app_name: str, request: Request, Authorize: AuthJWT = Depends()):
async def sse_stats(app_name: str, request: Request, Authorize: AuthJWT = Depends()):
auth_check(Authorize)
stat_generator = actions.stat_generator(request, app_name)
return EventSourceResponse(stat_generator)
return EventSourceResponse(stat_generator)
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
aiodocker==0.19.1
aiosqlite==0.15.0
aiostream==0.4.3
alembic==1.4.3
bcrypt==3.1.7
certifi==2020.6.20
Expand Down
Loading

0 comments on commit 9dead84

Please sign in to comment.