ADD: Dockerize
This commit is contained in:
parent
3483a7008c
commit
fc9b8a8f22
12
.idea/dataSources.xml
Normal file
12
.idea/dataSources.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="database.db" uuid="d39a7297-12f1-460d-940b-c994fe436bec">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/database.db</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/pySourceRootDetection.xml
Normal file
10
.idea/pySourceRootDetection.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PySourceRootDetectionService">
|
||||
<option name="sourcePathsSet">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Erst nur requirements kopieren -> besseres Docker-Layer-Caching
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
10
db.py
10
db.py
@ -1,10 +1,10 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlmodel import SQLModel, Session
|
||||
import os
|
||||
from sqlmodel import create_engine, SQLModel, Session
|
||||
|
||||
from models.station import Station
|
||||
from models.measurement import IndoorMeasurement, OutdoorMeasurement
|
||||
DATA_DIR = "data"
|
||||
os.makedirs(DATA_DIR, exist_ok=True)
|
||||
|
||||
engine = create_engine("sqlite:///database.db")
|
||||
engine = create_engine(f"sqlite:///{DATA_DIR}/database.db")
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
def get_session():
|
||||
|
||||
6
main.py
6
main.py
@ -2,6 +2,7 @@ import functools
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI, Depends, Query
|
||||
from enum import Enum
|
||||
|
||||
@ -19,7 +20,7 @@ from services import stationService, measurementService
|
||||
app = FastAPI()
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:4200"],
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
@ -65,3 +66,6 @@ async def get_measurements(
|
||||
@app.get('/measurements/records', response_model=RecordResponse, status_code=200)
|
||||
async def get_records(station_ids: list[int] | None = Query(default=None), from_timestamp: datetime | None = None, session: Session = Depends(get_session)):
|
||||
return RecordResponse.model_validate(measurementService.get_measurement_records(session, station_ids, from_timestamp))
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("main:app", host="0.0.0.0", port=8000)
|
||||
24
requirements.txt
Normal file
24
requirements.txt
Normal file
@ -0,0 +1,24 @@
|
||||
annotated-doc==0.0.4
|
||||
annotated-types==0.7.0
|
||||
anyio==4.14.1
|
||||
certifi==2026.6.17
|
||||
charset-normalizer==3.4.7
|
||||
click==8.4.2
|
||||
coolname==5.0.0
|
||||
fastapi==0.138.1
|
||||
greenlet==3.5.3
|
||||
h11==0.16.0
|
||||
httpcore==1.0.9
|
||||
httpx==0.28.1
|
||||
idna==3.18
|
||||
pydantic==2.13.4
|
||||
pydantic_core==2.46.4
|
||||
requests==2.34.2
|
||||
SQLAlchemy==2.0.51
|
||||
sqlmodel==0.0.39
|
||||
starlette==1.3.1
|
||||
typing-inspection==0.4.2
|
||||
typing_extensions==4.15.0
|
||||
urllib3==2.7.0
|
||||
utcnow==0.3.8
|
||||
uvicorn==0.49.0
|
||||
Loading…
Reference in New Issue
Block a user