ad dockerfiles

This commit is contained in:
oleg.vodyanov91@gmail.com 2025-09-10 00:59:38 +04:00
parent 932829cd19
commit 22bcc814e1
3 changed files with 152 additions and 2 deletions

View File

@ -8,6 +8,64 @@ services:
- db_data:/var/lib/postgresql/data
- ./db/init:/docker-entrypoint-initdb.d:ro
ports:
- 127.0.0.1:5432:5432
- 5432:5432
networks:
- docbot-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
chat:
build:
context: .
dockerfile: docker/chatbot/Dockerfile
restart: unless-stopped
environment:
- BOT_TOKEN=${BOT_TOKEN}
- DATABASE_URL=${DATABASE_URL}
- ADMIN_API_KEY=${ADMIN_API_KEY}
- LOGGING_LEVEL=${LOGGING_LEVEL:-INFO}
- PRODAMUS_TOKEN=${PRODAMUS_TOKEN}
volumes:
- ./data:/app/data
- ./conversations.pkl:/app/conversations.pkl
- ./.env:/app/.env
- ./.env_db:/app/.env_db
depends_on:
db:
condition: service_healthy
networks:
- docbot-network
profiles:
- production
- development
- chat_only
webhook:
build:
context: .
dockerfile: docker/webhook/Dockerfile
restart: unless-stopped
environment:
- BOT_TOKEN=${BOT_TOKEN}
- DATABASE_URL=${DATABASE_URL}
- ADMIN_API_KEY=${ADMIN_API_KEY}
- LOGGING_LEVEL=${LOGGING_LEVEL:-INFO}
- PRODAMUS_TOKEN=${PRODAMUS_TOKEN}
ports:
- "8000:8089"
depends_on:
db:
condition: service_healthy
networks:
- docbot-network
profiles:
- production
- development
networks:
docbot-network:
driver: bridge
volumes:
db_data:
db_data:

45
docker/chatbot/Dockerfile Normal file
View File

@ -0,0 +1,45 @@
FROM python:3.13-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONPATH="${PYTHONPATH}:/app/src"
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential
# Install Poetry
RUN pip install poetry==2.1.4
# Set work directory
WORKDIR /app
# Copy Poetry configuration files
COPY pyproject.toml poetry.lock* ./
# Configure Poetry and install dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --only=main --no-root \
&& rm -rf $POETRY_CACHE_DIR
# Copy application code
COPY src/ ./src/
# Create directories for bot persistence
RUN mkdir -p /app/data
# Create non-root user
RUN groupadd -r botuser && useradd -r -g botuser botuser
RUN chown -R botuser:botuser /app
USER botuser
# Health check - check if the bot process is running
HEALTHCHECK --interval=60s --timeout=30s --start-period=10s --retries=3 \
CMD pgrep -f "docbot.main" || exit 1
RUN ls -la
# Run the chatbot
CMD ["python", "-m", "docbot.main"]

47
docker/webhook/Dockerfile Normal file
View File

@ -0,0 +1,47 @@
FROM python:3.13-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV POETRY_NO_INTERACTION=1
ENV POETRY_VENV_IN_PROJECT=1
ENV POETRY_CACHE_DIR=/tmp/poetry_cache
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install poetry==2.1.4
# Set work directory
WORKDIR /app
# Copy Poetry configuration files
COPY pyproject.toml poetry.lock* ./
# Configure Poetry and install dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --only=main --no-dev \
&& rm -rf $POETRY_CACHE_DIR
# Copy application code
COPY src/ ./src/
# Create non-root user
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chown -R appuser:appuser /app
USER appuser
# Expose port
EXPOSE 8089
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8089/ || exit 1
# Run the webhook server
CMD ["uvicorn", "webhook.main:app", "--host", "0.0.0.0", "--port", "8089"]