feat: dev/prod environment split + APPLICATION_ID + privileged intents
- .env.dev / .env.prod with separate tokens and APPLICATION_ID - Bot syncs commands to specific guild in dev mode - Global sync for production - Updated .forgejo/workflows/ci.yml with SSH deploy to prod server - Updated .gitignore for .env.dev / .env.prod
This commit is contained in:
parent
e44349cea9
commit
0bdf414540
4 changed files with 54 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
name: CI
|
name: CI/CD
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|
@ -17,8 +17,7 @@ jobs:
|
||||||
python-version: "3.12"
|
python-version: "3.12"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: pip install -r requirements.txt -r requirements-dev.txt
|
||||||
pip install -r requirements.txt -r requirements-dev.txt
|
|
||||||
|
|
||||||
- name: Ruff lint
|
- name: Ruff lint
|
||||||
run: ruff check .
|
run: ruff check .
|
||||||
|
|
@ -36,11 +35,39 @@ jobs:
|
||||||
python-version: "3.12"
|
python-version: "3.12"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: pip install -r requirements.txt -r requirements-dev.txt
|
||||||
pip install -r requirements.txt -r requirements-dev.txt
|
|
||||||
|
|
||||||
- name: Syntax check
|
- name: Syntax check
|
||||||
run: python -m py_compile bot.py && python -m py_compile vision.py && python -m py_compile config.py
|
run: |
|
||||||
|
python -m py_compile bot.py
|
||||||
|
python -m py_compile vision.py
|
||||||
|
python -m py_compile config.py
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: pytest tests/ -v || true
|
run: pytest tests/ -v || true
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
needs: [lint, test]
|
||||||
|
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Deploy to production server
|
||||||
|
uses: appleboy/ssh-action@v1
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.PROD_HOST }}
|
||||||
|
username: ${{ secrets.PROD_USER }}
|
||||||
|
password: ${{ secrets.PROD_PASSWORD }}
|
||||||
|
script: |
|
||||||
|
cd /home/discord/Bots/VisionApp
|
||||||
|
git pull origin main --rebase
|
||||||
|
if command -v docker &>/dev/null; then
|
||||||
|
docker compose build --no-cache vision
|
||||||
|
docker compose up -d vision
|
||||||
|
else
|
||||||
|
pkill -f "python.*vision\.py" 2>/dev/null || true
|
||||||
|
source venv/bin/activate
|
||||||
|
pip install -r requirements.txt
|
||||||
|
nohup python vision.py > /dev/null 2>&1 &
|
||||||
|
fi
|
||||||
|
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,5 +1,7 @@
|
||||||
# --- SÉCURITÉ ---
|
# --- SÉCURITÉ ---
|
||||||
.env
|
.env
|
||||||
|
.env.dev
|
||||||
|
.env.prod
|
||||||
|
|
||||||
# --- PYTHON ---
|
# --- PYTHON ---
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
|
||||||
20
bot.py
20
bot.py
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
@ -6,6 +7,8 @@ import config
|
||||||
|
|
||||||
logger = logging.getLogger("vision")
|
logger = logging.getLogger("vision")
|
||||||
|
|
||||||
|
DEV_GUILD_IDS = [int(x) for x in os.getenv("DEV_GUILD_IDS", "").split(",") if x.strip()]
|
||||||
|
|
||||||
|
|
||||||
class VisionBot(commands.Bot):
|
class VisionBot(commands.Bot):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -22,13 +25,22 @@ class VisionBot(commands.Bot):
|
||||||
async def setup_hook(self):
|
async def setup_hook(self):
|
||||||
logger.info("Chargement des cogs...")
|
logger.info("Chargement des cogs...")
|
||||||
await self.load_extension("commandes.hello")
|
await self.load_extension("commandes.hello")
|
||||||
logger.info("Sync des slash commands...")
|
|
||||||
|
if config.DEV and DEV_GUILD_IDS:
|
||||||
|
logger.info(f"Mode DEV — sync des commands sur les guilds: {DEV_GUILD_IDS}")
|
||||||
|
for guild_id in DEV_GUILD_IDS:
|
||||||
|
self.tree.copy_global_to(guild=guild_id)
|
||||||
|
await self.tree.sync(guild=guild_id)
|
||||||
|
logger.info(f" ✓ Sync guild {guild_id}")
|
||||||
|
else:
|
||||||
|
logger.info("Mode PROD — sync global des slash commands...")
|
||||||
await self.tree.sync()
|
await self.tree.sync()
|
||||||
logger.info("Slash commands synchronisées")
|
logger.info("Slash commands synchronisées (global)")
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
logger.info(f"Connecté en tant que {self.user} (ID: {self.user.id})")
|
instance = "DEV" if config.DEV else "PROD"
|
||||||
logger.info(f"Serveurs : {len(self.guilds)}")
|
logger.info(f"[{instance}] Connecté en tant que {self.user} (ID: {self.user.id})")
|
||||||
|
logger.info(f"[{instance}] Serveurs : {len(self.guilds)}")
|
||||||
await self.change_presence(
|
await self.change_presence(
|
||||||
activity=discord.Activity(
|
activity=discord.Activity(
|
||||||
type=discord.ActivityType.watching,
|
type=discord.ActivityType.watching,
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ import sys
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from bot import VisionBot
|
from bot import VisionBot
|
||||||
|
|
||||||
|
|
@ -26,7 +24,8 @@ async def main():
|
||||||
logger.critical("DISCORD_TOKEN manquant dans .env")
|
logger.critical("DISCORD_TOKEN manquant dans .env")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logger.info("Lancement de Vision Studio...")
|
instance = "DEV" if config.DEV else "PROD"
|
||||||
|
logger.info(f"Lancement de Vision Studio [{instance}]...")
|
||||||
bot = VisionBot()
|
bot = VisionBot()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue