feature gunicorn startup
This commit is contained in:
+19
-3
@@ -24,13 +24,20 @@ services:
|
|||||||
- type: bind
|
- type: bind
|
||||||
source: ../DB
|
source: ../DB
|
||||||
target: /home/excel-project/DB
|
target: /home/excel-project/DB
|
||||||
|
- type: bind
|
||||||
|
source: ../upload
|
||||||
|
target: /home/excel-project/upload
|
||||||
|
- type: bind
|
||||||
|
source: ../upload_bad
|
||||||
|
target: /home/excel-project/upload_bad
|
||||||
|
- type: bind
|
||||||
|
source: ../upload_finished
|
||||||
|
target: /home/excel-project/upload_finished
|
||||||
networks:
|
networks:
|
||||||
- backend
|
- backend
|
||||||
ports:
|
ports:
|
||||||
- "80:8000"
|
- "80:8000"
|
||||||
entrypoint:
|
entrypoint: ["./entrypoint.sh", "--dev"]
|
||||||
- python3
|
|
||||||
- main.py
|
|
||||||
|
|
||||||
backend-prod:
|
backend-prod:
|
||||||
profiles: ["prod"]
|
profiles: ["prod"]
|
||||||
@@ -49,6 +56,15 @@ services:
|
|||||||
- type: bind
|
- type: bind
|
||||||
source: ../DB
|
source: ../DB
|
||||||
target: /home/excel-project/DB
|
target: /home/excel-project/DB
|
||||||
|
- type: bind
|
||||||
|
source: ../upload
|
||||||
|
target: /home/excel-project/upload
|
||||||
|
- type: bind
|
||||||
|
source: ../upload_bad
|
||||||
|
target: /home/excel-project/upload_bad
|
||||||
|
- type: bind
|
||||||
|
source: ../upload_finished
|
||||||
|
target: /home/excel-project/upload_finished
|
||||||
networks:
|
networks:
|
||||||
- backend
|
- backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
+7
-3
@@ -6,7 +6,9 @@ LABEL org.opencontainers.image.source="https://git.homyk.space/MH.Dmitrii/The_Gr
|
|||||||
|
|
||||||
WORKDIR /home/excel-project
|
WORKDIR /home/excel-project
|
||||||
|
|
||||||
COPY pyproject.toml poetry.lock ./
|
COPY pyproject.toml poetry.lock docker/entrypoint.sh ./
|
||||||
|
|
||||||
|
RUN chmod +x ./entrypoint.sh
|
||||||
|
|
||||||
RUN pip install --no-cache-dir --break-system-packages poetry \
|
RUN pip install --no-cache-dir --break-system-packages poetry \
|
||||||
&& poetry config virtualenvs.create false \
|
&& poetry config virtualenvs.create false \
|
||||||
@@ -21,9 +23,11 @@ LABEL org.opencontainers.image.source="https://git.homyk.space/MH.Dmitrii/The_Gr
|
|||||||
|
|
||||||
WORKDIR /home/excel-project
|
WORKDIR /home/excel-project
|
||||||
|
|
||||||
COPY pyproject.toml poetry.lock main.py ./
|
COPY pyproject.toml poetry.lock main.py docker/entrypoint.sh ./
|
||||||
COPY src/ ./src/
|
COPY src/ ./src/
|
||||||
|
|
||||||
|
RUN chmod +x ./entrypoint.sh
|
||||||
|
|
||||||
RUN pip install --no-cache-dir --break-system-packages poetry \
|
RUN pip install --no-cache-dir --break-system-packages poetry \
|
||||||
&& poetry config virtualenvs.create false \
|
&& poetry config virtualenvs.create false \
|
||||||
&& poetry install --no-root --no-interaction --only main
|
&& poetry install --no-root --no-interaction --only main
|
||||||
@@ -34,4 +38,4 @@ RUN groupadd --gid 1000 appuser \
|
|||||||
|
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
ENTRYPOINT ["python3", "main.py"]
|
ENTRYPOINT ["./entrypoint.sh", "--prod"]
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
MODE=""
|
||||||
|
WORKERS=""
|
||||||
|
|
||||||
|
while [ -n "$1" ]; do
|
||||||
|
case "$1" in
|
||||||
|
--dev) MODE="dev" ;;
|
||||||
|
--prod) MODE="prod" ;;
|
||||||
|
--workers)
|
||||||
|
shift
|
||||||
|
WORKERS="$1"
|
||||||
|
;;
|
||||||
|
*) echo "$1 is not an option" ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$MODE" ]; then
|
||||||
|
echo "Usage: entrypoint.sh --dev|--prod [--workers N]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$MODE" = "dev" ]; then
|
||||||
|
WORKERS="${WORKERS:-1}"
|
||||||
|
exec gunicorn \
|
||||||
|
--workers "$WORKERS" \
|
||||||
|
--worker-class uvicorn.workers.UvicornWorker \
|
||||||
|
--worker-connections 1000 \
|
||||||
|
--reload \
|
||||||
|
--bind 0.0.0.0:8000 \
|
||||||
|
main:app
|
||||||
|
else
|
||||||
|
WORKERS="${WORKERS:-4}"
|
||||||
|
exec gunicorn \
|
||||||
|
--workers "$WORKERS" \
|
||||||
|
--worker-class uvicorn.workers.UvicornWorker \
|
||||||
|
--worker-connections 1000 \
|
||||||
|
--bind 0.0.0.0:8000 \
|
||||||
|
main:app
|
||||||
|
fi
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
|
from contextlib import asynccontextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import uvicorn
|
# import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
from src.web.protected_routes.auth_routes import router as protected_router
|
from src.web.protected_routes.auth_routes import router as protected_router
|
||||||
@@ -8,7 +9,15 @@ from src.web.protected_routes.protected_user_action_routes import (
|
|||||||
router as protected_user_action_routes,
|
router as protected_user_action_routes,
|
||||||
)
|
)
|
||||||
|
|
||||||
app=FastAPI(root_path="/")
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def lifespan(app: FastAPI):
|
||||||
|
create_dirs()
|
||||||
|
yield
|
||||||
|
print("shutting down")
|
||||||
|
|
||||||
|
|
||||||
|
app=FastAPI(root_path="/", lifespan=lifespan)
|
||||||
app.include_router(router=protected_router)
|
app.include_router(router=protected_router)
|
||||||
app.include_router(router=protected_user_action_routes)
|
app.include_router(router=protected_user_action_routes)
|
||||||
|
|
||||||
@@ -27,10 +36,3 @@ def create_dirs():
|
|||||||
|
|
||||||
for x in dirs_to_create:
|
for x in dirs_to_create:
|
||||||
Path(x).mkdir(parents=True, exist_ok=True)
|
Path(x).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
def main():
|
|
||||||
create_dirs()
|
|
||||||
uvicorn.run("main:app", host="0.0.0.0", reload=True)
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
|
||||||
main()
|
|
||||||
Reference in New Issue
Block a user