config for Docker
This commit is contained in:
12
.idea/runConfigurations/latest.xml
generated
Normal file
12
.idea/runConfigurations/latest.xml
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="latest" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
|
||||||
|
<deployment type="dockerfile">
|
||||||
|
<settings>
|
||||||
|
<option name="imageTag" value="docker.ctmapp.kiongroup.net/oms-db:latest" />
|
||||||
|
<option name="buildOnly" value="true" />
|
||||||
|
<option name="sourceFilePath" value="Dockerfile" />
|
||||||
|
</settings>
|
||||||
|
</deployment>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
7
.idea/runConfigurations/sandboxapi.xml
generated
7
.idea/runConfigurations/sandboxapi.xml
generated
@@ -6,6 +6,13 @@
|
|||||||
<option name="ENV_FILES" value="" />
|
<option name="ENV_FILES" value="" />
|
||||||
<option name="INTERPRETER_OPTIONS" value="" />
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
<option name="PARENT_ENVS" value="true" />
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="DB_HOST" value="mariadb.ctmapp.kiongroup.net" />
|
||||||
|
<env name="DB_PASSWORD" value="fast" />
|
||||||
|
<env name="DB_PORT" value="3306" />
|
||||||
|
<env name="DB_USER" value="fast" />
|
||||||
|
<env name="DB_DATABASE" value="fast_vpsx" />
|
||||||
|
</envs>
|
||||||
<option name="SDK_HOME" value="$PROJECT_DIR$/.venv/bin/python" />
|
<option name="SDK_HOME" value="$PROJECT_DIR$/.venv/bin/python" />
|
||||||
<option name="SDK_NAME" value="uv (vpsx-fast)" />
|
<option name="SDK_NAME" value="uv (vpsx-fast)" />
|
||||||
<option name="WORKING_DIRECTORY" value="" />
|
<option name="WORKING_DIRECTORY" value="" />
|
||||||
|
|||||||
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
FROM python:3
|
||||||
|
|
||||||
|
LABEL authors="Bernhard Radermacher"
|
||||||
|
|
||||||
|
RUN pip install fastapi mariadb pymysql passlib[bcrypt] pyjwt python-multipart sqlmodel uvicorn ldap3
|
||||||
|
|
||||||
|
ARG DB_USER="must be set"
|
||||||
|
ARG DB_PASSWORD="must be set"
|
||||||
|
|
||||||
|
ENV DB_USER=$DB_USER \
|
||||||
|
DB_PASSWORD=$DB_PASSWORD \
|
||||||
|
DB_HOST="mariadb.ctmapp.kiongroup.net" \
|
||||||
|
DB_PORT=3306 \
|
||||||
|
DB_DATABASE="fast_vpsx" \
|
||||||
|
LOG_LEVEL="INFO"
|
||||||
|
|
||||||
|
COPY app /
|
||||||
|
|
||||||
|
|
||||||
|
#ENTRYPOINT ["python", "main.py"]
|
||||||
|
#ENTRYPOINT ["/bin/bash"]
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/uvicorn", "main:app", "--host", "0.0.0.0"]
|
||||||
@@ -1,11 +1,22 @@
|
|||||||
from sqlalchemy import create_engine
|
import os
|
||||||
|
import sqlalchemy
|
||||||
|
|
||||||
# engine_url="sqlite+pysqlite:///vpsx.db"
|
# # engine_url="sqlite+pysqlite:///vpsx.db"
|
||||||
engine_url="mariadb+pymysql://fast:fast@mariadb.ctmapp.kiongroup.net/fast_vpsx?charset=utf8mb4"
|
# engine_url="mariadb+pymysql://fast:fast@mariadb.ctmapp.kiongroup.net/fast_vpsx?charset=utf8mb4"
|
||||||
|
|
||||||
|
engine_url = sqlalchemy.URL.create(
|
||||||
|
drivername="mariadb+pymysql",
|
||||||
|
username=os.getenv("DB_USER"),
|
||||||
|
password=os.getenv("DB_PASSWORD"),
|
||||||
|
host=os.getenv("DB_HOST"),
|
||||||
|
port=int(os.getenv("DB_PORT")),
|
||||||
|
database=os.getenv("DB_DATABASE"),
|
||||||
|
query={'charset': 'utf8mb4'},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_engine():
|
def get_engine():
|
||||||
return create_engine(engine_url)
|
return sqlalchemy.create_engine(engine_url)
|
||||||
|
|
||||||
engine = get_engine()
|
engine = get_engine()
|
||||||
|
|
||||||
|
|||||||
19
app/main.py
19
app/main.py
@@ -1,15 +1,13 @@
|
|||||||
import inspect
|
import inspect
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from typing import Annotated
|
|
||||||
|
|
||||||
import fastapi
|
import fastapi
|
||||||
from fastapi.security import OAuth2PasswordRequestForm
|
from fastapi import FastAPI
|
||||||
|
|
||||||
from app.alchemy import Base
|
|
||||||
from app.dependencies import engine
|
|
||||||
from fastapi import FastAPI, Depends, HTTPException
|
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
from app import routers
|
|
||||||
|
from alchemy import Base
|
||||||
|
import routers
|
||||||
|
from dependencies import engine
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
@@ -17,15 +15,10 @@ async def lifespan(app: FastAPI):
|
|||||||
Base.metadata.create_all(engine)
|
Base.metadata.create_all(engine)
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(lifespan=lifespan)
|
app = FastAPI(lifespan=lifespan)
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"])
|
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"])
|
||||||
|
|
||||||
|
|
||||||
# app.include_router(routers.contact)
|
|
||||||
# app.include_router(routers.country)
|
|
||||||
# app.include_router(routers.status)
|
|
||||||
# app.include_router(routers.user)
|
|
||||||
|
|
||||||
for i in inspect.getmembers(routers):
|
for i in inspect.getmembers(routers):
|
||||||
if isinstance(i[1], fastapi.routing.APIRouter):
|
if isinstance(i[1], fastapi.routing.APIRouter):
|
||||||
app.include_router(i[1])
|
app.include_router(i[1])
|
||||||
|
|||||||
Reference in New Issue
Block a user