File size: 3,189 Bytes
6ab316e
 
d2ac0ec
6ab316e
d2ac0ec
6ab316e
 
 
 
 
ef6a2f3
 
6ab316e
 
 
ef6a2f3
6ab316e
75fefa7
6ab316e
f0b07c1
 
75fefa7
6ab316e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d2ac0ec
6ab316e
 
75fefa7
6ab316e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0b07c1
75fefa7
6ab316e
 
 
 
d2ac0ec
6ab316e
 
 
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
# Use Python 3.11 image for better compatibility
FROM python:3.11-slim-bookworm

LABEL description="Dockerfile for Agent-Zero on Hugging Face Spaces"

# Avoid prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    openssl \
    procps \
    zstd \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Install uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"

# Use the official Ollama installation script
RUN curl -fsSL https://ollama.com/install.sh | sh

# Clone the agent-zero repository
RUN git clone --branch fix-initialize-mcp-nameerror https://github.com/JsonLord/agent-zero.git /app

# Copy the local files to overwrite or add to the repository
COPY requirements.txt /app/requirements.txt
COPY run_ui.py /app/run_ui.py
COPY models.py /app/models.py
COPY whisper.py /app/python/helpers/whisper.py
COPY webui/js/api.js /app/webui/js/api.js
COPY webui/index.html /app/webui/index.html
COPY webui/js/index.js /app/webui/js/index.js
COPY preload.py /app/preload.py
COPY python/extensions/system_prompt/_10_system_prompt.py /app/python/extensions/system_prompt/_10_system_prompt.py
COPY python/helpers/searxng.py /app/python/helpers/searxng.py
COPY python/helpers/settings.py /app/python/helpers/settings.py
COPY python/helpers/csrf.py /app/python/helpers/csrf.py
COPY python/api/csrf_token.py /app/python/api/csrf_token.py
COPY start.sh /app/start.sh
COPY python/tools/search_engine.py /app/python/tools/search_engine.py
COPY initialize.py /app/initialize.py

# New API handlers
COPY python/api/health.py /app/python/api/health.py
COPY python/api/chat.py /app/python/api/chat.py
COPY python/api/stream.py /app/python/api/stream.py
COPY python/api/set.py /app/python/api/set.py
COPY python/api/get.py /app/python/api/get.py
COPY python/api/docs.py /app/python/api/docs.py

# New extensions
COPY python/extensions/response_stream/_30_api_stream.py /app/python/extensions/response_stream/_30_api_stream.py
COPY python/extensions/reasoning_stream/_30_api_stream.py /app/python/extensions/reasoning_stream/_30_api_stream.py

# Set the working directory for the next steps
WORKDIR /app

# --- DEFINITIVE FIX: GENERATE KEY AT BUILD TIME ---
RUN echo "FLASK_SECRET_KEY=$(openssl rand -hex 32)" > .env

# Install Python dependencies from requirements.txt using uv
RUN uv pip install --system --no-cache -r requirements.txt

# Pre-download the required spaCy model during the build
RUN python -m spacy download en_core_web_sm

# Manually create the 'ollama' group
RUN groupadd -r ollama

# Create a non-root user for security
RUN useradd --create-home --shell /bin/bash user

# Add the user to the 'ollama' group so it can use the service
RUN usermod -aG ollama user

# Grant the non-root user ownership of the application directory
RUN chown -R user:user /app

# Make start.sh executable
RUN chmod +x /app/start.sh

# Switch to the non-root user
USER user

# Set the final working directory
WORKDIR /app

# Expose the application port (Hugging Face standard is 7860)
EXPOSE 7860

# Command to start the services
CMD ["/app/start.sh"]