Skip to content

Commit

Permalink
Bootstrap file upload server
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-z committed Oct 13, 2024
1 parent 7bec651 commit 8b929e4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ services:
target: server

ports:
# cvmfs file server
- "8080:80"
# application server
- "8081:81"
# cvmfs gateway
- "4929:4929"

volumes:
Expand Down
4 changes: 3 additions & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
watcloud-utils @ git+https://github.com/WATonomous/watcloud-utils.git@c8ce1006716e65971f750560f90f442721b3777d
python-slugify>=8.0.4,<9
python-slugify>=8.0.4,<9
python-multipart>=0.0.12,<1
uvicorn>=0.31.1,<1
25 changes: 25 additions & 0 deletions server/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
import string
import subprocess
import sys
import time
from pathlib import Path

import uvicorn
from fastapi import UploadFile
from slugify import slugify
from watcloud_utils.fastapi import WATcloudFastAPI
from watcloud_utils.logging import logger, set_up_logging
from watcloud_utils.typer import app

set_up_logging()

@app.command()
def init_cvmfs_repo(repo_name: str):
Expand Down Expand Up @@ -70,6 +76,25 @@ def start_server():
while True:
pass

fastapi_app = WATcloudFastAPI(logger=logger)


@fastapi_app.post("/upload")
async def upload_file(file: UploadFile):
# Time the file upload
start_time = time.perf_counter()
await file.read()
end_time = time.perf_counter()

logger.info(f"Uploaded file: {file.filename} (content_type: {file.content_type}) took {end_time - start_time:.2f}s")

return {"filename": file.filename, "content_type": file.content_type, "upload_time_s": end_time - start_time}


@app.command()
def start_server(port: int = 81):
uvicorn.run(fastapi_app, host="0.0.0.0", port=port)


if __name__ == "__main__":
app()

0 comments on commit 8b929e4

Please sign in to comment.