NitinBot001 commited on
Commit
95eeba3
·
verified ·
1 Parent(s): 807d93d

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +75 -82
Dockerfile CHANGED
@@ -1,164 +1,157 @@
1
- # Agenta on Hugging Face Spaces - Multi-service setup without DinD
2
- # Uses official Agenta images directly
3
 
4
- FROM ghcr.io/agenta-ai/agenta-api:latest AS api
5
 
6
- # Switch to root to install additional services
7
  USER root
8
 
9
- # Install Node.js for web service, PostgreSQL, Redis, and other deps
10
  RUN apt-get update && apt-get install -y \
11
- curl \
12
- gnupg \
13
- postgresql \
14
- postgresql-contrib \
15
  redis-server \
16
  nginx \
17
  supervisor \
18
- && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
19
- && apt-get install -y nodejs \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
- # Setup PostgreSQL
23
- RUN service postgresql start && \
24
- su - postgres -c "psql -c \"CREATE USER agenta WITH PASSWORD 'agenta';\"" && \
25
- su - postgres -c "psql -c \"CREATE DATABASE agenta OWNER agenta;\"" && \
26
- su - postgres -c "psql -c \"ALTER USER agenta WITH SUPERUSER;\""
27
 
28
- # Setup Redis
29
- RUN mkdir -p /var/run/redis && chmod 777 /var/run/redis
30
-
31
- # Copy web assets from web image (multi-stage)
32
- FROM ghcr.io/agenta-ai/agenta-web:latest AS web-builder
33
  WORKDIR /app
34
- # Web assets are already in /app in this image
35
 
36
- # Final stage - combine everything
37
- FROM ghcr.io/agenta-ai/agenta-api:latest
38
 
39
- USER root
 
40
 
