Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json
.idea
*.iml
out
gen
*.zwc
*.zwc.old
*zcompdump*
.zsh_history
.zsh_sessions
.zcalc_history
._zinit
.zinit_lstupd
zsdoc/data
.directory_history
/tests/_output/*
!/tests/_output/.gitkeep
__pycache__/
*.py[cod]
*$py.class
*.so
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
Comment thread
anvaari marked this conversation as resolved.
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
*.manifest
*.spec
pip-log.txt
pip-delete-this-directory.txt
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
*.mo
*.pot
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
instance/
.webassets-cache
.scrapy
docs/_build/
.pybuilder/
target/
.ipynb_checkpoints
profile_default/
ipython_config.py
.pdm.toml
__pypackages__/
celerybeat-schedule
celerybeat.pid
*.sage.py
.env
env/
venv/
ENV/
env.bak/
venv.bak/
.spyderproject
.spyproject
.ropeproject
/site
.mypy_cache/
.dmypy.json
dmypy.json
.pyre/
.pytype/
cython_debug/
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Bot Configuration
BOT_TOKEN=your_telegram_bot_token_here
DATABASE_NAME=playlist.db
ADD_TRACK_TIME_WINDOW=60
LOG_LEVEL=INFO

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we need LOG_FILE here


# GitHub Actions Secrets (set these in repository settings > Secrets and variables > Actions)
# DOCKER_USERNAME=your_docker_hub_username
# DOCKER_PASSWORD=your_docker_hub_password_or_token
# SERVER_HOST=your_server_ip_or_hostname
# SERVER_USER=your_server_ssh_username
# SERVER_SSH_KEY=your_private_ssh_key_content
102 changes: 102 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: CI/CD Pipeline

on:
push:
branches: [ main ]
tags:
- "v*.*.*"
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
run: |
docker buildx build --platform linux/amd64 -t bilbomusicbot:latest --load .

- name: Test Docker image
run: |
docker run --rm -e BOT_TOKEN=${{ secrets.BOT_TOKEN }} bilbomusicbot:latest python -c "
try:
import bot
print('Bot module imported successfully')
except Exception as e:
print(f'Import failed: {e}')
exit(1)
"
Comment thread
anvaari marked this conversation as resolved.

release:
needs: build
runs-on: ubuntu-latest
environment: prod
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# if your server support ssh key use this format
# key: ${{ secrets.SERVER_SSH_KEY }}

- name: Build and push Docker image
run: |
docker buildx build --platform linux/amd64,linux/arm64 \
-t ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:latest \
-t ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:${{ github.ref_name }} \
--push .

- name: Copy docker-compose.yml to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_SSH_KEY }}
source: "docker-compose.yml"
target: "/opt/bilbomusicbot/"

Comment on lines +64 to +72

@coderabbitai coderabbitai Bot Aug 22, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Incorrect credential field for SCP: use key, not password; ensure target dir exists first

You’re passing an SSH private key via the password field, which won’t work. Also, ensure /opt/bilbomusicbot exists before scp.

Apply:

-    - name: Copy docker-compose.yml to server
-      uses: appleboy/scp-action@v0.1.7
-      with:
-        host: ${{ secrets.SERVER_HOST }}
-        username: ${{ secrets.SERVER_USER }}
-        password: ${{ secrets.SERVER_SSH_KEY }}
-        source: "docker-compose.yml"
-        target: "/opt/bilbomusicbot/"
+    - name: Prepare server for deployment
+      uses: appleboy/ssh-action@v1.0.3
+      with:
+        host: ${{ secrets.SERVER_HOST }}
+        username: ${{ secrets.SERVER_USER }}
+        key: ${{ secrets.SERVER_SSH_KEY }}
+        script: |
+          mkdir -p /opt/bilbomusicbot
+          docker pull ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:latest
+
+    - name: Copy docker-compose.yml to server
+      uses: appleboy/scp-action@v0.1.7
+      with:
+        host: ${{ secrets.SERVER_HOST }}
+        username: ${{ secrets.SERVER_USER }}
+        key: ${{ secrets.SERVER_SSH_KEY }}
+        source: "docker-compose.yml"
+        target: "/opt/bilbomusicbot/"

Note: This reorders steps so the directory exists before SCP and fixes the credential field.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Copy docker-compose.yml to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_SSH_KEY }}
source: "docker-compose.yml"
target: "/opt/bilbomusicbot/"
- name: Prepare server for deployment
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
mkdir -p /opt/bilbomusicbot
docker pull ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:latest
- name: Copy docker-compose.yml to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: "docker-compose.yml"
target: "/opt/bilbomusicbot/"
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 72-72: trailing spaces

(trailing-spaces)

🤖 Prompt for AI Agents
In .github/workflows/ci-cd.yml around lines 64 to 72, the scp step incorrectly
supplies the SSH private key via the `password` field and runs before the remote
target directory is created; update the workflow to first ensure
/opt/bilbomusicbot exists on the server (e.g., an SSH or run step that creates
the directory with proper permissions) and then call appleboy/scp-action with
the private key passed in the `key` field (not `password`), keeping source as
"docker-compose.yml" and target "/opt/bilbomusicbot/".

@anvaari anvaari Aug 26, 2025

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Art4Man please use appleboy/scp-action@v1.0.0 and also use key instead of password. Please refer to this doc https://github.com/appleboy/scp-action

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

- name: Prepare server for deployment
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_SSH_KEY }}
script: |
mkdir -p /opt/bilbomusicbot
cd /opt/bilbomusicbot
docker pull ${{ secrets.DOCKER_USERNAME }}/bilbomusicbot:latest

Comment thread
anvaari marked this conversation as resolved.
deploy:
needs: release
runs-on: ubuntu-latest
environment: prod
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Deploy to server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_SSH_KEY }}
script: |
Comment thread
anvaari marked this conversation as resolved.
cd /opt/bilbomusicbot
export DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}
export BOT_TOKEN=${{ secrets.BOT_TOKEN }}
docker compose down
docker compose up -d
docker system prune -f
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.13-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python", "bot.py"]
Comment on lines +5 to +11

@coderabbitai coderabbitai Bot Aug 22, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Run as non-root and add Python runtime envs

Running as root is risky in production. Also consider standard Python envs to reduce noise and improve logging behavior.

 FROM python:3.13-slim

 WORKDIR /app

+ENV PYTHONDONTWRITEBYTECODE=1 \
+    PYTHONUNBUFFERED=1
+
 COPY requirements.txt .
 
 RUN pip install --no-cache-dir -r requirements.txt
 
 COPY . .
 
-CMD ["python", "bot.py"]
+# Create non-root user and switch
+RUN addgroup --system app && adduser --system --ingroup app app && \
+    chown -R app:app /app
+USER app
+
+CMD ["python", "bot.py"]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "bot.py"]
FROM python:3.13-slim
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Create non-root user and switch
RUN addgroup --system app && adduser --system --ingroup app app && \
chown -R app:app /app
USER app
CMD ["python", "bot.py"]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Art4Man Also please consider this suggestion.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this great PR @Art4Man .
But we need to set all variables in .env.example as environment variables in the container. I think setting them as secret is a good option

18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
bilbomusicbot:
image: ${DOCKER_USERNAME}/bilbomusicbot:latest
container_name: bilbomusicbot
restart: unless-stopped
environment:
- BOT_TOKEN=${BOT_TOKEN}
volumes:
- ./data:/app/data

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't data folder. It's better to mount log directory

networks:
- bilbonet

networks:
bilbonet:
driver: bridge

volumes:
data: