superbrain-server 1.0.49 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/superbrain.js +204 -204
- package/package.json +1 -1
- package/payload/.env.example +58 -58
- package/payload/Dockerfile +73 -73
- package/payload/docker-compose.yml +124 -124
- package/payload/start-docker-prod.sh +125 -125
- package/payload/start-docker.sh +56 -56
- package/payload/stop-docker.sh +16 -16
package/payload/Dockerfile
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
2
|
-
# Multi-stage build for optimized image size
|
|
3
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
|
|
5
|
-
FROM python:3.11-slim as builder
|
|
6
|
-
|
|
7
|
-
WORKDIR /app
|
|
8
|
-
|
|
9
|
-
# Install system build dependencies
|
|
10
|
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
11
|
-
gcc \
|
|
12
|
-
&& rm -rf /var/lib/apt/lists/*
|
|
13
|
-
|
|
14
|
-
# Copy requirements
|
|
15
|
-
COPY requirements.txt .
|
|
16
|
-
|
|
17
|
-
# Build dependencies in separate layer
|
|
18
|
-
RUN pip install --user --no-cache-dir -r requirements.txt
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
22
|
-
# Final production image
|
|
23
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
24
|
-
|
|
25
|
-
FROM python:3.11-slim
|
|
26
|
-
|
|
27
|
-
LABEL maintainer="SuperBrain <sidinsearch@gmail.com>"
|
|
28
|
-
LABEL description="SuperBrain API - AI-powered content analysis and archival"
|
|
29
|
-
LABEL version="1.0.0"
|
|
30
|
-
|
|
31
|
-
WORKDIR /app
|
|
32
|
-
|
|
33
|
-
# ──── Install runtime dependencies only ────
|
|
34
|
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
35
|
-
ffmpeg \
|
|
36
|
-
libmagic1 \
|
|
37
|
-
libgl1-mesa-glx \
|
|
38
|
-
libglib2.0-0 \
|
|
39
|
-
curl \
|
|
40
|
-
&& rm -rf /var/lib/apt/lists/*
|
|
41
|
-
|
|
42
|
-
# ──── Copy Python dependencies from builder ────
|
|
43
|
-
COPY --from=builder /root/.local /root/.local
|
|
44
|
-
|
|
45
|
-
# ──── Set environment variables ────
|
|
46
|
-
ENV PATH=/root/.local/bin:$PATH \
|
|
47
|
-
PYTHONUNBUFFERED=1 \
|
|
48
|
-
PYTHONDONTWRITEBYTECODE=1 \
|
|
49
|
-
ENVIRONMENT=production \
|
|
50
|
-
WORKERS=2
|
|
51
|
-
|
|
52
|
-
# ──── Copy application code ────
|
|
53
|
-
COPY . .
|
|
54
|
-
|
|
55
|
-
# ──── Create necessary directories with proper permissions ────
|
|
56
|
-
RUN mkdir -p temp config static logs data && \
|
|
57
|
-
chmod 755 temp config static logs data
|
|
58
|
-
|
|
59
|
-
# ──── Health check ────
|
|
60
|
-
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
61
|
-
CMD curl -f http://localhost:5000/health || exit 1
|
|
62
|
-
|
|
63
|
-
# ──── Run as non-root user for security ────
|
|
64
|
-
RUN useradd -m -u 1000 appuser && \
|
|
65
|
-
chown -R appuser:appuser /app
|
|
66
|
-
|
|
67
|
-
USER appuser
|
|
68
|
-
|
|
69
|
-
# ──── Expose port ────
|
|
70
|
-
EXPOSE 5000
|
|
71
|
-
|
|
72
|
-
# ──── Run the application ────
|
|
73
|
-
CMD ["sh", "-c", "python -m uvicorn api:app --host 0.0.0.0 --port 5000 --workers ${WORKERS:-2} --loop uvloop --no-access-log"]
|
|
1
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
# Multi-stage build for optimized image size
|
|
3
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
FROM python:3.11-slim as builder
|
|
6
|
+
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
|
|
9
|
+
# Install system build dependencies
|
|
10
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
11
|
+
gcc \
|
|
12
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
13
|
+
|
|
14
|
+
# Copy requirements
|
|
15
|
+
COPY requirements.txt .
|
|
16
|
+
|
|
17
|
+
# Build dependencies in separate layer
|
|
18
|
+
RUN pip install --user --no-cache-dir -r requirements.txt
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
22
|
+
# Final production image
|
|
23
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
FROM python:3.11-slim
|
|
26
|
+
|
|
27
|
+
LABEL maintainer="SuperBrain <sidinsearch@gmail.com>"
|
|
28
|
+
LABEL description="SuperBrain API - AI-powered content analysis and archival"
|
|
29
|
+
LABEL version="1.0.0"
|
|
30
|
+
|
|
31
|
+
WORKDIR /app
|
|
32
|
+
|
|
33
|
+
# ──── Install runtime dependencies only ────
|
|
34
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
35
|
+
ffmpeg \
|
|
36
|
+
libmagic1 \
|
|
37
|
+
libgl1-mesa-glx \
|
|
38
|
+
libglib2.0-0 \
|
|
39
|
+
curl \
|
|
40
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
41
|
+
|
|
42
|
+
# ──── Copy Python dependencies from builder ────
|
|
43
|
+
COPY --from=builder /root/.local /root/.local
|
|
44
|
+
|
|
45
|
+
# ──── Set environment variables ────
|
|
46
|
+
ENV PATH=/root/.local/bin:$PATH \
|
|
47
|
+
PYTHONUNBUFFERED=1 \
|
|
48
|
+
PYTHONDONTWRITEBYTECODE=1 \
|
|
49
|
+
ENVIRONMENT=production \
|
|
50
|
+
WORKERS=2
|
|
51
|
+
|
|
52
|
+
# ──── Copy application code ────
|
|
53
|
+
COPY . .
|
|
54
|
+
|
|
55
|
+
# ──── Create necessary directories with proper permissions ────
|
|
56
|
+
RUN mkdir -p temp config static logs data && \
|
|
57
|
+
chmod 755 temp config static logs data
|
|
58
|
+
|
|
59
|
+
# ──── Health check ────
|
|
60
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
61
|
+
CMD curl -f http://localhost:5000/health || exit 1
|
|
62
|
+
|
|
63
|
+
# ──── Run as non-root user for security ────
|
|
64
|
+
RUN useradd -m -u 1000 appuser && \
|
|
65
|
+
chown -R appuser:appuser /app
|
|
66
|
+
|
|
67
|
+
USER appuser
|
|
68
|
+
|
|
69
|
+
# ──── Expose port ────
|
|
70
|
+
EXPOSE 5000
|
|
71
|
+
|
|
72
|
+
# ──── Run the application ────
|
|
73
|
+
CMD ["sh", "-c", "python -m uvicorn api:app --host 0.0.0.0 --port 5000 --workers ${WORKERS:-2} --loop uvloop --no-access-log"]
|
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
2
|
-
# SuperBrain Production Docker Compose Configuration
|
|
3
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
|
|
5
|
-
services:
|
|
6
|
-
|
|
7
|
-
# ──── Main SuperBrain API Service ────
|
|
8
|
-
superbrain-api:
|
|
9
|
-
image: superbrain:latest
|
|
10
|
-
build:
|
|
11
|
-
context: .
|
|
12
|
-
dockerfile: Dockerfile
|
|
13
|
-
container_name: superbrain-api
|
|
14
|
-
|
|
15
|
-
# ──── Network & Ports ────
|
|
16
|
-
ports:
|
|
17
|
-
- "${API_PORT:-5000}:5000"
|
|
18
|
-
networks:
|
|
19
|
-
- superbrain-network
|
|
20
|
-
|
|
21
|
-
# ──── Environment Variables ────
|
|
22
|
-
environment:
|
|
23
|
-
PYTHONUNBUFFERED: 1
|
|
24
|
-
PYTHONDONTWRITEBYTECODE: 1
|
|
25
|
-
ENVIRONMENT: ${ENVIRONMENT:-production}
|
|
26
|
-
HOST: 0.0.0.0
|
|
27
|
-
PORT: 5000
|
|
28
|
-
WORKERS: ${WORKERS:-4}
|
|
29
|
-
LOG_LEVEL: ${LOG_LEVEL:-INFO}
|
|
30
|
-
|
|
31
|
-
# Database
|
|
32
|
-
DATABASE_PATH: /app/data/superbrain.db
|
|
33
|
-
DATABASE_TIMEOUT: 30
|
|
34
|
-
|
|
35
|
-
# API Keys (load from .env file)
|
|
36
|
-
GROQ_API_KEY: ${GROQ_API_KEY}
|
|
37
|
-
GEMINI_API_KEY: ${GEMINI_API_KEY}
|
|
38
|
-
GOOGLE_API_KEY: ${GOOGLE_API_KEY}
|
|
39
|
-
OPENROUTER_API_KEY: ${OPENROUTER_API_KEY}
|
|
40
|
-
|
|
41
|
-
# Instagram credentials
|
|
42
|
-
INSTAGRAM_USERNAME: ${INSTAGRAM_USERNAME}
|
|
43
|
-
INSTAGRAM_PASSWORD: ${INSTAGRAM_PASSWORD}
|
|
44
|
-
|
|
45
|
-
# AI Configuration
|
|
46
|
-
WHISPER_MODEL: ${WHISPER_MODEL:-base}
|
|
47
|
-
WHISPER_USE_CLOUD: ${WHISPER_USE_CLOUD:-true}
|
|
48
|
-
|
|
49
|
-
# Performance
|
|
50
|
-
MAX_UPLOAD_SIZE: ${MAX_UPLOAD_SIZE:-52428800}
|
|
51
|
-
REQUEST_TIMEOUT: ${REQUEST_TIMEOUT:-60}
|
|
52
|
-
ANALYSIS_TIMEOUT: ${ANALYSIS_TIMEOUT:-120}
|
|
53
|
-
|
|
54
|
-
# ──── Volumes ────
|
|
55
|
-
volumes:
|
|
56
|
-
# Database persistence
|
|
57
|
-
- superbrain-db:/app/data
|
|
58
|
-
# Configuration persistence
|
|
59
|
-
- superbrain-config:/app/config
|
|
60
|
-
# Temporary files
|
|
61
|
-
- superbrain-temp:/app/temp
|
|
62
|
-
# Uploads
|
|
63
|
-
- superbrain-uploads:/app/static/uploads
|
|
64
|
-
# Extracted ZIP Thumbnails
|
|
65
|
-
- superbrain-thumbnails:/app/static/thumbnails
|
|
66
|
-
# Logs
|
|
67
|
-
- superbrain-logs:/app/logs
|
|
68
|
-
|
|
69
|
-
# ──── Restart Policy ────
|
|
70
|
-
restart: unless-stopped
|
|
71
|
-
|
|
72
|
-
# ──── Health Check ────
|
|
73
|
-
healthcheck:
|
|
74
|
-
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
|
|
75
|
-
interval: 30s
|
|
76
|
-
timeout: 10s
|
|
77
|
-
retries: 3
|
|
78
|
-
start_period: 40s
|
|
79
|
-
|
|
80
|
-
# ──── Resource Limits (optional, enable for production) ────
|
|
81
|
-
# uncomment to enable
|
|
82
|
-
# deploy:
|
|
83
|
-
# resources:
|
|
84
|
-
# limits:
|
|
85
|
-
# cpus: '2'
|
|
86
|
-
# memory: 2G
|
|
87
|
-
# reservations:
|
|
88
|
-
# cpus: '1'
|
|
89
|
-
# memory: 1G
|
|
90
|
-
|
|
91
|
-
# ──── Security Options ────
|
|
92
|
-
security_opt:
|
|
93
|
-
- no-new-privileges:true
|
|
94
|
-
read_only: false
|
|
95
|
-
cap_drop:
|
|
96
|
-
- ALL
|
|
97
|
-
cap_add:
|
|
98
|
-
- NET_BIND_SERVICE
|
|
99
|
-
|
|
100
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
101
|
-
# Networks
|
|
102
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
103
|
-
|
|
104
|
-
networks:
|
|
105
|
-
superbrain-network:
|
|
106
|
-
driver: bridge
|
|
107
|
-
|
|
108
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
109
|
-
# Volumes for data persistence
|
|
110
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
111
|
-
|
|
112
|
-
volumes:
|
|
113
|
-
superbrain-db:
|
|
114
|
-
driver: local
|
|
115
|
-
superbrain-config:
|
|
116
|
-
driver: local
|
|
117
|
-
superbrain-temp:
|
|
118
|
-
driver: local
|
|
119
|
-
superbrain-uploads:
|
|
120
|
-
driver: local
|
|
121
|
-
superbrain-thumbnails:
|
|
122
|
-
driver: local
|
|
123
|
-
superbrain-logs:
|
|
124
|
-
driver: local
|
|
1
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
# SuperBrain Production Docker Compose Configuration
|
|
3
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
services:
|
|
6
|
+
|
|
7
|
+
# ──── Main SuperBrain API Service ────
|
|
8
|
+
superbrain-api:
|
|
9
|
+
image: superbrain:latest
|
|
10
|
+
build:
|
|
11
|
+
context: .
|
|
12
|
+
dockerfile: Dockerfile
|
|
13
|
+
container_name: superbrain-api
|
|
14
|
+
|
|
15
|
+
# ──── Network & Ports ────
|
|
16
|
+
ports:
|
|
17
|
+
- "${API_PORT:-5000}:5000"
|
|
18
|
+
networks:
|
|
19
|
+
- superbrain-network
|
|
20
|
+
|
|
21
|
+
# ──── Environment Variables ────
|
|
22
|
+
environment:
|
|
23
|
+
PYTHONUNBUFFERED: 1
|
|
24
|
+
PYTHONDONTWRITEBYTECODE: 1
|
|
25
|
+
ENVIRONMENT: ${ENVIRONMENT:-production}
|
|
26
|
+
HOST: 0.0.0.0
|
|
27
|
+
PORT: 5000
|
|
28
|
+
WORKERS: ${WORKERS:-4}
|
|
29
|
+
LOG_LEVEL: ${LOG_LEVEL:-INFO}
|
|
30
|
+
|
|
31
|
+
# Database
|
|
32
|
+
DATABASE_PATH: /app/data/superbrain.db
|
|
33
|
+
DATABASE_TIMEOUT: 30
|
|
34
|
+
|
|
35
|
+
# API Keys (load from .env file)
|
|
36
|
+
GROQ_API_KEY: ${GROQ_API_KEY}
|
|
37
|
+
GEMINI_API_KEY: ${GEMINI_API_KEY}
|
|
38
|
+
GOOGLE_API_KEY: ${GOOGLE_API_KEY}
|
|
39
|
+
OPENROUTER_API_KEY: ${OPENROUTER_API_KEY}
|
|
40
|
+
|
|
41
|
+
# Instagram credentials
|
|
42
|
+
INSTAGRAM_USERNAME: ${INSTAGRAM_USERNAME}
|
|
43
|
+
INSTAGRAM_PASSWORD: ${INSTAGRAM_PASSWORD}
|
|
44
|
+
|
|
45
|
+
# AI Configuration
|
|
46
|
+
WHISPER_MODEL: ${WHISPER_MODEL:-base}
|
|
47
|
+
WHISPER_USE_CLOUD: ${WHISPER_USE_CLOUD:-true}
|
|
48
|
+
|
|
49
|
+
# Performance
|
|
50
|
+
MAX_UPLOAD_SIZE: ${MAX_UPLOAD_SIZE:-52428800}
|
|
51
|
+
REQUEST_TIMEOUT: ${REQUEST_TIMEOUT:-60}
|
|
52
|
+
ANALYSIS_TIMEOUT: ${ANALYSIS_TIMEOUT:-120}
|
|
53
|
+
|
|
54
|
+
# ──── Volumes ────
|
|
55
|
+
volumes:
|
|
56
|
+
# Database persistence
|
|
57
|
+
- superbrain-db:/app/data
|
|
58
|
+
# Configuration persistence
|
|
59
|
+
- superbrain-config:/app/config
|
|
60
|
+
# Temporary files
|
|
61
|
+
- superbrain-temp:/app/temp
|
|
62
|
+
# Uploads
|
|
63
|
+
- superbrain-uploads:/app/static/uploads
|
|
64
|
+
# Extracted ZIP Thumbnails
|
|
65
|
+
- superbrain-thumbnails:/app/static/thumbnails
|
|
66
|
+
# Logs
|
|
67
|
+
- superbrain-logs:/app/logs
|
|
68
|
+
|
|
69
|
+
# ──── Restart Policy ────
|
|
70
|
+
restart: unless-stopped
|
|
71
|
+
|
|
72
|
+
# ──── Health Check ────
|
|
73
|
+
healthcheck:
|
|
74
|
+
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
|
|
75
|
+
interval: 30s
|
|
76
|
+
timeout: 10s
|
|
77
|
+
retries: 3
|
|
78
|
+
start_period: 40s
|
|
79
|
+
|
|
80
|
+
# ──── Resource Limits (optional, enable for production) ────
|
|
81
|
+
# uncomment to enable
|
|
82
|
+
# deploy:
|
|
83
|
+
# resources:
|
|
84
|
+
# limits:
|
|
85
|
+
# cpus: '2'
|
|
86
|
+
# memory: 2G
|
|
87
|
+
# reservations:
|
|
88
|
+
# cpus: '1'
|
|
89
|
+
# memory: 1G
|
|
90
|
+
|
|
91
|
+
# ──── Security Options ────
|
|
92
|
+
security_opt:
|
|
93
|
+
- no-new-privileges:true
|
|
94
|
+
read_only: false
|
|
95
|
+
cap_drop:
|
|
96
|
+
- ALL
|
|
97
|
+
cap_add:
|
|
98
|
+
- NET_BIND_SERVICE
|
|
99
|
+
|
|
100
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
101
|
+
# Networks
|
|
102
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
networks:
|
|
105
|
+
superbrain-network:
|
|
106
|
+
driver: bridge
|
|
107
|
+
|
|
108
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
109
|
+
# Volumes for data persistence
|
|
110
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
111
|
+
|
|
112
|
+
volumes:
|
|
113
|
+
superbrain-db:
|
|
114
|
+
driver: local
|
|
115
|
+
superbrain-config:
|
|
116
|
+
driver: local
|
|
117
|
+
superbrain-temp:
|
|
118
|
+
driver: local
|
|
119
|
+
superbrain-uploads:
|
|
120
|
+
driver: local
|
|
121
|
+
superbrain-thumbnails:
|
|
122
|
+
driver: local
|
|
123
|
+
superbrain-logs:
|
|
124
|
+
driver: local
|
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
# SuperBrain Backend Production Startup Script
|
|
5
|
-
# Ensures all configuration is validated and services are healthy
|
|
6
|
-
# ────────────────────────────────────────────────────────────────────────────────
|
|
7
|
-
|
|
8
|
-
set -e # Exit on any error
|
|
9
|
-
|
|
10
|
-
# Colors for output
|
|
11
|
-
RED='\033[0;31m'
|
|
12
|
-
GREEN='\033[0;32m'
|
|
13
|
-
YELLOW='\033[1;33m'
|
|
14
|
-
BLUE='\033[0;34m'
|
|
15
|
-
NC='\033[0m' # No Color
|
|
16
|
-
|
|
17
|
-
echo -e "${BLUE}╔════════════════════════════════════════════════════════════════╗${NC}"
|
|
18
|
-
echo -e "${BLUE}║ SuperBrain API - Production Startup ║${NC}"
|
|
19
|
-
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════╝${NC}"
|
|
20
|
-
|
|
21
|
-
# ──── Check prerequisites ────
|
|
22
|
-
echo -e "\n${YELLOW}→ Checking prerequisites...${NC}"
|
|
23
|
-
|
|
24
|
-
if ! command -v docker &> /dev/null; then
|
|
25
|
-
echo -e "${RED}✗ Docker is not installed${NC}"
|
|
26
|
-
exit 1
|
|
27
|
-
fi
|
|
28
|
-
echo -e "${GREEN}✓ Docker found${NC}"
|
|
29
|
-
|
|
30
|
-
if docker compose version &> /dev/null; then
|
|
31
|
-
COMPOSE_CMD="docker compose"
|
|
32
|
-
elif command -v docker-compose &> /dev/null; then
|
|
33
|
-
COMPOSE_CMD="docker-compose"
|
|
34
|
-
else
|
|
35
|
-
echo -e "${RED}✗ Docker Compose is not installed${NC}"
|
|
36
|
-
exit 1
|
|
37
|
-
fi
|
|
38
|
-
echo -e "${GREEN}✓ Docker Compose found (${COMPOSE_CMD})${NC}"
|
|
39
|
-
|
|
40
|
-
# ──── Check environment file ────
|
|
41
|
-
echo -e "\n${YELLOW}→ Checking environment configuration...${NC}"
|
|
42
|
-
|
|
43
|
-
if [ ! -f .env ]; then
|
|
44
|
-
if [ -f .env.example ]; then
|
|
45
|
-
echo -e "${YELLOW}⚠ .env file not found. Creating from .env.example...${NC}"
|
|
46
|
-
cp .env.example .env
|
|
47
|
-
echo -e "${YELLOW}⚠ Please edit .env with your actual credentials and run this script again${NC}"
|
|
48
|
-
exit 1
|
|
49
|
-
else
|
|
50
|
-
echo -e "${RED}✗ Neither .env nor .env.example found${NC}"
|
|
51
|
-
exit 1
|
|
52
|
-
fi
|
|
53
|
-
else
|
|
54
|
-
echo -e "${GREEN}✓ .env file found${NC}"
|
|
55
|
-
fi
|
|
56
|
-
|
|
57
|
-
# ──── Check required API keys ────
|
|
58
|
-
source .env
|
|
59
|
-
|
|
60
|
-
if [ -z "$GROQ_API_KEY" ] && [ -z "$GEMINI_API_KEY" ] && [ -z "$GOOGLE_API_KEY" ] && [ -z "$OPENROUTER_API_KEY" ]; then
|
|
61
|
-
echo -e "${YELLOW}⚠ Warning: No AI provider API keys configured${NC}"
|
|
62
|
-
echo -e "${YELLOW} Set at least one of: GROQ_API_KEY, GEMINI_API_KEY, OPENROUTER_API_KEY${NC}"
|
|
63
|
-
fi
|
|
64
|
-
|
|
65
|
-
# ──── Create necessary directories ────
|
|
66
|
-
echo -e "\n${YELLOW}→ Setting up directories...${NC}"
|
|
67
|
-
|
|
68
|
-
mkdir -p config temp static/uploads logs
|
|
69
|
-
chmod 755 config temp static static/uploads logs
|
|
70
|
-
|
|
71
|
-
echo -e "${GREEN}✓ Directories created${NC}"
|
|
72
|
-
|
|
73
|
-
# ──── Build Docker image ────
|
|
74
|
-
echo -e "\n${YELLOW}→ Building Docker image...${NC}"
|
|
75
|
-
|
|
76
|
-
${COMPOSE_CMD} build --no-cache
|
|
77
|
-
|
|
78
|
-
echo -e "${GREEN}✓ Docker image built successfully${NC}"
|
|
79
|
-
|
|
80
|
-
# ──── Start services ────
|
|
81
|
-
echo -e "\n${YELLOW}→ Starting SuperBrain API...${NC}"
|
|
82
|
-
|
|
83
|
-
${COMPOSE_CMD} up -d
|
|
84
|
-
|
|
85
|
-
echo -e "${GREEN}✓ Containers started${NC}"
|
|
86
|
-
|
|
87
|
-
# ──── Wait for service to be healthy ────
|
|
88
|
-
echo -e "\n${YELLOW}→ Waiting for API to become healthy...${NC}"
|
|
89
|
-
|
|
90
|
-
for i in {1..30}; do
|
|
91
|
-
if ${COMPOSE_CMD} exec -T superbrain-api curl -s http://localhost:5000/health > /dev/null 2>&1; then
|
|
92
|
-
echo -e "${GREEN}✓ API is healthy${NC}"
|
|
93
|
-
break
|
|
94
|
-
fi
|
|
95
|
-
|
|
96
|
-
if [ $i -eq 30 ]; then
|
|
97
|
-
echo -e "${RED}✗ API failed to start after 30 seconds${NC}"
|
|
98
|
-
${COMPOSE_CMD} logs superbrain-api
|
|
99
|
-
exit 1
|
|
100
|
-
fi
|
|
101
|
-
|
|
102
|
-
echo -n "."
|
|
103
|
-
sleep 1
|
|
104
|
-
done
|
|
105
|
-
|
|
106
|
-
# ──── Display status ────
|
|
107
|
-
echo -e "\n${BLUE}╔════════════════════════════════════════════════════════════════╗${NC}"
|
|
108
|
-
echo -e "${BLUE}║ Startup Complete! ✓ ║${NC}"
|
|
109
|
-
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════╝${NC}"
|
|
110
|
-
|
|
111
|
-
echo -e "\n${GREEN}Services running:${NC}"
|
|
112
|
-
${COMPOSE_CMD} ps
|
|
113
|
-
|
|
114
|
-
echo -e "\n${GREEN}API Information:${NC}"
|
|
115
|
-
echo -e " 📡 Endpoint: http://localhost:${API_PORT:-5000}"
|
|
116
|
-
echo -e " 📚 Documentation: http://localhost:${API_PORT:-5000}/docs"
|
|
117
|
-
echo -e " 🏥 Health Check: http://localhost:${API_PORT:-5000}/health"
|
|
118
|
-
|
|
119
|
-
echo -e "\n${GREEN}Useful commands:${NC}"
|
|
120
|
-
echo -e " View logs: ${YELLOW}${COMPOSE_CMD} logs -f superbrain-api${NC}"
|
|
121
|
-
echo -e " Stop services: ${YELLOW}${COMPOSE_CMD} down${NC}"
|
|
122
|
-
echo -e " Restart: ${YELLOW}${COMPOSE_CMD} restart${NC}"
|
|
123
|
-
echo -e " Status: ${YELLOW}${COMPOSE_CMD} ps${NC}"
|
|
124
|
-
|
|
125
|
-
echo -e "\n"
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
# SuperBrain Backend Production Startup Script
|
|
5
|
+
# Ensures all configuration is validated and services are healthy
|
|
6
|
+
# ────────────────────────────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
set -e # Exit on any error
|
|
9
|
+
|
|
10
|
+
# Colors for output
|
|
11
|
+
RED='\033[0;31m'
|
|
12
|
+
GREEN='\033[0;32m'
|
|
13
|
+
YELLOW='\033[1;33m'
|
|
14
|
+
BLUE='\033[0;34m'
|
|
15
|
+
NC='\033[0m' # No Color
|
|
16
|
+
|
|
17
|
+
echo -e "${BLUE}╔════════════════════════════════════════════════════════════════╗${NC}"
|
|
18
|
+
echo -e "${BLUE}║ SuperBrain API - Production Startup ║${NC}"
|
|
19
|
+
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════╝${NC}"
|
|
20
|
+
|
|
21
|
+
# ──── Check prerequisites ────
|
|
22
|
+
echo -e "\n${YELLOW}→ Checking prerequisites...${NC}"
|
|
23
|
+
|
|
24
|
+
if ! command -v docker &> /dev/null; then
|
|
25
|
+
echo -e "${RED}✗ Docker is not installed${NC}"
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
echo -e "${GREEN}✓ Docker found${NC}"
|
|
29
|
+
|
|
30
|
+
if docker compose version &> /dev/null; then
|
|
31
|
+
COMPOSE_CMD="docker compose"
|
|
32
|
+
elif command -v docker-compose &> /dev/null; then
|
|
33
|
+
COMPOSE_CMD="docker-compose"
|
|
34
|
+
else
|
|
35
|
+
echo -e "${RED}✗ Docker Compose is not installed${NC}"
|
|
36
|
+
exit 1
|
|
37
|
+
fi
|
|
38
|
+
echo -e "${GREEN}✓ Docker Compose found (${COMPOSE_CMD})${NC}"
|
|
39
|
+
|
|
40
|
+
# ──── Check environment file ────
|
|
41
|
+
echo -e "\n${YELLOW}→ Checking environment configuration...${NC}"
|
|
42
|
+
|
|
43
|
+
if [ ! -f .env ]; then
|
|
44
|
+
if [ -f .env.example ]; then
|
|
45
|
+
echo -e "${YELLOW}⚠ .env file not found. Creating from .env.example...${NC}"
|
|
46
|
+
cp .env.example .env
|
|
47
|
+
echo -e "${YELLOW}⚠ Please edit .env with your actual credentials and run this script again${NC}"
|
|
48
|
+
exit 1
|
|
49
|
+
else
|
|
50
|
+
echo -e "${RED}✗ Neither .env nor .env.example found${NC}"
|
|
51
|
+
exit 1
|
|
52
|
+
fi
|
|
53
|
+
else
|
|
54
|
+
echo -e "${GREEN}✓ .env file found${NC}"
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
# ──── Check required API keys ────
|
|
58
|
+
source .env
|
|
59
|
+
|
|
60
|
+
if [ -z "$GROQ_API_KEY" ] && [ -z "$GEMINI_API_KEY" ] && [ -z "$GOOGLE_API_KEY" ] && [ -z "$OPENROUTER_API_KEY" ]; then
|
|
61
|
+
echo -e "${YELLOW}⚠ Warning: No AI provider API keys configured${NC}"
|
|
62
|
+
echo -e "${YELLOW} Set at least one of: GROQ_API_KEY, GEMINI_API_KEY, OPENROUTER_API_KEY${NC}"
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
# ──── Create necessary directories ────
|
|
66
|
+
echo -e "\n${YELLOW}→ Setting up directories...${NC}"
|
|
67
|
+
|
|
68
|
+
mkdir -p config temp static/uploads logs
|
|
69
|
+
chmod 755 config temp static static/uploads logs
|
|
70
|
+
|
|
71
|
+
echo -e "${GREEN}✓ Directories created${NC}"
|
|
72
|
+
|
|
73
|
+
# ──── Build Docker image ────
|
|
74
|
+
echo -e "\n${YELLOW}→ Building Docker image...${NC}"
|
|
75
|
+
|
|
76
|
+
${COMPOSE_CMD} build --no-cache
|
|
77
|
+
|
|
78
|
+
echo -e "${GREEN}✓ Docker image built successfully${NC}"
|
|
79
|
+
|
|
80
|
+
# ──── Start services ────
|
|
81
|
+
echo -e "\n${YELLOW}→ Starting SuperBrain API...${NC}"
|
|
82
|
+
|
|
83
|
+
${COMPOSE_CMD} up -d
|
|
84
|
+
|
|
85
|
+
echo -e "${GREEN}✓ Containers started${NC}"
|
|
86
|
+
|
|
87
|
+
# ──── Wait for service to be healthy ────
|
|
88
|
+
echo -e "\n${YELLOW}→ Waiting for API to become healthy...${NC}"
|
|
89
|
+
|
|
90
|
+
for i in {1..30}; do
|
|
91
|
+
if ${COMPOSE_CMD} exec -T superbrain-api curl -s http://localhost:5000/health > /dev/null 2>&1; then
|
|
92
|
+
echo -e "${GREEN}✓ API is healthy${NC}"
|
|
93
|
+
break
|
|
94
|
+
fi
|
|
95
|
+
|
|
96
|
+
if [ $i -eq 30 ]; then
|
|
97
|
+
echo -e "${RED}✗ API failed to start after 30 seconds${NC}"
|
|
98
|
+
${COMPOSE_CMD} logs superbrain-api
|
|
99
|
+
exit 1
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
echo -n "."
|
|
103
|
+
sleep 1
|
|
104
|
+
done
|
|
105
|
+
|
|
106
|
+
# ──── Display status ────
|
|
107
|
+
echo -e "\n${BLUE}╔════════════════════════════════════════════════════════════════╗${NC}"
|
|
108
|
+
echo -e "${BLUE}║ Startup Complete! ✓ ║${NC}"
|
|
109
|
+
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════╝${NC}"
|
|
110
|
+
|
|
111
|
+
echo -e "\n${GREEN}Services running:${NC}"
|
|
112
|
+
${COMPOSE_CMD} ps
|
|
113
|
+
|
|
114
|
+
echo -e "\n${GREEN}API Information:${NC}"
|
|
115
|
+
echo -e " 📡 Endpoint: http://localhost:${API_PORT:-5000}"
|
|
116
|
+
echo -e " 📚 Documentation: http://localhost:${API_PORT:-5000}/docs"
|
|
117
|
+
echo -e " 🏥 Health Check: http://localhost:${API_PORT:-5000}/health"
|
|
118
|
+
|
|
119
|
+
echo -e "\n${GREEN}Useful commands:${NC}"
|
|
120
|
+
echo -e " View logs: ${YELLOW}${COMPOSE_CMD} logs -f superbrain-api${NC}"
|
|
121
|
+
echo -e " Stop services: ${YELLOW}${COMPOSE_CMD} down${NC}"
|
|
122
|
+
echo -e " Restart: ${YELLOW}${COMPOSE_CMD} restart${NC}"
|
|
123
|
+
echo -e " Status: ${YELLOW}${COMPOSE_CMD} ps${NC}"
|
|
124
|
+
|
|
125
|
+
echo -e "\n"
|