diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..14babb0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# Use an official Python runtime as a parent image (Alpine-based for minimal vulnerabilities) +FROM python:3.13-alpine + +# Set the working directory in the container +WORKDIR /app + +# Prevent Python from writing pyc files to disc +ENV PYTHONDONTWRITEBYTECODE=1 +# Ensure Python output is sent straight to terminal (useful for logs) +ENV PYTHONUNBUFFERED=1 + +# Install system dependencies if needed (e.g., for certain Python packages) +# RUN apt-get update && apt-get install -y --no-install-recommends some-package && rm -rf /var/lib/apt/lists/* + +# Copy dependency definition files +# If using Poetry: +# COPY pyproject.toml poetry.lock* ./ +# RUN pip install --no-cache-dir poetry +# RUN poetry config virtualenvs.create false && poetry install --no-dev --no-interaction --no-ansi +# If using pip with requirements.txt: +COPY requirements.txt ./ +RUN pip install --no-cache-dir --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code +COPY main.py . +# COPY session_string_generator.py . # Optional: if needed within the container, otherwise can be run outside + +# Create a non-root user and switch to it +RUN adduser --disabled-password --gecos "" appuser && chown -R appuser:appuser /app +USER appuser + +# Define environment variables needed by the application +# These should be provided at runtime, not hardcoded (especially secrets) +ENV TELEGRAM_API_ID="" +ENV TELEGRAM_API_HASH="" +# Specify one of the following at runtime: +# Default session filename +ENV TELEGRAM_SESSION_NAME="telegram_mcp_session" +# Or provide the session string directly +ENV TELEGRAM_SESSION_STRING="" + +# Expose any ports if the application were a web server (not needed for stdio MCP) +# EXPOSE 8000 + +# Define the command to run the application +CMD ["python", "main.py"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7293089 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + telegram-mcp-server: + build: + context: . + dockerfile: Dockerfile + container_name: telegram_mcp_server + # Load environment variables from a .env file in the same directory + env_file: + - .env + # Keep stdin open and allocate a pseudo-TTY, crucial for stdio MCP servers + stdin_open: true + tty: true + # Optional: Uncomment the following lines to mount a local directory + # for persisting the Telegram session file if NOT using TELEGRAM_SESSION_STRING. + # Replace './telegram_sessions' with your desired host path. + # volumes: + # - ./telegram_sessions:/app + restart: unless-stopped \ No newline at end of file