Merge pull request #1 from overspend1/codex/fix-dockerfile-and-compose-for-meme-wrangler
fix: repair docker setup for telegram bot
This commit was merged in pull request #1.
This commit is contained in:
@@ -1,32 +1,7 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
.venv/
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Database
|
||||
*.db
|
||||
*.db-journal
|
||||
|
||||
# Environment variables
|
||||
.git
|
||||
.gitignore
|
||||
__pycache__
|
||||
*.pyc
|
||||
backups
|
||||
.env
|
||||
|
||||
# IDEs
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Docker
|
||||
data/
|
||||
.env.*
|
||||
|
||||
32
Dockerfile
32
Dockerfile
@@ -1,32 +1,38 @@
|
||||
# Use Python 3.12 slim image
|
||||
FROM python:3.12-slim
|
||||
|
||||
# Configure Python environment
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies (if needed)
|
||||
RUN apt-get update && apt-get install -y \
|
||||
# Install system dependencies required for asyncpg build
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
libpq-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy requirements first (for better caching)
|
||||
COPY requirements.txt .
|
||||
COPY requirements.txt ./
|
||||
|
||||
# Install Python dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
RUN pip install --no-cache-dir python-telegram-bot==20.7
|
||||
RUN pip install --no-cache-dir --upgrade pip \
|
||||
&& pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the bot code
|
||||
COPY bot.py .
|
||||
# Copy application source
|
||||
COPY . .
|
||||
|
||||
# Create directory for backups
|
||||
# Ensure backups directory exists inside the container
|
||||
RUN mkdir -p /app/backups
|
||||
|
||||
# Set environment variables (will be overridden by docker-compose or run command)
|
||||
ENV TELEGRAM_BOT_TOKEN=""
|
||||
ENV OWNER_ID=""
|
||||
ENV CHANNEL_ID=""
|
||||
ENV DATABASE_URL=""
|
||||
ENV MEMEBOT_BACKUP_DIR="/app/backups"
|
||||
ENV TELEGRAM_BOT_TOKEN="" \
|
||||
OWNER_ID="" \
|
||||
CHANNEL_ID="" \
|
||||
DATABASE_URL="" \
|
||||
MEMEBOT_BACKUP_DIR="/app/backups"
|
||||
|
||||
# Run the bot
|
||||
CMD ["python", "bot.py"]
|
||||
|
||||
48
bot.py
48
bot.py
@@ -30,31 +30,41 @@ if TYPE_CHECKING:
|
||||
from telegram import Update, Message, InputFile
|
||||
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters
|
||||
else:
|
||||
Update = Message = InputFile = Any # type: ignore
|
||||
ContextTypes = SimpleNamespace(DEFAULT_TYPE=Any) # type: ignore
|
||||
try:
|
||||
from telegram import Update, Message, InputFile # type: ignore
|
||||
from telegram.ext import ( # type: ignore
|
||||
ApplicationBuilder,
|
||||
ContextTypes,
|
||||
CommandHandler,
|
||||
MessageHandler,
|
||||
filters,
|
||||
)
|
||||
except ModuleNotFoundError:
|
||||
Update = Message = InputFile = Any # type: ignore
|
||||
ContextTypes = SimpleNamespace(DEFAULT_TYPE=Any) # type: ignore
|
||||
|
||||
class _MissingTelegramModule:
|
||||
"""Lazily raise when Telegram features are used without dependency."""
|
||||
class _MissingTelegramModule:
|
||||
"""Lazily raise when Telegram features are used without dependency."""
|
||||
|
||||
def __getattr__(self, item):
|
||||
raise RuntimeError(
|
||||
"python-telegram-bot must be installed to use the Meme Wrangler bot (missing telegram module)."
|
||||
)
|
||||
def __getattr__(self, item):
|
||||
raise RuntimeError(
|
||||
"python-telegram-bot must be installed to use the Meme Wrangler bot (missing telegram module)."
|
||||
)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
raise RuntimeError(
|
||||
"python-telegram-bot must be installed to use the Meme Wrangler bot (missing telegram module)."
|
||||
)
|
||||
def __call__(self, *args, **kwargs):
|
||||
raise RuntimeError(
|
||||
"python-telegram-bot must be installed to use the Meme Wrangler bot (missing telegram module)."
|
||||
)
|
||||
|
||||
ApplicationBuilder = CommandHandler = MessageHandler = _MissingTelegramModule() # type: ignore
|
||||
ApplicationBuilder = CommandHandler = MessageHandler = _MissingTelegramModule() # type: ignore
|
||||
|
||||
class _MissingFilters(SimpleNamespace):
|
||||
def __getattr__(self, item):
|
||||
raise RuntimeError(
|
||||
"python-telegram-bot must be installed to use the Meme Wrangler bot (missing telegram filters)."
|
||||
)
|
||||
class _MissingFilters(SimpleNamespace):
|
||||
def __getattr__(self, item):
|
||||
raise RuntimeError(
|
||||
"python-telegram-bot must be installed to use the Meme Wrangler bot (missing telegram filters)."
|
||||
)
|
||||
|
||||
filters = _MissingFilters() # type: ignore
|
||||
filters = _MissingFilters() # type: ignore
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -3,19 +3,30 @@ services:
|
||||
image: postgres:15
|
||||
container_name: meme-wrangler-db
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- POSTGRES_DB=${POSTGRES_DB}
|
||||
- POSTGRES_USER=${POSTGRES_USER}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-meme} -d ${POSTGRES_DB:-meme_wrangler}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 5s
|
||||
|
||||
meme-wrangler:
|
||||
build: .
|
||||
container_name: meme-wrangler
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- postgres
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
|
||||
- OWNER_ID=${OWNER_ID}
|
||||
|
||||
Reference in New Issue
Block a user