Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.11-slim
LABEL maintainer="Dmitry Titenkov <lt200711@yandex.ru>"
LABEL version="1.0"
LABEL description="API for miniCRM"
RUN mkdir /app
COPY requirements.txt /app
RUN pip3 install -r /app/requirements.txt --no-cache-dir -vvv
COPY . /app
WORKDIR /app
CMD [ "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload" ]
6 changes: 4 additions & 2 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class Settings(BaseSettings):
first_superuser_password: str | None = None
first_superuser_role: str | None = None

class Config:
env_file = ".env"
model_config = {
"env_file": ".env",
"extra": "ignore",
}


settings = Settings()
7 changes: 0 additions & 7 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import logging
from contextlib import asynccontextmanager

import uvicorn
from fastapi import FastAPI

from app.core.config import settings
from app.core.init_db import create_first_superuser
from app.core.logging import setup_logging
from app.routers.clients import client_router
from app.routers.comments import comment_router
Expand All @@ -20,7 +18,6 @@
@asynccontextmanager
async def lifespan(app: FastAPI):
logging.info("Приложение miniCRM запущено")
await create_first_superuser()
yield
logging.info("Приложение miniCRM остановлено")

Expand All @@ -31,7 +28,3 @@ async def lifespan(app: FastAPI):
app.include_router(client_router)
app.include_router(deal_router)
app.include_router(comment_router)


if __name__ == "__main__":
uvicorn.run("app.main:app", reload=True)
11 changes: 11 additions & 0 deletions create_superuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import asyncio

from app.core.init_db import create_first_superuser


async def main():
await create_first_superuser()


if __name__ == "__main__":
asyncio.run(main())
24 changes: 24 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.8'

services:
db:
image: postgres:15.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
ports:
- "5432:5432"
env_file:
- ./.env
backend:
build: .
restart: always
depends_on:
- db
env_file:
- ./.env
ports:
- "8000:8000"
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload

volumes:
postgres_data: