Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +217 -60
Dockerfile
CHANGED
|
@@ -1,67 +1,224 @@
|
|
| 1 |
-
#
|
| 2 |
-
#
|
| 3 |
-
#
|
| 4 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
# https://raw.githubusercontent.com/penpot/penpot/main/docker/images/docker-compose.yaml
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
USER root
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
RUN
|
| 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 |
EXPOSE 7860
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
set -e\n\
|
| 46 |
-
\n\
|
| 47 |
-
echo "Starting PostgreSQL..."\n\
|
| 48 |
-
su - postgres -c "/usr/lib/postgresql/15/bin/pg_ctl -D /var/lib/postgresql/data -l /var/log/postgresql.log start"\n\
|
| 49 |
-
sleep 5\n\
|
| 50 |
-
\n\
|
| 51 |
-
echo "Creating database..."\n\
|
| 52 |
-
su - postgres -c "psql -c \"CREATE DATABASE penpot;\"" || true\n\
|
| 53 |
-
su - postgres -c "psql -c \"CREATE USER penpot WITH PASSWORD '\''penpot'\'';\"" || true\n\
|
| 54 |
-
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE penpot TO penpot;\"" || true\n\
|
| 55 |
-
\n\
|
| 56 |
-
echo "Starting Penpot..."\n\
|
| 57 |
-
exec /opt/run.sh\n\
|
| 58 |
-
' > /start.sh && chmod +x /start.sh
|
| 59 |
-
|
| 60 |
-
CMD ["/start.sh"]
|
| 61 |
-
|
| 62 |
-
# IMPORTANT NOTES:
|
| 63 |
-
# 1. This Dockerfile is NOT suitable for production use
|
| 64 |
-
# 2. Hugging Face Spaces may not support this complex setup
|
| 65 |
-
# 3. For proper deployment, use docker-compose with the official setup
|
| 66 |
-
# 4. This lacks Redis/Valkey, proper backend service, and exporter service
|
| 67 |
-
# 5. Consider using Elestio or dedicated hosting instead
|
|
|
|
| 1 |
+
# ============================================================
|
| 2 |
+
# Agenta Self-Hosted — Hugging Face Spaces Dockerfile
|
| 3 |
+
# ============================================================
|
| 4 |
+
# HF Spaces requirements:
|
| 5 |
+
# - Single container, port 7860 exposed
|
| 6 |
+
# - No privileged / Docker-in-Docker
|
| 7 |
+
# - Runs as non-root after setup (HF uid 1000)
|
| 8 |
+
# Strategy:
|
| 9 |
+
# - supervisord manages: PostgreSQL, Redis, Agenta API, Agenta Web, nginx
|
| 10 |
+
# - nginx reverse-proxies everything on port 7860
|
| 11 |
+
# ============================================================
|
| 12 |
|
| 13 |
+
FROM ubuntu:22.04
|
|
|
|
| 14 |
|
| 15 |
+
# ---------- Avoid interactive prompts ----------
|
| 16 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 17 |
+
ENV TZ=UTC
|
| 18 |
|
| 19 |
+
# ---------- System dependencies ----------
|
| 20 |
+
RUN apt-get update && apt-get install -y \
|
| 21 |
+
curl wget git ca-certificates gnupg lsb-release \
|
| 22 |
+
supervisor nginx \
|
| 23 |
+
postgresql postgresql-contrib \
|
| 24 |
+
redis-server \
|
| 25 |
+
python3.11 python3.11-venv python3.11-dev python3-pip \
|
| 26 |
+
build-essential libpq-dev \
|
| 27 |
+
nodejs npm \
|
| 28 |
+
&& npm install -g n && n 20 \
|
| 29 |
+
&& hash -r \
|
| 30 |
+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 31 |
+
|
| 32 |
+
# ---------- Environment variables ----------
|
| 33 |
+
ENV PORT=7860
|
| 34 |
+
ENV AGENTA_WEB_URL=http://localhost:7860
|
| 35 |
+
ENV AGENTA_API_URL=http://localhost:7860/api
|
| 36 |
+
ENV AGENTA_SERVICES_URL=http://localhost:7860/services
|
| 37 |
+
ENV AGENTA_API_INTERNAL_URL=http://localhost:8000
|
| 38 |
+
|
| 39 |
+
# Postgres
|
| 40 |
+
ENV POSTGRES_USER=agenta
|
| 41 |
+
ENV POSTGRES_PASSWORD=agenta_secret
|
| 42 |
+
ENV POSTGRES_DB_CORE=agenta_core
|
| 43 |
+
ENV POSTGRES_DB_TRACING=agenta_tracing
|
| 44 |
+
ENV POSTGRES_DB_SUPERTOKENS=agenta_supertokens
|
| 45 |
+
ENV POSTGRES_URI_CORE=postgresql+asyncpg://agenta:agenta_secret@localhost:5432/agenta_core
|
| 46 |
+
ENV POSTGRES_URI_TRACING=postgresql+asyncpg://agenta:agenta_secret@localhost:5432/agenta_tracing
|
| 47 |
+
ENV POSTGRES_URI_SUPERTOKENS=postgresql://agenta:agenta_secret@localhost:5432/agenta_supertokens
|
| 48 |
+
|
| 49 |
+
# Redis
|
| 50 |
+
ENV REDIS_URI=redis://localhost:6379/0
|
| 51 |
+
|
| 52 |
+
# Auth keys — CHANGE THESE in HF Space Secrets!
|
| 53 |
+
ENV AGENTA_AUTH_KEY=changeme_auth_key_32chars_minimum
|
| 54 |
+
ENV AGENTA_CRYPT_KEY=changeme_crypt_key_32charsminimum
|
| 55 |
+
|
| 56 |
+
# API internals
|
| 57 |
+
ENV PYTHONPATH=/app
|
| 58 |
+
ENV PYTHONUNBUFFERED=1
|
| 59 |
+
|
| 60 |
+
WORKDIR /app
|
| 61 |
+
|
| 62 |
+
# ---------- Clone Agenta ----------
|
| 63 |
+
RUN git clone --depth 1 https://github.com/Agenta-AI/agenta .
|
| 64 |
+
|
| 65 |
+
# ---------- Python virtualenv + API deps ----------
|
| 66 |
+
RUN python3.11 -m venv /app/venv && \
|
| 67 |
+
/app/venv/bin/pip install --upgrade pip && \
|
| 68 |
+
/app/venv/bin/pip install \
|
| 69 |
+
fastapi uvicorn[standard] \
|
| 70 |
+
sqlalchemy[asyncio] asyncpg alembic \
|
| 71 |
+
redis celery \
|
| 72 |
+
pydantic pydantic-settings \
|
| 73 |
+
httpx tenacity \
|
| 74 |
+
python-multipart python-jose[cryptography] \
|
| 75 |
+
passlib[bcrypt] \
|
| 76 |
+
supertokens-python \
|
| 77 |
+
opentelemetry-sdk opentelemetry-exporter-otlp \
|
| 78 |
+
posthog \
|
| 79 |
+
agenta || true
|
| 80 |
+
# Install from repo requirements if present
|
| 81 |
+
RUN [ -f /app/api/requirements.txt ] && \
|
| 82 |
+
/app/venv/bin/pip install -r /app/api/requirements.txt || true
|
| 83 |
+
RUN [ -f /app/oss/src/requirements.txt ] && \
|
| 84 |
+
/app/venv/bin/pip install -r /app/oss/src/requirements.txt || true
|
| 85 |
+
|
| 86 |
+
# ---------- Web (Next.js) build ----------
|
| 87 |
+
# Locate the web app directory
|
| 88 |
+
RUN WEB_DIR=$(find /app -maxdepth 3 -name "package.json" \
|
| 89 |
+
-not -path "*/node_modules/*" \
|
| 90 |
+
-not -path "/app/package.json" | head -1 | xargs dirname) && \
|
| 91 |
+
echo "Web dir: $WEB_DIR" && \
|
| 92 |
+
cd "$WEB_DIR" && \
|
| 93 |
+
NEXT_PUBLIC_AGENTA_API_URL=http://localhost:7860/api \
|
| 94 |
+
npm install && \
|
| 95 |
+
NEXT_PUBLIC_AGENTA_API_URL=http://localhost:7860/api npm run build || true
|
| 96 |
+
|
| 97 |
+
# ---------- PostgreSQL setup ----------
|
| 98 |
+
USER postgres
|
| 99 |
+
RUN /etc/init.d/postgresql start && \
|
| 100 |
+
psql -c "CREATE USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}';" && \
|
| 101 |
+
psql -c "CREATE DATABASE ${POSTGRES_DB_CORE} OWNER ${POSTGRES_USER};" && \
|
| 102 |
+
psql -c "CREATE DATABASE ${POSTGRES_DB_TRACING} OWNER ${POSTGRES_USER};" && \
|
| 103 |
+
psql -c "CREATE DATABASE ${POSTGRES_DB_SUPERTOKENS} OWNER ${POSTGRES_USER};" && \
|
| 104 |
+
/etc/init.d/postgresql stop
|
| 105 |
USER root
|
| 106 |
|
| 107 |
+
# ---------- Nginx config (reverse proxy on 7860) ----------
|
| 108 |
+
RUN cat > /etc/nginx/sites-available/agenta <<'EOF'
|
| 109 |
+
server {
|
| 110 |
+
listen 7860;
|
| 111 |
+
server_name _;
|
| 112 |
+
client_max_body_size 50M;
|
| 113 |
+
|
| 114 |
+
# Agenta Web (Next.js on port 3000)
|
| 115 |
+
location / {
|
| 116 |
+
proxy_pass http://127.0.0.1:3000;
|
| 117 |
+
proxy_http_version 1.1;
|
| 118 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 119 |
+
proxy_set_header Connection 'upgrade';
|
| 120 |
+
proxy_set_header Host $host;
|
| 121 |
+
proxy_cache_bypass $http_upgrade;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
# Agenta API (FastAPI on port 8000)
|
| 125 |
+
location /api/ {
|
| 126 |
+
proxy_pass http://127.0.0.1:8000/;
|
| 127 |
+
proxy_http_version 1.1;
|
| 128 |
+
proxy_set_header Host $host;
|
| 129 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 130 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 131 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
# Services endpoint
|
| 135 |
+
location /services/ {
|
| 136 |
+
proxy_pass http://127.0.0.1:8000/services/;
|
| 137 |
+
proxy_http_version 1.1;
|
| 138 |
+
proxy_set_header Host $host;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
EOF
|
| 142 |
+
RUN ln -sf /etc/nginx/sites-available/agenta /etc/nginx/sites-enabled/agenta && \
|
| 143 |
+
rm -f /etc/nginx/sites-enabled/default
|
| 144 |
+
|
| 145 |
+
# ---------- Supervisord config ----------
|
| 146 |
+
RUN mkdir -p /var/log/supervisor
|
| 147 |
+
RUN cat > /etc/supervisor/conf.d/agenta.conf <<'EOF'
|
| 148 |
+
[supervisord]
|
| 149 |
+
nodaemon=true
|
| 150 |
+
logfile=/var/log/supervisor/supervisord.log
|
| 151 |
+
pidfile=/var/run/supervisord.pid
|
| 152 |
+
|
| 153 |
+
[program:postgresql]
|
| 154 |
+
command=/usr/lib/postgresql/14/bin/postgres -D /var/lib/postgresql/14/main -c config_file=/etc/postgresql/14/main/postgresql.conf
|
| 155 |
+
user=postgres
|
| 156 |
+
autostart=true
|
| 157 |
+
autorestart=true
|
| 158 |
+
stderr_logfile=/var/log/supervisor/postgres.err.log
|
| 159 |
+
stdout_logfile=/var/log/supervisor/postgres.out.log
|
| 160 |
+
priority=1
|
| 161 |
+
|
| 162 |
+
[program:redis]
|
| 163 |
+
command=redis-server --daemonize no --bind 127.0.0.1 --port 6379
|
| 164 |
+
autostart=true
|
| 165 |
+
autorestart=true
|
| 166 |
+
stderr_logfile=/var/log/supervisor/redis.err.log
|
| 167 |
+
stdout_logfile=/var/log/supervisor/redis.out.log
|
| 168 |
+
priority=2
|
| 169 |
+
|
| 170 |
+
[program:agenta-api]
|
| 171 |
+
command=/app/venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000
|
| 172 |
+
directory=/app/api
|
| 173 |
+
environment=PYTHONPATH=/app,POSTGRES_URI_CORE=%(ENV_POSTGRES_URI_CORE)s,POSTGRES_URI_TRACING=%(ENV_POSTGRES_URI_TRACING)s,REDIS_URI=%(ENV_REDIS_URI)s,AGENTA_AUTH_KEY=%(ENV_AGENTA_AUTH_KEY)s,AGENTA_CRYPT_KEY=%(ENV_AGENTA_CRYPT_KEY)s,AGENTA_API_URL=%(ENV_AGENTA_API_URL)s,AGENTA_WEB_URL=%(ENV_AGENTA_WEB_URL)s
|
| 174 |
+
autostart=true
|
| 175 |
+
autorestart=true
|
| 176 |
+
stderr_logfile=/var/log/supervisor/api.err.log
|
| 177 |
+
stdout_logfile=/var/log/supervisor/api.out.log
|
| 178 |
+
priority=10
|
| 179 |
+
startsecs=5
|
| 180 |
+
|
| 181 |
+
[program:agenta-web]
|
| 182 |
+
command=node server.js
|
| 183 |
+
directory=/app/web/.next/standalone
|
| 184 |
+
environment=PORT=3000,HOSTNAME=0.0.0.0,NEXT_PUBLIC_AGENTA_API_URL=http://localhost:7860/api
|
| 185 |
+
autostart=true
|
| 186 |
+
autorestart=true
|
| 187 |
+
stderr_logfile=/var/log/supervisor/web.err.log
|
| 188 |
+
stdout_logfile=/var/log/supervisor/web.out.log
|
| 189 |
+
priority=20
|
| 190 |
+
startsecs=5
|
| 191 |
+
|
| 192 |
+
[program:nginx]
|
| 193 |
+
command=/usr/sbin/nginx -g "daemon off;"
|
| 194 |
+
autostart=true
|
| 195 |
+
autorestart=true
|
| 196 |
+
stderr_logfile=/var/log/supervisor/nginx.err.log
|
| 197 |
+
stdout_logfile=/var/log/supervisor/nginx.out.log
|
| 198 |
+
priority=30
|
| 199 |
+
EOF
|
| 200 |
+
|
| 201 |
+
# ---------- Entrypoint script ----------
|
| 202 |
+
RUN cat > /app/entrypoint.sh <<'SCRIPT'
|
| 203 |
+
#!/bin/bash
|
| 204 |
+
set -e
|
| 205 |
+
|
| 206 |
+
echo "==> Waiting for PostgreSQL to be ready..."
|
| 207 |
+
su -c "/usr/lib/postgresql/14/bin/pg_ctl start -D /var/lib/postgresql/14/main" postgres &
|
| 208 |
+
sleep 4
|
| 209 |
+
|
| 210 |
+
echo "==> Running Agenta DB migrations..."
|
| 211 |
+
cd /app && /app/venv/bin/python -m alembic \
|
| 212 |
+
-c oss/databases/postgres/migrations/core/alembic.ini upgrade head 2>/dev/null || \
|
| 213 |
+
echo "Migration step skipped or already up to date."
|
| 214 |
+
|
| 215 |
+
echo "==> Starting all services via supervisord..."
|
| 216 |
+
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
|
| 217 |
+
SCRIPT
|
| 218 |
+
RUN chmod +x /app/entrypoint.sh
|
| 219 |
+
|
| 220 |
+
# ---------- Expose port ----------
|
| 221 |
EXPOSE 7860
|
| 222 |
|
| 223 |
+
# ---------- Run ----------
|
| 224 |
+
CMD ["/app/entrypoint.sh"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|