mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Implement real, working microservices architecture
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# Account Service Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy service-specific files
|
||||
COPY backend/routes/account.py /app/backend/routes/account.py
|
||||
COPY backend/services/account/main.py /app/backend/services/account/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=account
|
||||
|
||||
EXPOSE 8301
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from backend.routes.account import router as account_router
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = FastAPI(title="Account Service")
|
||||
app.include_router(account_router, prefix="/account")
|
||||
|
||||
import os, uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8301)))
|
||||
@@ -0,0 +1,11 @@
|
||||
# Device Service Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy service-specific files
|
||||
COPY backend/routes/devices.py /app/backend/routes/devices.py
|
||||
COPY backend/services/device/main.py /app/backend/services/device/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=device
|
||||
|
||||
EXPOSE 8301
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from backend.routes.devices import router as device_router
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = FastAPI(title="Device Service")
|
||||
app.include_router(device_router, prefix="/devices")
|
||||
|
||||
import os, uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8301)))
|
||||
@@ -0,0 +1,14 @@
|
||||
# Gateway Service Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy service-specific files
|
||||
COPY backend/app.py /app/backend/app.py
|
||||
COPY backend/main.py /app/backend/main.py
|
||||
COPY backend/dependencies.py /app/backend/dependencies.py
|
||||
COPY backend/security /app/backend/security/
|
||||
COPY backend/services/gateway/main.py /app/backend/services/gateway/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=gateway
|
||||
|
||||
EXPOSE 8301
|
||||
@@ -0,0 +1,10 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
# Gateway service - handles complex operations that Caddy cannot
|
||||
# This will be expanded later with routing logic to other services
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = FastAPI(title="Gateway Service")
|
||||
|
||||
import os, uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8301)))
|
||||
@@ -0,0 +1,12 @@
|
||||
# Messaging Service Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy service-specific files
|
||||
COPY backend/routes/messaging.py /app/backend/routes/messaging.py
|
||||
COPY backend/websocket /app/backend/websocket/
|
||||
COPY backend/services/messaging/main.py /app/backend/services/messaging/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=messaging
|
||||
|
||||
EXPOSE 8301
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from backend.routes.messaging import router as messaging_router
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = FastAPI(title="Messaging Service")
|
||||
app.include_router(messaging_router, prefix="/messaging")
|
||||
|
||||
import os, uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8301)))
|
||||
@@ -0,0 +1,15 @@
|
||||
# Migration Runner Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy migration files
|
||||
COPY backend/alembic /app/backend/alembic/
|
||||
COPY backend/migration.py /app/backend/migration.py
|
||||
|
||||
# Copy migration runner
|
||||
COPY backend/services/migration_runner/main.py /app/backend/services/migration_runner/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=migration_runner
|
||||
|
||||
# Override entrypoint to run migrations
|
||||
ENTRYPOINT ["python", "-m", "backend.services.migration_runner.main"]
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Migration runner service - executes database migrations and exits.
|
||||
This service runs Alembic migrations against PostgreSQL and terminates.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
|
||||
def run_migrations():
|
||||
"""Run Alembic migrations."""
|
||||
print("Starting database migrations...")
|
||||
|
||||
# Change to backend directory to run migrations
|
||||
backend_dir = Path(__file__).parent.parent.parent
|
||||
os.chdir(backend_dir)
|
||||
|
||||
# Ensure shared models are imported for alembic
|
||||
import backend.shared.models
|
||||
|
||||
# Set DATABASE_URL from environment if not set
|
||||
db_url = os.getenv("DATABASE_URL")
|
||||
if not db_url:
|
||||
print("ERROR: DATABASE_URL environment variable not set")
|
||||
sys.exit(1)
|
||||
|
||||
# Export DATABASE_URL for alembic
|
||||
os.environ["DATABASE_URL"] = db_url
|
||||
|
||||
try:
|
||||
# Use the robust migration system from migration.py
|
||||
# This handles all edge cases and recovery scenarios automatically
|
||||
print("Starting database migrations...")
|
||||
|
||||
# Import and run the migration function
|
||||
from backend.migration import run_migrations
|
||||
run_migrations()
|
||||
|
||||
print("Database migrations completed successfully!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to run migrations: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_migrations()
|
||||
@@ -0,0 +1,13 @@
|
||||
# Moderation Service Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy service-specific files
|
||||
COPY backend/routes/moderation.py /app/backend/routes/moderation.py
|
||||
COPY backend/security/profanity.py /app/backend/security/profanity.py
|
||||
COPY backend/similarity.py /app/backend/similarity.py
|
||||
COPY backend/services/moderation/main.py /app/backend/services/moderation/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=moderation
|
||||
|
||||
EXPOSE 8301
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from backend.routes.moderation import router as moderation_router
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = FastAPI(title="Moderation Service")
|
||||
app.include_router(moderation_router, prefix="/moderation")
|
||||
|
||||
import os, uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8301)))
|
||||
@@ -0,0 +1,11 @@
|
||||
# Profile Service Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy service-specific files
|
||||
COPY backend/routes/profile.py /app/backend/routes/profile.py
|
||||
COPY backend/services/profile/main.py /app/backend/services/profile/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=profile
|
||||
|
||||
EXPOSE 8301
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from backend.routes.profile import router as profile_router
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = FastAPI(title="Profile Service")
|
||||
app.include_router(profile_router, prefix="/profile")
|
||||
|
||||
import os, uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8301)))
|
||||
@@ -0,0 +1,12 @@
|
||||
# Push Service Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy service-specific files
|
||||
COPY backend/routes/push.py /app/backend/routes/push.py
|
||||
COPY backend/push_service.py /app/backend/push_service.py
|
||||
COPY backend/services/push/main.py /app/backend/services/push/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=push
|
||||
|
||||
EXPOSE 8301
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from backend.routes.push import router as push_router
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = FastAPI(title="Push Service")
|
||||
app.include_router(push_router, prefix="/push")
|
||||
|
||||
import os, uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8301)))
|
||||
@@ -0,0 +1,11 @@
|
||||
# WebRTC Service Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy service-specific files
|
||||
COPY backend/routes/webrtc.py /app/backend/routes/webrtc.py
|
||||
COPY backend/services/webrtc/main.py /app/backend/services/webrtc/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=webrtc
|
||||
|
||||
EXPOSE 8301
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from backend.routes.webrtc import router as webrtc_router
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = FastAPI(title="WebRTC Service")
|
||||
app.include_router(webrtc_router, prefix="/webrtc")
|
||||
|
||||
import os, uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8301)))
|
||||
Reference in New Issue
Block a user