Run local Telegram Bot API in app container

This commit is contained in:
Your Name
2026-07-22 20:33:35 +05:00
parent 247593ece2
commit 313d5e3cf4
3 changed files with 52 additions and 0 deletions
+2
View File
@@ -17,6 +17,8 @@ VK_STORAGE_GROUP_ID=239548476
TG_BOT_TOKEN=
TG_MEDIA_CHANNEL_ID=
LOCAL_BOT_API_URL=
TELEGRAM_API_ID=
TELEGRAM_API_HASH=
ADMIN_HOST=0.0.0.0
ADMIN_PORT=8080
+20
View File
@@ -1,3 +1,5 @@
FROM aiogram/telegram-bot-api:latest AS telegram-bot-api
FROM python:3.12-slim
WORKDIR /app
@@ -10,6 +12,15 @@ RUN apt-get update && apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy the local Telegram Bot API binary and its musl runtime from the official aiogram image.
COPY --from=telegram-bot-api /usr/local/bin/telegram-bot-api /usr/local/bin/telegram-bot-api
COPY --from=telegram-bot-api /lib/ld-musl-x86_64.so.1 /lib/ld-musl-x86_64.so.1
COPY --from=telegram-bot-api /usr/lib/libssl.so.3 /usr/lib/libssl.so.3
COPY --from=telegram-bot-api /usr/lib/libcrypto.so.3 /usr/lib/libcrypto.so.3
COPY --from=telegram-bot-api /usr/lib/libz.so.1 /usr/lib/libz.so.1
COPY --from=telegram-bot-api /usr/lib/libstdc++.so.6 /usr/lib/libstdc++.so.6
COPY --from=telegram-bot-api /usr/lib/libgcc_s.so.1 /usr/lib/libgcc_s.so.1
# Install python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
@@ -17,14 +28,23 @@ RUN pip install --no-cache-dir -r requirements.txt
# Copy source code
COPY src/ src/
COPY scripts/ scripts/
COPY docker-entrypoint.sh /usr/local/bin/vk-parser-entrypoint
RUN chmod +x /usr/local/bin/vk-parser-entrypoint \
&& mkdir -p /var/lib/telegram-bot-api /tmp/telegram-bot-api
COPY favi.png .
COPY .env.example .env
ENV PYTHONPATH=/app/src
ENV PYTHONUNBUFFERED=1
ENV LOCAL_BOT_API_URL=http://127.0.0.1:8081
ENV TELEGRAM_WORK_DIR=/var/lib/telegram-bot-api
ENV TELEGRAM_TEMP_DIR=/tmp/telegram-bot-api
ENV TELEGRAM_HTTP_PORT=8081
ENV TELEGRAM_LOCAL=1
EXPOSE 8000
# Start uvicorn without any workers
ENTRYPOINT ["vk-parser-entrypoint"]
CMD ["uvicorn", "vk_parser_app.admin:app", "--host", "0.0.0.0", "--port", "8000"]
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env sh
set -eu
tg_pid=""
stop_children() {
if [ -n "$tg_pid" ] && kill -0 "$tg_pid" 2>/dev/null; then
kill "$tg_pid"
wait "$tg_pid" 2>/dev/null || true
fi
}
trap stop_children INT TERM EXIT
if [ -n "${TELEGRAM_API_ID:-}" ] && [ -n "${TELEGRAM_API_HASH:-}" ]; then
mkdir -p "${TELEGRAM_WORK_DIR:-/var/lib/telegram-bot-api}" "${TELEGRAM_TEMP_DIR:-/tmp/telegram-bot-api}"
telegram-bot-api \
--api-id="${TELEGRAM_API_ID}" \
--api-hash="${TELEGRAM_API_HASH}" \
--dir="${TELEGRAM_WORK_DIR:-/var/lib/telegram-bot-api}" \
--temp-dir="${TELEGRAM_TEMP_DIR:-/tmp/telegram-bot-api}" \
--http-port="${TELEGRAM_HTTP_PORT:-8081}" \
--local &
tg_pid="$!"
echo "Started local Telegram Bot API on 127.0.0.1:${TELEGRAM_HTTP_PORT:-8081}"
else
echo "TELEGRAM_API_ID/TELEGRAM_API_HASH are not set; local Telegram Bot API is disabled"
fi
exec "$@"