Skip to content

Commit 7f5da65

Browse files
authored
Merge pull request #18 from dmsnback/feature/docker
dockerfile и docker-compose
2 parents a0eac0a + 5f8c955 commit 7f5da65

5 files changed

Lines changed: 49 additions & 9 deletions

File tree

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.11-slim
2+
LABEL maintainer="Dmitry Titenkov <lt200711@yandex.ru>"
3+
LABEL version="1.0"
4+
LABEL description="API for miniCRM"
5+
RUN mkdir /app
6+
COPY requirements.txt /app
7+
RUN pip3 install -r /app/requirements.txt --no-cache-dir -vvv
8+
COPY . /app
9+
WORKDIR /app
10+
CMD [ "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload" ]

app/core/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class Settings(BaseSettings):
1111
first_superuser_password: str | None = None
1212
first_superuser_role: str | None = None
1313

14-
class Config:
15-
env_file = ".env"
14+
model_config = {
15+
"env_file": ".env",
16+
"extra": "ignore",
17+
}
1618

1719

1820
settings = Settings()

app/main.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import logging
22
from contextlib import asynccontextmanager
33

4-
import uvicorn
54
from fastapi import FastAPI
65

76
from app.core.config import settings
8-
from app.core.init_db import create_first_superuser
97
from app.core.logging import setup_logging
108
from app.routers.clients import client_router
119
from app.routers.comments import comment_router
@@ -20,7 +18,6 @@
2018
@asynccontextmanager
2119
async def lifespan(app: FastAPI):
2220
logging.info("Приложение miniCRM запущено")
23-
await create_first_superuser()
2421
yield
2522
logging.info("Приложение miniCRM остановлено")
2623

@@ -31,7 +28,3 @@ async def lifespan(app: FastAPI):
3128
app.include_router(client_router)
3229
app.include_router(deal_router)
3330
app.include_router(comment_router)
34-
35-
36-
if __name__ == "__main__":
37-
uvicorn.run("app.main:app", reload=True)

create_superuser.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import asyncio
2+
3+
from app.core.init_db import create_first_superuser
4+
5+
6+
async def main():
7+
await create_first_superuser()
8+
9+
10+
if __name__ == "__main__":
11+
asyncio.run(main())

docker-compose.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3.8'
2+
3+
services:
4+
db:
5+
image: postgres:15.0-alpine
6+
volumes:
7+
- postgres_data:/var/lib/postgresql/data/
8+
ports:
9+
- "5432:5432"
10+
env_file:
11+
- ./.env
12+
backend:
13+
build: .
14+
restart: always
15+
depends_on:
16+
- db
17+
env_file:
18+
- ./.env
19+
ports:
20+
- "8000:8000"
21+
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
22+
23+
volumes:
24+
postgres_data:

0 commit comments

Comments
 (0)