Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +149 -50
Dockerfile
CHANGED
|
@@ -1,73 +1,172 @@
|
|
| 1 |
-
#
|
| 2 |
-
#
|
| 3 |
|
| 4 |
-
FROM
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
git \
|
| 9 |
-
curl \
|
| 10 |
-
bash \
|
| 11 |
-
python3 \
|
| 12 |
-
py3-pip \
|
| 13 |
-
nodejs \
|
| 14 |
-
npm \
|
| 15 |
-
postgresql-client \
|
| 16 |
-
redis
|
| 17 |
|
| 18 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
WORKDIR /app
|
|
|
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
RUN cp hosting/docker-compose/oss/env.oss.gh.example hosting/docker-compose/oss/.env.oss.gh
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
RUN
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
RUN cat > /
|
| 41 |
#!/bin/bash
|
| 42 |
set -e
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
sleep 5
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
--env-file hosting/docker-compose/oss/.env.oss.gh \
|
| 59 |
-
--profile with-web \
|
| 60 |
-
up -d
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
|
| 64 |
-
docker logs -f agenta-oss-gh-web
|
| 65 |
EOF
|
| 66 |
|
| 67 |
-
RUN chmod +x /
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
# Health check
|
| 70 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 71 |
CMD curl -f http://localhost:7860 || exit 1
|
| 72 |
|
| 73 |
-
ENTRYPOINT ["/
|
|
|
|
| 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 |
|
| 165 |
+
RUN chmod +x /init.sh
|
| 166 |
+
|
| 167 |
+
EXPOSE 7860
|
| 168 |
|
|
|
|
| 169 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 170 |
CMD curl -f http://localhost:7860 || exit 1
|
| 171 |
|
| 172 |
+
ENTRYPOINT ["/init.sh"]
|