41
- # Install runtime dependencies
42
- RUN apt-get update && apt-get install -y \
43
- postgresql-client \
44
- redis-tools \
45
- nginx \
46
- supervisor \
47
- && rm -rf /var/lib/apt/lists/*
48
-
49
- # Copy web service from web image
50
- COPY --from=web-builder /app /app/web
51
-
52
- # Setup environment variables for Hugging Face Spaces
53
  ENV PORT=7860
54
  ENV HOSTNAME=0.0.0.0
55
  ENV AGENTA_MODE=oss
56
 
57
- # Database configuration (using SQLite for simplicity in single container)
58
  ENV DATABASE_URL=sqlite:////app/data/agenta.db
59
  ENV REDIS_URL=redis://localhost:6379/0
60
 
61
- # API configuration
62
  ENV AGENTA_API_URL=http://localhost:7860/api
63
  ENV AGENTA_WEB_URL=http://localhost:7860
64
  ENV AGENTA_SERVICES_URL=http://localhost:7860/services
65
 
66
- # Create necessary directories
67
- RUN mkdir -p /app/data /var/log/supervisor /run/postgresql
 
68
 
69
- # Supervisor configuration to manage multiple processes
70
  RUN cat > /etc/supervisor/conf.d/supervisord.conf << 'EOF'
71
  [supervisord]
72
  nodaemon=true
73
  user=root
74
-
75
- [program:postgres]
76
- command=/usr/lib/postgresql/15/bin/postgres -D /var/lib/postgresql/15/main -c config_file=/etc/postgresql/15/main/postgresql.conf
77
- autostart=true
78
- autorestart=true
79
- priority=1
80
 
81
  [program:redis]
82
- command=/usr/bin/redis-server --daemonize no --bind 0.0.0.0
83
  autostart=true
84
  autorestart=true
85
- priority=2
 
 
86
 
87
  [program:api]
88
- command=bash -c "sleep 10 && cd /app && uvicorn agenta_backend.main:app --host 0.0.0.0 --port 8080 --reload"
 
89
  autostart=true
90
  autorestart=true
91
- priority=3
92
- environment=DATABASE_URL="%(ENV_DATABASE_URL)s",REDIS_URL="%(ENV_REDIS_URL)s"
 
 
93
 
94
  [program:web]
95
- command=bash -c "sleep 15 && cd /app/web && node server.js"
 
96
  autostart=true
97
  autorestart=true
98
- priority=4
99
- environment=PORT="3000",API_URL="http://localhost:8080"
 
100
 
101
  [program:nginx]
102
  command=/usr/sbin/nginx -g 'daemon off;'
103
  autostart=true
104
  autorestart=true
105
- priority=5
 
 
106
  EOF
107
 
108
- # Nginx configuration to route traffic
109
  RUN cat > /etc/nginx/sites-available/default << 'EOF'
110
  server {
111
  listen 7860;
112
- server_name localhost;
 
 
113
 
114
  location / {
115
- proxy_pass http://localhost:3000;
116
  proxy_http_version 1.1;
117
  proxy_set_header Upgrade $http_upgrade;
118
  proxy_set_header Connection 'upgrade';
119
  proxy_set_header Host $host;
 
 
 
120
  proxy_cache_bypass $http_upgrade;
121
  }
122
 
123
- location /api {
124
- proxy_pass http://localhost:8080;
125
  proxy_http_version 1.1;
126
  proxy_set_header Upgrade $http_upgrade;
127
  proxy_set_header Connection 'upgrade';
128
  proxy_set_header Host $host;
 
 
 
129
  proxy_cache_bypass $http_upgrade;
130
  }
131
  }
132
  EOF
133
 
134
- # Initialize script
 
 
 
 
135
  RUN cat > /init.sh << 'EOF'
136
  #!/bin/bash
137
  set -e
138
 
139
- # Initialize PostgreSQL if not already done
140
- if [ ! -d "/var/lib/postgresql/15/main" ]; then
141
- mkdir -p /var/lib/postgresql/15/main
142
- chown -R postgres:postgres /var/lib/postgresql
143
- su - postgres -c "/usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/15/main"
144
- fi
145
-
146
- # Start PostgreSQL temporarily to create DB
147
- su - postgres -c "/usr/lib/postgresql/15/bin/pg_ctl -D /var/lib/postgresql/15/main -l /var/lib/postgresql/logfile start"
148
- sleep 5
149
 
150
- # Create database and user
151
- su - postgres -c "psql -c \"CREATE USER agenta WITH PASSWORD 'agenta';\" 2>/dev/null || true"
152
- su - postgres -c "psql -c \"CREATE DATABASE agenta OWNER agenta;\" 2>/dev/null || true"
153
- su - postgres -c "psql -c \"ALTER USER agenta WITH SUPERUSER;\" 2>/dev/null || true"
 
 
154
 
155
- # Stop PostgreSQL (supervisor will start it properly)
156
- su - postgres -c "/usr/lib/postgresql/15/bin/pg_ctl -D /var/lib/postgresql/15/main stop" || true
 
157
 
158
- # Run database migrations
159
- sleep 5
 
160
 
161
- # Start all services via supervisor
162
  exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
163
  EOF
164
 
 
1
+ # Agenta on Hugging Face Spaces - Fixed version
2
+ # Uses official Agenta images with SQLite instead of PostgreSQL
3
 
4
+ FROM ghcr.io/agenta-ai/agenta-api:latest AS api-base
5
 
 
6
  USER root
7
 
8
+ # Install Python dependencies for SQLite and other tools
9
  RUN apt-get update && apt-get install -y \
10
+ sqlite3 \
 
 
 
11
  redis-server \
12
  nginx \
13
  supervisor \
14
+ curl \
 
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
+ # Setup directories
18
+ RUN mkdir -p /app/data /var/log/supervisor /var/run/redis
 
 
 
19
 
20
+ # Copy web assets from web image
21
+ FROM ghcr.io/agenta-ai/agenta-web:latest AS web-source
 
 
 
22
  WORKDIR /app
 
23
 
24
+ # Final stage
25
+ FROM api-base
26
 
27
+ # Copy web files
28
+ COPY --from=web-source /app /app/web
29
 
30
+ # Setup environment for SQLite and single container
 
 
 
 
 
 
 
 
 
 
 
31
  ENV PORT=7860
32
  ENV HOSTNAME=0.0.0.0
33
  ENV AGENTA_MODE=oss
34
 
35
+ # Use SQLite instead of PostgreSQL
36
  ENV DATABASE_URL=sqlite:////app/data/agenta.db
37
  ENV REDIS_URL=redis://localhost:6379/0
38
 
39
+ # API and Web URLs
40
  ENV AGENTA_API_URL=http://localhost:7860/api
41
  ENV AGENTA_WEB_URL=http://localhost:7860
42
  ENV AGENTA_SERVICES_URL=http://localhost:7860/services
43
 
44
+ # Additional config for Agenta
45
+ ENV ENVIRONMENT=production
46
+ ENV FEATURE_FLAG=oss
47
 
48
+ # Create supervisor config
49
  RUN cat > /etc/supervisor/conf.d/supervisord.conf << 'EOF'
50
  [supervisord]
51
  nodaemon=true
52
  user=root
53
+ logfile=/var/log/supervisor/supervisord.log
54
+ pidfile=/var/run/supervisord.pid
 
 
 
 
55
 
56
  [program:redis]
57
+ command=/usr/bin/redis-server --daemonize no --bind 127.0.0.1 --port 6379
58
  autostart=true
59
  autorestart=true
60
+ priority=1
61
+ stdout_logfile=/var/log/supervisor/redis.log
62
+ stderr_logfile=/var/log/supervisor/redis.err
63
 
64
  [program:api]
65
+ command=bash -c "sleep 5 && cd /app && uvicorn agenta_backend.main:app --host 0.0.0.0 --port 8080"
66
+ directory=/app
67
  autostart=true
68
  autorestart=true
69
+ priority=2
70
+ stdout_logfile=/var/log/supervisor/api.log
71
+ stderr_logfile=/var/log/supervisor/api.err
72
+ environment=DATABASE_URL="%(ENV_DATABASE_URL)s",REDIS_URL="%(ENV_REDITS_URL)s",ENVIRONMENT="production"
73
 
74
  [program:web]
75
+ command=bash -c "sleep 10 && cd /app/web && npm start"
76
+ directory=/app/web
77
  autostart=true
78
  autorestart=true
79
+ priority=3
80
+ stdout_logfile=/var/log/supervisor/web.log
81
+ stderr_logfile=/var/log/supervisor/web.err
82
 
83
  [program:nginx]
84
  command=/usr/sbin/nginx -g 'daemon off;'
85
  autostart=true
86
  autorestart=true
87
+ priority=4
88
+ stdout_logfile=/var/log/supervisor/nginx.log
89
+ stderr_logfile=/var/log/supervisor/nginx.err
90
  EOF
91
 
92
+ # Nginx config for port 7860
93
  RUN cat > /etc/nginx/sites-available/default << 'EOF'
94
  server {
95
  listen 7860;
96
+ server_name _;
97
+
98
+ client_max_body_size 100M;
99
 
100
  location / {
101
+ proxy_pass http://127.0.0.1:3000;
102
  proxy_http_version 1.1;
103
  proxy_set_header Upgrade $http_upgrade;
104
  proxy_set_header Connection 'upgrade';
105
  proxy_set_header Host $host;
106
+ proxy_set_header X-Real-IP $remote_addr;
107
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
108
+ proxy_set_header X-Forwarded-Proto $scheme;
109
  proxy_cache_bypass $http_upgrade;
110
  }
111
 
112
+ location /api/ {
113
+ proxy_pass http://127.0.0.1:8080/;
114
  proxy_http_version 1.1;
115
  proxy_set_header Upgrade $http_upgrade;
116
  proxy_set_header Connection 'upgrade';
117
  proxy_set_header Host $host;
118
+ proxy_set_header X-Real-IP $remote_addr;
119
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
120
+ proxy_set_header X-Forwarded-Proto $scheme;
121
  proxy_cache_bypass $http_upgrade;
122
  }
123
  }
124
  EOF
125
 
126
+ # Remove default nginx site if exists
127
+ RUN rm -f /etc/nginx/sites-enabled/default && \
128
+ ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
129
+
130
+ # Init script
131
  RUN cat > /init.sh << 'EOF'
132
  #!/bin/bash
133
  set -e
134
 
135
+ # Ensure data directory exists
136
+ mkdir -p /app/data
137
+ chmod 777 /app/data
 
 
 
 
 
 
 
138
 
139
+ # Initialize SQLite database if not exists
140
+ if [ ! -f /app/data/agenta.db ]; then
141
+ echo "Initializing SQLite database..."
142
+ touch /app/data/agenta.db
143
+ chmod 666 /app/data/agenta.db
144
+ fi
145
 
146
+ # Export environment variables for supervisor
147
+ export DATABASE_URL=${DATABASE_URL}
148
+ export REDIS_URL=${REDIS_URL}
149
 
150
+ echo "Starting Agenta services..."
151
+ echo "Database: $DATABASE_URL"
152
+ echo "Redis: $REDIS_URL"
153
 
154
+ # Start supervisor
155
  exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
156
  EOF
157