diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8591ab4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,35 @@ +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python + +venv/ +env/ +ENV/ +.venv/ + +.vscode/ +.idea/ +*.swp +*.swo +*~ +.DS_Store + +.git/ +.gitignore +.gitattributes + +Dockerfile* +docker-compose*.yml +.dockerignore + +drone.yml + +tmp/ +temp/ +*.tmp + +Thumbs.db +.DS_Store + diff --git a/.gitignore b/.gitignore index 9f99d40..436fb97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -# Python __pycache__/ *.pyc *.pyo diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..43088e5 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.11-slim + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + gcc \ + postgresql-client \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +ENV PYTHONPATH=/app +ENV PYTHONUNBUFFERED=1 + +EXPOSE 8000 + + +CMD ["python", "-m", "uvicorn", "src.presentation.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "info"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..495c444 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,81 @@ +services: + postgres: + image: postgres:15-alpine + restart: unless-stopped + env_file: + - .env + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + + qdrant: + image: qdrant/qdrant:latest + restart: unless-stopped + ports: + - "6333:6333" + volumes: + - qdrant_data:/qdrant/storage + + redis: + image: redis:7-alpine + restart: unless-stopped + ports: + - "6379:6379" + volumes: + - redis_data:/data + + backend: + build: ./backend + restart: unless-stopped + env_file: + - .env + environment: + POSTGRES_HOST: postgres + POSTGRES_PORT: ${POSTGRES_PORT} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + QDRANT_HOST: qdrant + QDRANT_PORT: ${QDRANT_PORT} + REDIS_HOST: redis + REDIS_PORT: ${REDIS_PORT} + DEBUG: "true" + SECRET_KEY: ${SECRET_KEY} + APP_NAME: ${APP_NAME} + CORS_ORIGINS: ${CORS_ORIGINS} + ports: + - "8000:8000" + depends_on: + - postgres + - qdrant + - redis + + tg_bot: + build: ./tg_bot + restart: unless-stopped + env_file: + - .env + environment: + POSTGRES_HOST: postgres + POSTGRES_PORT: ${POSTGRES_PORT} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN} + DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY} + DEEPSEEK_API_URL: ${DEEPSEEK_API_URL:-https://api.deepseek.com/v1/chat/completions} + YANDEX_OCR_API_KEY: ${YANDEX_OCR_API_KEY} + DEBUG: "true" + depends_on: + - postgres + - backend + +volumes: + postgres_data: + qdrant_data: + redis_data: \ No newline at end of file diff --git a/drone.yml b/drone.yml new file mode 100644 index 0000000..ea0b9a7 --- /dev/null +++ b/drone.yml @@ -0,0 +1,30 @@ +kind: pipeline +type: docker +name: deploy-backend + +trigger: + event: + - push + - pull_request + - tag + branch: + - main + +steps: + - name: deploy-backend + image: appleboy/drone-ssh + settings: + host: + from_secret: server_host + username: + from_secret: server_username + password: + from_secret: server_password + port: 22 + script: + - cd BETTERCALLPRASKOVIA + - git pull origin main + - docker-compose stop backend tg_bot + - docker-compose up --build -d backend tg_bot + - docker system prune -f + diff --git a/tg_bot/Dockerfile b/tg_bot/Dockerfile new file mode 100644 index 0000000..8bbf51d --- /dev/null +++ b/tg_bot/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.11-slim + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + gcc \ + postgresql-client \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +ENV PYTHONPATH=/app +ENV PYTHONUNBUFFERED=1 + +CMD ["python", "tg_bot/main.py"] \ No newline at end of file