-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dockerized backend, tests and lint checks
- Loading branch information
1 parent
a0da475
commit d722fac
Showing
16 changed files
with
239 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Application that allows authenticated users to upload files of any size (hardware resources permitting) | ||
|
||
## BE | ||
- Implement an API endpoint that allows users to upload files of any size (hardware resources permitting). | ||
- Efficiently handle large file uploads, make sure to prevent memory issues. | ||
- Implement a way to authenticate users before allowing them to upload files. | ||
(For simplicity, you can hard-code a set of valid usernames and passwords.) | ||
- Dockerize the application. | ||
- Write test cases covering critical backend functionalities. Focus on testing file upload endpoint. | ||
|
||
## FE | ||
TODO | ||
|
||
|
||
## Notes | ||
- Used a single docker image for both api and test containers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Exclude Python bytecode files | ||
*.pyc | ||
|
||
# Exclude system-specific files | ||
__pycache__ | ||
|
||
# Exclude development files | ||
.DS_Store | ||
.idea/ | ||
*.log | ||
*.bak | ||
|
||
# Exclude version control files | ||
.git | ||
.gitignore | ||
|
||
.venv | ||
venv | ||
|
||
# Exclude pytest cache directories | ||
__pycache__/ | ||
.pytest_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
FROM python:3.12-slim | ||
|
||
ENV PYTHONFAULTHANDLER=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONHASHSEED=random \ | ||
PIP_NO_CACHE_DIR=off \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=on \ | ||
PIP_DEFAULT_TIMEOUT=100 | ||
|
||
RUN groupadd user && useradd --create-home --home-dir /home/user -g user user | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /home/user/app/ | ||
ENV PYTHONPATH=/home/user/app/ | ||
|
||
COPY pyproject.toml poetry.lock /home/user/app/ | ||
RUN pip install 'uvicorn[standard]' | ||
RUN pip install --no-cache-dir poetry | ||
|
||
RUN poetry config virtualenvs.create false | ||
RUN poetry install --with dev --no-root --no-interaction --no-ansi | ||
|
||
|
||
RUN mkdir -p /home/user/app/uploaded_files/ && chown -R user:user /home/user/app/uploaded_files/ | ||
|
||
USER user | ||
|
||
COPY --chown=user:user . /home/user/app/ | ||
|
||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
from fastapi import FastAPI, Response | ||
|
||
app = FastAPI() | ||
from fastapi import FastAPI | ||
|
||
from app.routers import router | ||
|
||
@app.get("/") | ||
def index() -> Response: | ||
return Response(content='{"message": "OK"}', media_type="application/json") | ||
app = FastAPI() | ||
app.include_router(router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.routers.health import router as health_router | ||
from app.routers.index import router as index_router | ||
|
||
__all__ = ["router"] | ||
|
||
router = APIRouter(prefix="/api") | ||
|
||
router.include_router(health_router) | ||
router.include_router(index_router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from http import HTTPStatus | ||
|
||
from fastapi import APIRouter, Response | ||
|
||
router = APIRouter(prefix="/health") | ||
|
||
|
||
@router.get("", name="health", description="Health check") | ||
async def health() -> Response: | ||
return Response(status_code=HTTPStatus.OK, content="OK") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import APIRouter, Response | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/", name="index", description="Index page") | ||
def index() -> Response: | ||
return Response(content="index page") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from fastapi import FastAPI, APIRouter | ||
from starlette.testclient import TestClient | ||
|
||
from app.main import app as api_app | ||
from app.routers import router as api_router | ||
|
||
|
||
@pytest.fixture | ||
def app() -> FastAPI: | ||
return api_app | ||
|
||
|
||
@pytest.fixture | ||
def router() -> APIRouter: | ||
return api_router | ||
|
||
|
||
@pytest.fixture | ||
def client(app: FastAPI) -> TestClient: | ||
return TestClient(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from fastapi import APIRouter | ||
from starlette.testclient import TestClient | ||
from http import HTTPStatus | ||
|
||
|
||
def test_health(client: TestClient, router: APIRouter) -> None: | ||
url = router.url_path_for("health") | ||
response = client.get(url) | ||
|
||
assert response.status_code == HTTPStatus.OK | ||
assert response.text == "OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from fastapi import APIRouter | ||
from starlette.testclient import TestClient | ||
from http import HTTPStatus | ||
|
||
|
||
def test_index(client: TestClient, router: APIRouter) -> None: | ||
url = router.url_path_for("index") | ||
response = client.get(url) | ||
|
||
assert response.status_code == HTTPStatus.OK | ||
assert response.text == "index page" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
services: | ||
api: &api | ||
container_name: virtuo-api | ||
build: | ||
context: ./backend | ||
ports: | ||
- "8000:8000" | ||
volumes: | ||
- uploaded-files-data:/home/user/app/uploaded_files | ||
|
||
test: | ||
<<: *api | ||
container_name: virtuo-api-test | ||
profiles: ["test"] | ||
command: poetry run task ci | ||
|
||
|
||
volumes: | ||
uploaded-files-data: |