fix: deployment — resolve dependency conflicts, add initial migration, CI/CD webhook
- Fix httpx/pydantic/redis version conflicts for litellm/aiogram/celery compatibility - Add PYTHONPATH=/app to Dockerfile for alembic module resolution - Skip Telegram webhook setup when URL is not HTTPS - Fix FileUpload prop type mismatch in RecordingsPage - Add alembic script.py.mako template and initial migration - Configure docker-compose: port 8081, built frontend, no exposed internal ports - Add deploy.sh and webhook-server.js for Gitea CI/CD auto-deploy Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ FROM nvidia/cuda:12.4.1-runtime-ubuntu22.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV PYTHONPATH=/app
|
||||
|
||||
# System dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = ${repr(up_revision)}
|
||||
down_revision: Union[str, None] = ${repr(down_revision)}
|
||||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
||||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,111 @@
|
||||
"""initial
|
||||
|
||||
Revision ID: a7d968fceaaf
|
||||
Revises:
|
||||
Create Date: 2026-04-06 17:59:05.406839
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'a7d968fceaaf'
|
||||
down_revision: Union[str, None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('prompt_templates',
|
||||
sa.Column('name', sa.String(length=255), nullable=False),
|
||||
sa.Column('description', sa.String(length=1000), nullable=False),
|
||||
sa.Column('type', sa.Enum('client_survey', 'client_intro', 'internal', 'custom', name='templatetype'), nullable=False),
|
||||
sa.Column('system_prompt', sa.Text(), nullable=False),
|
||||
sa.Column('user_prompt', sa.Text(), nullable=False),
|
||||
sa.Column('output_schema', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
|
||||
sa.Column('is_default', sa.Boolean(), nullable=False),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('users',
|
||||
sa.Column('username', sa.String(length=150), nullable=False),
|
||||
sa.Column('email', sa.String(length=255), nullable=False),
|
||||
sa.Column('password_hash', sa.String(length=255), nullable=False),
|
||||
sa.Column('role', sa.Enum('admin', 'user', name='userrole'), nullable=False),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=False),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
||||
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
|
||||
op.create_table('recordings',
|
||||
sa.Column('user_id', sa.Uuid(), nullable=False),
|
||||
sa.Column('title', sa.String(length=500), nullable=False),
|
||||
sa.Column('file_path', sa.String(length=1000), nullable=False),
|
||||
sa.Column('file_size', sa.BigInteger(), nullable=False),
|
||||
sa.Column('duration', sa.Float(), nullable=True),
|
||||
sa.Column('format', sa.String(length=20), nullable=False),
|
||||
sa.Column('source', sa.Enum('web', 'telegram', 'lensa', name='recordingsource'), nullable=False),
|
||||
sa.Column('status', sa.Enum('uploaded', 'processing', 'done', 'error', name='recordingstatus'), nullable=False),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('transcriptions',
|
||||
sa.Column('recording_id', sa.Uuid(), nullable=False),
|
||||
sa.Column('text', sa.Text(), nullable=False),
|
||||
sa.Column('segments', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
|
||||
sa.Column('language', sa.String(length=10), nullable=True),
|
||||
sa.Column('whisper_model', sa.String(length=50), nullable=False),
|
||||
sa.Column('processing_time', sa.Float(), nullable=True),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['recording_id'], ['recordings.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('recording_id')
|
||||
)
|
||||
op.create_table('protocols',
|
||||
sa.Column('transcription_id', sa.Uuid(), nullable=False),
|
||||
sa.Column('template_id', sa.Uuid(), nullable=False),
|
||||
sa.Column('content', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
|
||||
sa.Column('raw_text', sa.Text(), nullable=False),
|
||||
sa.Column('llm_model', sa.String(length=100), nullable=False),
|
||||
sa.Column('status', sa.Enum('generating', 'done', 'error', name='protocolstatus'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['template_id'], ['prompt_templates.id'], ),
|
||||
sa.ForeignKeyConstraint(['transcription_id'], ['transcriptions.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('export_files',
|
||||
sa.Column('protocol_id', sa.Uuid(), nullable=False),
|
||||
sa.Column('format', sa.Enum('docx', 'pdf', 'md', name='exportformat'), nullable=False),
|
||||
sa.Column('file_path', sa.String(length=1000), nullable=False),
|
||||
sa.Column('file_size', sa.BigInteger(), nullable=False),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['protocol_id'], ['protocols.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('export_files')
|
||||
op.drop_table('protocols')
|
||||
op.drop_table('transcriptions')
|
||||
op.drop_table('recordings')
|
||||
op.drop_index(op.f('ix_users_username'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_email'), table_name='users')
|
||||
op.drop_table('users')
|
||||
op.drop_table('prompt_templates')
|
||||
# ### end Alembic commands ###
|
||||
+2
-2
@@ -30,10 +30,10 @@ async def seed_default_templates():
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
await seed_default_templates()
|
||||
if settings.telegram_bot_token:
|
||||
if settings.telegram_bot_token and settings.telegram_webhook_url.startswith("https"):
|
||||
await telegram_service.setup()
|
||||
yield
|
||||
if settings.telegram_bot_token:
|
||||
if settings.telegram_bot_token and settings.telegram_webhook_url.startswith("https"):
|
||||
await telegram_service.shutdown()
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ psycopg2-binary==2.9.10
|
||||
alembic==1.14.1
|
||||
|
||||
# Validation
|
||||
pydantic==2.10.4
|
||||
pydantic>=2.7.0,<2.10
|
||||
pydantic-settings==2.7.1
|
||||
|
||||
# Auth
|
||||
@@ -19,7 +19,7 @@ python-jose[cryptography]==3.3.0
|
||||
|
||||
# Task queue
|
||||
celery[redis]==5.4.0
|
||||
redis==5.2.1
|
||||
redis==4.6.0
|
||||
|
||||
# AI/ML
|
||||
faster-whisper==1.1.0
|
||||
@@ -36,10 +36,10 @@ markdown==3.7
|
||||
|
||||
# Utils
|
||||
ffmpeg-python==0.2.0
|
||||
httpx==0.28.1
|
||||
httpx>=0.23.0,<0.28.0
|
||||
aiofiles==24.1.0
|
||||
|
||||
# Testing
|
||||
pytest==8.3.4
|
||||
pytest-asyncio==0.25.0
|
||||
httpx==0.28.1
|
||||
httpx>=0.23.0,<0.28.0
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
# Auto-deploy script triggered by Gitea webhook
|
||||
set -e
|
||||
|
||||
DEPLOY_DIR="D:/meeting-protocol-service"
|
||||
LOG_FILE="$DEPLOY_DIR/deploy.log"
|
||||
|
||||
echo "$(date) - Deploy started" >> "$LOG_FILE"
|
||||
|
||||
cd "$DEPLOY_DIR"
|
||||
|
||||
# Pull latest changes
|
||||
git pull origin main >> "$LOG_FILE" 2>&1
|
||||
|
||||
# Rebuild and restart services
|
||||
docker compose up -d --build >> "$LOG_FILE" 2>&1
|
||||
|
||||
echo "$(date) - Deploy completed" >> "$LOG_FILE"
|
||||
+7
-9
@@ -2,8 +2,8 @@ services:
|
||||
app:
|
||||
build: ./backend
|
||||
env_file: .env
|
||||
ports:
|
||||
- "8000:8000"
|
||||
expose:
|
||||
- "8000"
|
||||
volumes:
|
||||
- uploads:/app/uploads
|
||||
- exports:/app/exports
|
||||
@@ -12,6 +12,7 @@ services:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
working_dir: /app
|
||||
command: >
|
||||
sh -c "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000"
|
||||
|
||||
@@ -45,8 +46,6 @@ services:
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
ports:
|
||||
- "6379:6379"
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
@@ -57,7 +56,7 @@ services:
|
||||
image: postgres:16-alpine
|
||||
env_file: .env
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- "5433:5432"
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
@@ -66,13 +65,12 @@ services:
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
frontend:
|
||||
build: ./frontend
|
||||
ports:
|
||||
- "80:80"
|
||||
- "8081:80"
|
||||
volumes:
|
||||
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./frontend/dist:/usr/share/nginx/html
|
||||
depends_on:
|
||||
- app
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export default function RecordingsPage() {
|
||||
<h1 className="text-2xl font-bold">Записи</h1>
|
||||
</div>
|
||||
<div className="mb-6 bg-white p-4 rounded-lg shadow-sm">
|
||||
<FileUpload onUpload={upload} isUploading={isUploading} />
|
||||
<FileUpload onUpload={(file, title) => upload({ file, title })} isUploading={isUploading} />
|
||||
</div>
|
||||
{isLoading ? (
|
||||
<p>Загрузка...</p>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
const http = require('http');
|
||||
const { execFile } = require('child_process');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const PORT = 9000;
|
||||
const SECRET = 'meeting-proto-deploy-secret';
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
if (req.method !== 'POST' || req.url !== '/deploy') {
|
||||
res.writeHead(404);
|
||||
res.end('Not found');
|
||||
return;
|
||||
}
|
||||
|
||||
let body = '';
|
||||
req.on('data', chunk => { body += chunk; });
|
||||
req.on('end', () => {
|
||||
// Verify Gitea signature
|
||||
const sig = req.headers['x-gitea-signature'];
|
||||
if (sig) {
|
||||
const hmac = crypto.createHmac('sha256', SECRET).update(body).digest('hex');
|
||||
if (sig !== hmac) {
|
||||
console.log(`${new Date().toISOString()} - Invalid signature, rejecting`);
|
||||
res.writeHead(403);
|
||||
res.end('Invalid signature');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`${new Date().toISOString()} - Deploy triggered`);
|
||||
res.writeHead(200);
|
||||
res.end('Deploy started');
|
||||
|
||||
execFile('bash', ['D:/meeting-protocol-service/deploy.sh'], (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
console.error(`Deploy error: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
console.log(`Deploy output: ${stdout}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Webhook server listening on port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user