feature/docker #1
+19
-3
@@ -24,13 +24,20 @@ services:
|
||||
- type: bind
|
||||
source: ../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:
|
||||
- backend
|
||||
ports:
|
||||
- "80:8000"
|
||||
entrypoint:
|
||||
- python3
|
||||
- main.py
|
||||
entrypoint: ["./entrypoint.sh", "--dev"]
|
||||
|
||||
backend-prod:
|
||||
profiles: ["prod"]
|
||||
@@ -49,6 +56,15 @@ services:
|
||||
- type: bind
|
||||
source: ../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:
|
||||
- backend
|
||||
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
|
||||
|
||||
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 \
|
||||
&& 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
|
||||
|
||||
COPY pyproject.toml poetry.lock main.py ./
|
||||
COPY pyproject.toml poetry.lock main.py docker/entrypoint.sh ./
|
||||
COPY src/ ./src/
|
||||
|
||||
RUN chmod +x ./entrypoint.sh
|
||||
|
||||
RUN pip install --no-cache-dir --break-system-packages poetry \
|
||||
&& poetry config virtualenvs.create false \
|
||||
&& poetry install --no-root --no-interaction --only main
|
||||
@@ -34,4 +38,4 @@ RUN groupadd --gid 1000 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
|
||||
|
||||
import uvicorn
|
||||
# import uvicorn
|
||||
from fastapi import FastAPI
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
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_user_action_routes)
|
||||
|
||||
@@ -26,11 +35,4 @@ def create_dirs():
|
||||
"./upload_finished")
|
||||
|
||||
for x in dirs_to_create:
|
||||
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()
|
||||
Path(x).mkdir(parents=True, exist_ok=True)
|
||||
Reference in New Issue
Block a user