Skip to content

Commit 190474a

Browse files
authored
feat: (#40)
* version and description pulled from toml * black reformatting * moved main.py to root folder, dockerfile explicitly loads src * same as srcsplit but retaining src/main.py (#38) * removed main.py from root, added to src * black reformatting
1 parent 49fb42a commit 190474a

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ WORKDIR /app
88

99
# Copy the current directory contents into the container at /app
1010
COPY . /app
11-
11+
COPY src /app/
12+
1213
# Install dependencies
1314
RUN uv sync --frozen --no-install-project
1415

1516
# Sync the project
1617
RUN uv sync --frozen
1718

1819
# Command to run the app when the container starts
19-
CMD ["uv", "run", "src/main.py"]
20+
CMD ["uv", "run", "test_main.py"]

src/main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from fastapi import FastAPI
22
from fastapi.responses import RedirectResponse
3-
from routers.health import health_router
4-
from routers.mtcars import data_output
3+
from src.routers.health import health_router
4+
from src.routers.mtcars import data_output
55
import uvicorn
66
import tomllib
77

8+
# Import pyproject toml info using tomllib
89
try:
910
with open("pyproject.toml", "rb") as f:
1011
tomldata = tomllib.load(f)

test_main.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from fastapi import FastAPI
2+
from fastapi.responses import RedirectResponse
3+
from routers.health import health_router
4+
from routers.mtcars import data_output
5+
from docs.documentation import description
6+
import uvicorn
7+
8+
app = FastAPI(
9+
# This info goes directly into /docs
10+
title="RMI Web API poc",
11+
# Description of API defined in docs/documentation.py for ease of reading
12+
description=description,
13+
summary="This project is a proof-of-concept (POC) web API built using the FastAPI library.",
14+
version="0.0.1",
15+
contact={
16+
"name": "RMI",
17+
"url": "https://github.com/RMI",
18+
},
19+
license_info={
20+
"name": "MIT",
21+
"url": "https://github.com/RMI/web-api-poc/blob/main/LICENSE.txt",
22+
},
23+
)
24+
25+
26+
@app.get("/")
27+
async def redirect():
28+
response = RedirectResponse(url="/docs")
29+
return response
30+
31+
32+
app.include_router(health_router)
33+
app.include_router(data_output)
34+
35+
36+
if __name__ == "__main__":
37+
uvicorn.run("main:app", host="0.0.0.0", port=5000, log_level="info")

0 commit comments

Comments
 (0)