add services
Some checks failed
deploy misc services / deploy (push) Failing after 0s

This commit is contained in:
Elias Ahokas
2025-11-24 20:05:49 +02:00
commit b6e94fa231
7 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
name: deploy misc services
on:
push:
branches: [main]
workflow_dispatch:
jobs:
deploy:
runs-on: z420
steps:
- name: deploy
run: |
cd /home/sirian/services/misc
git pull origin main
docker compose build
docker compose up -d --remove-orphans

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
secrets/bot_token.txt

12
README.md Normal file
View File

@@ -0,0 +1,12 @@
# Z420 Misc Stack
Miscellaneous services for z420.
## Services
- Telegram Bot
## Setup
1. Copy bot token: `cp secrets/bot_token.txt.example secrets/bot_token.txt`
2. Edit token
3. Deploy: `docker compose up -d`

13
docker-compose.yml Normal file
View File

@@ -0,0 +1,13 @@
services:
telegram-bot:
build: ./telegram_bot
container_name: telegram-bot
volumes:
- /mnt/piratointi/tv_media/channel3:/app/media_folder
secrets:
- bot_token
restart: unless-stopped
secrets:
bot_token:
file: ./secrets/bot_token.txt

View File

@@ -0,0 +1 @@
place your token here

8
telegram_bot/Dockerfile Normal file
View File

@@ -0,0 +1,8 @@
FROM python:3.11-slim
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir python-telegram-bot
CMD ["python", "bot.py"]

23
telegram_bot/bot.py Normal file
View File

@@ -0,0 +1,23 @@
import os
from telegram import Update
from telegram.ext import ApplicationBuilder, MessageHandler, filters, ContextTypes
with open("/run/secrets/bot_token", 'r') as f:
BOT_TOKEN = f.read().strip()
SAVE_FOLDER = "/app/media_folder"
async def media_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.message.photo:
file = await update.message.photo[-1].get_file()
filename = os.path.join(SAVE_FOLDER, f"{file.file_unique_id}.jpg")
await file.download_to_drive(filename)
elif update.message.video:
file = await update.message.video.get_file()
filename = os.path.join(SAVE_FOLDER, f"{file.file_unique_id}.mp4")
await file.download_to_drive(filename)
if __name__ == "__main__":
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(MessageHandler(filters.PHOTO | filters.VIDEO, media_handler))
app.run_polling()