File size: 4,389 Bytes
6b0f97b
95eeba3
f7a3cff
95eeba3
f7a3cff
807d93d
f7a3cff
95eeba3
807d93d
95eeba3
807d93d
 
 
95eeba3
807d93d
 
95eeba3
 
807d93d
95eeba3
 
4b33e61
 
95eeba3
 
f7a3cff
95eeba3
 
4b33e61
95eeba3
807d93d
 
 
 
95eeba3
807d93d
 
 
95eeba3
807d93d
 
 
 
95eeba3
 
 
807d93d
6b0f97b
807d93d
 
 
 
95eeba3
 
807d93d
 
95eeba3
807d93d
 
95eeba3
 
 
807d93d
 
95eeba3
 
807d93d
 
95eeba3
 
 
6b0f97b
807d93d
 
95eeba3
 
807d93d
 
95eeba3
 
 
807d93d
 
 
 
 
95eeba3
 
 
807d93d
f7a3cff
95eeba3
807d93d
 
 
95eeba3
 
 
807d93d
 
95eeba3
807d93d
 
 
 
95eeba3
 
 
807d93d
 
 
95eeba3
 
807d93d
 
 
 
95eeba3
 
 
807d93d
 
 
 
f7a3cff
95eeba3
 
 
 
 
807d93d
4b33e61
 
 
95eeba3
 
 
4b33e61
95eeba3
 
 
 
 
 
4b33e61
95eeba3
 
 
4b33e61
95eeba3
 
 
f7a3cff
95eeba3
807d93d
f7a3cff
 
807d93d
 
 
f7a3cff
 
 
6415621
807d93d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Agenta on Hugging Face Spaces - Fixed typo in supervisor config
# Uses official Agenta images with SQLite instead of PostgreSQL

FROM ghcr.io/agenta-ai/agenta-api:latest AS api-base

USER root

# Install Python dependencies for SQLite and other tools
RUN apt-get update && apt-get install -y \
    sqlite3 \
    redis-server \
    nginx \
    supervisor \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Setup directories
RUN mkdir -p /app/data /var/log/supervisor /var/run/redis

# Copy web assets from web image
FROM ghcr.io/agenta-ai/agenta-web:latest AS web-source
WORKDIR /app

# Final stage
FROM api-base

# Copy web files
COPY --from=web-source /app /app/web

# Setup environment for SQLite and single container
ENV PORT=7860
ENV HOSTNAME=0.0.0.0
ENV AGENTA_MODE=oss

# Use SQLite instead of PostgreSQL
ENV DATABASE_URL=sqlite:////app/data/agenta.db
ENV REDIS_URL=redis://localhost:6379/0

# API and Web URLs
ENV AGENTA_API_URL=http://localhost:7860/api
ENV AGENTA_WEB_URL=http://localhost:7860
ENV AGENTA_SERVICES_URL=http://localhost:7860/services

# Additional config for Agenta
ENV ENVIRONMENT=production
ENV FEATURE_FLAG=oss

# Create supervisor config - FIXED TYPO HERE
RUN cat > /etc/supervisor/conf.d/supervisord.conf << 'EOF'
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

[program:redis]
command=/usr/bin/redis-server --daemonize no --bind 127.0.0.1 --port 6379
autostart=true
autorestart=true
priority=1
stdout_logfile=/var/log/supervisor/redis.log
stderr_logfile=/var/log/supervisor/redis.err

[program:api]
command=bash -c "sleep 5 && cd /app && uvicorn agenta_backend.main:app --host 0.0.0.0 --port 8080"
directory=/app
autostart=true
autorestart=true
priority=2
stdout_logfile=/var/log/supervisor/api.log
stderr_logfile=/var/log/supervisor/api.err
environment=DATABASE_URL="%(ENV_DATABASE_URL)s",REDIS_URL="%(ENV_REDIS_URL)s",ENVIRONMENT="production"

[program:web]
command=bash -c "sleep 10 && cd /app/web && npm start"
directory=/app/web
autostart=true
autorestart=true
priority=3
stdout_logfile=/var/log/supervisor/web.log
stderr_logfile=/var/log/supervisor/web.err

[program:nginx]
command=/usr/sbin/nginx -g 'daemon off;'
autostart=true
autorestart=true
priority=4
stdout_logfile=/var/log/supervisor/nginx.log
stderr_logfile=/var/log/supervisor/nginx.err
EOF

# Nginx config for port 7860
RUN cat > /etc/nginx/sites-available/default << 'EOF'
server {
    listen 7860;
    server_name _;
    
    client_max_body_size 100M;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }

    location /api/ {
        proxy_pass http://127.0.0.1:8080/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}
EOF

# Remove default nginx site if exists
RUN rm -f /etc/nginx/sites-enabled/default && \
    ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

# Init script
RUN cat > /init.sh << 'EOF'
#!/bin/bash
set -e

# Ensure data directory exists
mkdir -p /app/data
chmod 777 /app/data

# Initialize SQLite database if not exists
if [ ! -f /app/data/agenta.db ]; then
    echo "Initializing SQLite database..."
    touch /app/data/agenta.db
    chmod 666 /app/data/agenta.db
fi

# Export environment variables for supervisor
export DATABASE_URL=${DATABASE_URL}
export REDIS_URL=${REDIS_URL}

echo "Starting Agenta services..."
echo "Database: $DATABASE_URL"
echo "Redis: $REDIS_URL"

# Start supervisor
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
EOF

RUN chmod +x /init.sh

EXPOSE 7860

HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:7860 || exit 1

ENTRYPOINT ["/init.sh"]