Полная переработка контейнера с добавлением диагностики и исправлением структуры файлов
Browse files- Dockerfile +59 -28
- app.py +66 -15
Dockerfile
CHANGED
|
@@ -38,9 +38,6 @@ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
|
| 38 |
apt-get install -y nodejs && \
|
| 39 |
npm install -g pnpm
|
| 40 |
|
| 41 |
-
# Создаем пользователя
|
| 42 |
-
RUN useradd -m -s /bin/bash tenuser
|
| 43 |
-
|
| 44 |
# Устанавливаем рабочую директорию
|
| 45 |
WORKDIR /app
|
| 46 |
|
|
@@ -50,17 +47,17 @@ RUN git clone --depth 1 https://github.com/TEN-framework/TEN-Agent.git /app && \
|
|
| 50 |
git branch -a && \
|
| 51 |
git tag -l
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
# Создаем необходимые директории и устанавливаем права
|
| 54 |
RUN mkdir -p /app/server/bin && \
|
| 55 |
mkdir -p /app/agents && \
|
| 56 |
mkdir -p /tmp/ten_agent && \
|
| 57 |
-
mkdir -p /app/.pnpm-store
|
| 58 |
-
chown -R tenuser:tenuser /app && \
|
| 59 |
-
chown -R tenuser:tenuser /tmp/ten_agent
|
| 60 |
|
| 61 |
# Копируем .env файл
|
| 62 |
COPY .env /app/.env
|
| 63 |
-
RUN chown tenuser:tenuser /app/.env
|
| 64 |
|
| 65 |
# Компилируем сервер
|
| 66 |
RUN cd /app/server && \
|
|
@@ -69,7 +66,41 @@ RUN cd /app/server && \
|
|
| 69 |
go build -o bin/api main.go && \
|
| 70 |
chmod +x bin/api
|
| 71 |
|
| 72 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
RUN echo '{\n\
|
| 74 |
"name": "TEN Agent Example",\n\
|
| 75 |
"version": "0.0.1",\n\
|
|
@@ -79,37 +110,37 @@ RUN echo '{\n\
|
|
| 79 |
{\n\
|
| 80 |
"name": "Voice Agent",\n\
|
| 81 |
"description": "Basic voice agent with OpenAI",\n\
|
| 82 |
-
"file": "
|
| 83 |
},\n\
|
| 84 |
{\n\
|
| 85 |
"name": "Chat Agent",\n\
|
| 86 |
"description": "Simple chat agent",\n\
|
| 87 |
-
"file": "
|
| 88 |
}\n\
|
| 89 |
]\n\
|
| 90 |
}' > /app/agents/property.json
|
| 91 |
|
| 92 |
-
# Убедимся, что файл property.json существует во всех возможных местах
|
| 93 |
-
RUN cp /app/agents/property.json /app/property.json && \
|
| 94 |
-
mkdir -p /app/agents/examples/default && \
|
| 95 |
-
cp /app/agents/property.json /app/agents/examples/default/ && \
|
| 96 |
-
mkdir -p /app/agents/examples && \
|
| 97 |
-
cp /app/agents/property.json /app/agents/examples/ && \
|
| 98 |
-
chmod -R 777 /app/agents && \
|
| 99 |
-
ls -la /app/agents
|
| 100 |
-
|
| 101 |
# Создаем простые примеры графов
|
| 102 |
-
RUN
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
#
|
| 113 |
COPY app.py /app/app.py
|
| 114 |
RUN chmod +x /app/app.py
|
| 115 |
|
|
|
|
| 38 |
apt-get install -y nodejs && \
|
| 39 |
npm install -g pnpm
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
# Устанавливаем рабочую директорию
|
| 42 |
WORKDIR /app
|
| 43 |
|
|
|
|
| 47 |
git branch -a && \
|
| 48 |
git tag -l
|
| 49 |
|
| 50 |
+
# Устанавливаем task для сборки
|
| 51 |
+
RUN go install github.com/go-task/task/v3/cmd/task@latest
|
| 52 |
+
|
| 53 |
# Создаем необходимые директории и устанавливаем права
|
| 54 |
RUN mkdir -p /app/server/bin && \
|
| 55 |
mkdir -p /app/agents && \
|
| 56 |
mkdir -p /tmp/ten_agent && \
|
| 57 |
+
mkdir -p /app/.pnpm-store
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# Копируем .env файл
|
| 60 |
COPY .env /app/.env
|
|
|
|
| 61 |
|
| 62 |
# Компилируем сервер
|
| 63 |
RUN cd /app/server && \
|
|
|
|
| 66 |
go build -o bin/api main.go && \
|
| 67 |
chmod +x bin/api
|
| 68 |
|
| 69 |
+
# Установка зависимостей для Playground UI
|
| 70 |
+
ENV PNPM_HOME="/app/.pnpm-store"
|
| 71 |
+
ENV PATH="$PNPM_HOME:$PATH"
|
| 72 |
+
RUN cd /app/playground && \
|
| 73 |
+
pnpm install
|
| 74 |
+
|
| 75 |
+
# Подготавливаем пример агента для работы Select Graph
|
| 76 |
+
RUN cd /app && \
|
| 77 |
+
mkdir -p agents/examples && \
|
| 78 |
+
mkdir -p agents/examples/default && \
|
| 79 |
+
mkdir -p agents/examples/demo && \
|
| 80 |
+
mkdir -p agents/examples/experimental
|
| 81 |
+
|
| 82 |
+
# Копируем примеры из репозитория
|
| 83 |
+
RUN cd /app && \
|
| 84 |
+
cp -r agents/examples/default agents/ && \
|
| 85 |
+
cp -r agents/examples/demo agents/ && \
|
| 86 |
+
cp -r agents/examples/experimental agents/
|
| 87 |
+
|
| 88 |
+
# Создаем базовый manifest.json
|
| 89 |
+
RUN echo '{\n\
|
| 90 |
+
"name": "default",\n\
|
| 91 |
+
"agents": [\n\
|
| 92 |
+
{\n\
|
| 93 |
+
"name": "voice_agent",\n\
|
| 94 |
+
"description": "A simple voice agent"\n\
|
| 95 |
+
},\n\
|
| 96 |
+
{\n\
|
| 97 |
+
"name": "chat_agent",\n\
|
| 98 |
+
"description": "A text chat agent"\n\
|
| 99 |
+
}\n\
|
| 100 |
+
]\n\
|
| 101 |
+
}' > /app/agents/manifest.json
|
| 102 |
+
|
| 103 |
+
# Создаем базовый property.json
|
| 104 |
RUN echo '{\n\
|
| 105 |
"name": "TEN Agent Example",\n\
|
| 106 |
"version": "0.0.1",\n\
|
|
|
|
| 110 |
{\n\
|
| 111 |
"name": "Voice Agent",\n\
|
| 112 |
"description": "Basic voice agent with OpenAI",\n\
|
| 113 |
+
"file": "voice_agent.json"\n\
|
| 114 |
},\n\
|
| 115 |
{\n\
|
| 116 |
"name": "Chat Agent",\n\
|
| 117 |
"description": "Simple chat agent",\n\
|
| 118 |
+
"file": "chat_agent.json"\n\
|
| 119 |
}\n\
|
| 120 |
]\n\
|
| 121 |
}' > /app/agents/property.json
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
# Создаем простые примеры графов
|
| 124 |
+
RUN echo '{\n\
|
| 125 |
+
"nodes": [],\n\
|
| 126 |
+
"edges": [],\n\
|
| 127 |
+
"groups": [],\n\
|
| 128 |
+
"templates": [],\n\
|
| 129 |
+
"root": null\n\
|
| 130 |
+
}' > /app/agents/voice_agent.json
|
| 131 |
|
| 132 |
+
RUN echo '{\n\
|
| 133 |
+
"nodes": [],\n\
|
| 134 |
+
"edges": [],\n\
|
| 135 |
+
"groups": [],\n\
|
| 136 |
+
"templates": [],\n\
|
| 137 |
+
"root": null\n\
|
| 138 |
+
}' > /app/agents/chat_agent.json
|
| 139 |
+
|
| 140 |
+
# Устанавливаем правильные права доступа для всех файлов
|
| 141 |
+
RUN chmod -R 777 /app
|
| 142 |
|
| 143 |
+
# Настраиваем стартовый скрипт
|
| 144 |
COPY app.py /app/app.py
|
| 145 |
RUN chmod +x /app/app.py
|
| 146 |
|
app.py
CHANGED
|
@@ -25,12 +25,12 @@ def check_and_create_property_json():
|
|
| 25 |
{
|
| 26 |
"name": "Voice Agent",
|
| 27 |
"description": "Basic voice agent with OpenAI",
|
| 28 |
-
"file": "
|
| 29 |
},
|
| 30 |
{
|
| 31 |
"name": "Chat Agent",
|
| 32 |
"description": "Simple chat agent",
|
| 33 |
-
"file": "
|
| 34 |
}
|
| 35 |
]
|
| 36 |
}
|
|
@@ -41,19 +41,65 @@ def check_and_create_property_json():
|
|
| 41 |
# Записываем файл
|
| 42 |
with open(property_path, 'w') as f:
|
| 43 |
json.dump(property_data, f, indent=2)
|
| 44 |
-
|
| 45 |
-
# Создаем пустые файлы графов
|
| 46 |
-
examples_dir = property_path.parent / "examples"
|
| 47 |
-
examples_dir.mkdir(parents=True, exist_ok=True)
|
| 48 |
-
|
| 49 |
-
with open(examples_dir / "voice_agent.json", 'w') as f:
|
| 50 |
-
f.write('{"nodes":[]}')
|
| 51 |
-
|
| 52 |
-
with open(examples_dir / "chat_agent.json", 'w') as f:
|
| 53 |
-
f.write('{"nodes":[]}')
|
| 54 |
-
|
| 55 |
print(f"Файл {property_path} создан успешно")
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
def main():
|
| 58 |
processes = []
|
| 59 |
try:
|
|
@@ -73,13 +119,18 @@ def main():
|
|
| 73 |
# Проверяем и создаем property.json
|
| 74 |
check_and_create_property_json()
|
| 75 |
|
|
|
|
|
|
|
|
|
|
| 76 |
# Запускаем API сервер
|
| 77 |
print("Starting TEN-Agent API server on port 8080...")
|
| 78 |
api_process = subprocess.Popen([str(api_binary)])
|
| 79 |
processes.append(api_process)
|
| 80 |
|
| 81 |
-
#
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Запускаем Playground UI в режиме dev на порту 7860 (порт Hugging Face)
|
| 85 |
print("Starting Playground UI in development mode on port 7860...")
|
|
|
|
| 25 |
{
|
| 26 |
"name": "Voice Agent",
|
| 27 |
"description": "Basic voice agent with OpenAI",
|
| 28 |
+
"file": "voice_agent.json"
|
| 29 |
},
|
| 30 |
{
|
| 31 |
"name": "Chat Agent",
|
| 32 |
"description": "Simple chat agent",
|
| 33 |
+
"file": "chat_agent.json"
|
| 34 |
}
|
| 35 |
]
|
| 36 |
}
|
|
|
|
| 41 |
# Записываем файл
|
| 42 |
with open(property_path, 'w') as f:
|
| 43 |
json.dump(property_data, f, indent=2)
|
| 44 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
print(f"Файл {property_path} создан успешно")
|
| 46 |
|
| 47 |
+
def check_files():
|
| 48 |
+
"""Проверяет и выводит информацию о важных файлах"""
|
| 49 |
+
files_to_check = [
|
| 50 |
+
"/app/agents/property.json",
|
| 51 |
+
"/app/agents/manifest.json",
|
| 52 |
+
"/app/agents/voice_agent.json",
|
| 53 |
+
"/app/agents/chat_agent.json",
|
| 54 |
+
"/app/server/bin/api"
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
print("\n=== Проверка критических файлов ===")
|
| 58 |
+
for file_path in files_to_check:
|
| 59 |
+
path = Path(file_path)
|
| 60 |
+
if path.exists():
|
| 61 |
+
if path.is_file():
|
| 62 |
+
size = path.stat().st_size
|
| 63 |
+
print(f"✅ {file_path} (размер: {size} байт)")
|
| 64 |
+
|
| 65 |
+
# Если это JSON файл, выводим его содержимое
|
| 66 |
+
if file_path.endswith('.json'):
|
| 67 |
+
try:
|
| 68 |
+
with open(file_path, 'r') as f:
|
| 69 |
+
content = json.load(f)
|
| 70 |
+
print(f" Содержимое: {json.dumps(content, indent=2)}")
|
| 71 |
+
except Exception as e:
|
| 72 |
+
print(f" Ошибка чтения JSON: {e}")
|
| 73 |
+
else:
|
| 74 |
+
print(f"❌ {file_path} (это директория, а не файл)")
|
| 75 |
+
else:
|
| 76 |
+
print(f"❌ {file_path} (файл не найден)")
|
| 77 |
+
|
| 78 |
+
print("\n=== Проверка структуры директорий ===")
|
| 79 |
+
print("Содержимое /app/agents:")
|
| 80 |
+
subprocess.run(["ls", "-la", "/app/agents"])
|
| 81 |
+
|
| 82 |
+
print("\nПроверка прав доступа:")
|
| 83 |
+
subprocess.run(["stat", "/app/agents"])
|
| 84 |
+
subprocess.run(["stat", "/app/agents/property.json"])
|
| 85 |
+
|
| 86 |
+
def test_api():
|
| 87 |
+
"""Делает запрос к API для получения списка графов"""
|
| 88 |
+
import urllib.request
|
| 89 |
+
import urllib.error
|
| 90 |
+
|
| 91 |
+
print("\n=== Тестирование API ===")
|
| 92 |
+
try:
|
| 93 |
+
# Даем серверу время запуститься
|
| 94 |
+
time.sleep(3)
|
| 95 |
+
with urllib.request.urlopen("http://localhost:8080/graphs") as response:
|
| 96 |
+
data = response.read().decode('utf-8')
|
| 97 |
+
print(f"Ответ /graphs: {data}")
|
| 98 |
+
except urllib.error.URLError as e:
|
| 99 |
+
print(f"Ошибка запроса к API: {e}")
|
| 100 |
+
except Exception as e:
|
| 101 |
+
print(f"Неизвестная ошибка при запросе к API: {e}")
|
| 102 |
+
|
| 103 |
def main():
|
| 104 |
processes = []
|
| 105 |
try:
|
|
|
|
| 119 |
# Проверяем и создаем property.json
|
| 120 |
check_and_create_property_json()
|
| 121 |
|
| 122 |
+
# Проверка файлов перед запуском
|
| 123 |
+
check_files()
|
| 124 |
+
|
| 125 |
# Запускаем API сервер
|
| 126 |
print("Starting TEN-Agent API server on port 8080...")
|
| 127 |
api_process = subprocess.Popen([str(api_binary)])
|
| 128 |
processes.append(api_process)
|
| 129 |
|
| 130 |
+
# Тестируем API
|
| 131 |
+
test_thread = threading.Thread(target=test_api)
|
| 132 |
+
test_thread.daemon = True
|
| 133 |
+
test_thread.start()
|
| 134 |
|
| 135 |
# Запускаем Playground UI в режиме dev на порту 7860 (порт Hugging Face)
|
| 136 |
print("Starting Playground UI in development mode on port 7860...")
|