Update Dockerfile
Browse files- Dockerfile +48 -8
Dockerfile
CHANGED
|
@@ -3,9 +3,9 @@ FROM gitea/gitea:1.24.6
|
|
| 3 |
# 以 root 用户设置权限(Spaces 允许构建时使用 root)
|
| 4 |
USER root
|
| 5 |
|
| 6 |
-
# 安装 Python、pip、git 和异步库
|
| 7 |
RUN apk update && \
|
| 8 |
-
apk add python3 py3-pip git && \
|
| 9 |
pip3 install --break-system-packages --upgrade pip
|
| 10 |
|
| 11 |
# 安装 Python 包,包括 pytz
|
|
@@ -109,7 +109,7 @@ if __name__ == "__main__":
|
|
| 109 |
exit(1)
|
| 110 |
EOF
|
| 111 |
|
| 112 |
-
# 复制上传脚本,恢复第一版
|
| 113 |
COPY --chown=git:git <<'EOF' /uploadhf.py
|
| 114 |
import os
|
| 115 |
import time
|
|
@@ -225,23 +225,63 @@ def start_directory_monitoring(data_directory="/data", repo_id=None, hf_token=No
|
|
| 225 |
return observer
|
| 226 |
|
| 227 |
def start_gitea_server(port=7860):
|
| 228 |
-
"""启动 Gitea 服务器"""
|
| 229 |
def run_gitea():
|
| 230 |
max_restart_attempts = 5
|
| 231 |
restart_delay = 10 # 每次重启前的等待时间(秒)
|
|
|
|
| 232 |
attempt = 0
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
while attempt < max_restart_attempts:
|
| 235 |
try:
|
|
|
|
| 236 |
gitea_process = subprocess.Popen(
|
| 237 |
['gitea', 'web', '--port', str(port)],
|
| 238 |
stdout=subprocess.PIPE,
|
| 239 |
stderr=subprocess.PIPE,
|
| 240 |
universal_newlines=True
|
| 241 |
)
|
| 242 |
-
logger.info(f"🚀 Gitea 服务器
|
| 243 |
logger.info(f"📊 访问地址: http://localhost:{port}")
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
while True:
|
| 246 |
output = gitea_process.stdout.readline()
|
| 247 |
if output == '' and gitea_process.poll() is not None:
|
|
@@ -259,7 +299,7 @@ def start_gitea_server(port=7860):
|
|
| 259 |
logger.info(f"将在 {restart_delay} 秒后尝试重启 Gitea (尝试 {attempt + 1}/{max_restart_attempts})")
|
| 260 |
time.sleep(restart_delay)
|
| 261 |
else:
|
| 262 |
-
logger.error(f"❌ 达到最大重
|
| 263 |
exit(1)
|
| 264 |
else:
|
| 265 |
logger.info("✅ Gitea 服务器正常退出")
|
|
@@ -316,7 +356,7 @@ async def main():
|
|
| 316 |
|
| 317 |
logger.info("✅ 所有服务已启动完成!")
|
| 318 |
logger.info("📁 目录监控: /data → Hugging Face Hub")
|
| 319 |
-
logger.info("🌐 Gitea 服务: http://localhost:
|
| 320 |
logger.info("🛑 按 Ctrl+C 停止所有服务")
|
| 321 |
|
| 322 |
try:
|
|
|
|
| 3 |
# 以 root 用户设置权限(Spaces 允许构建时使用 root)
|
| 4 |
USER root
|
| 5 |
|
| 6 |
+
# 安装 Python、pip、git、curl 和异步库
|
| 7 |
RUN apk update && \
|
| 8 |
+
apk add python3 py3-pip git curl && \
|
| 9 |
pip3 install --break-system-packages --upgrade pip
|
| 10 |
|
| 11 |
# 安装 Python 包,包括 pytz
|
|
|
|
| 109 |
exit(1)
|
| 110 |
EOF
|
| 111 |
|
| 112 |
+
# 复制上传脚本,恢复第一版错误抛出逻辑,修复卡在 starting 问题
|
| 113 |
COPY --chown=git:git <<'EOF' /uploadhf.py
|
| 114 |
import os
|
| 115 |
import time
|
|
|
|
| 225 |
return observer
|
| 226 |
|
| 227 |
def start_gitea_server(port=7860):
|
| 228 |
+
"""启动 Gitea 服务器,包含健康检查"""
|
| 229 |
def run_gitea():
|
| 230 |
max_restart_attempts = 5
|
| 231 |
restart_delay = 10 # 每次重启前的等待时间(秒)
|
| 232 |
+
health_check_timeout = 30 # 健康检查超时时间(秒)
|
| 233 |
attempt = 0
|
| 234 |
|
| 235 |
+
# 检查 /data 目录权限
|
| 236 |
+
logger.info("检查 /data 目录权限")
|
| 237 |
+
os.system("ls -la /data 2>/dev/null")
|
| 238 |
+
os.system("ls -la /data/gitea 2>/dev/null || echo '/data/gitea 不存在'")
|
| 239 |
+
|
| 240 |
while attempt < max_restart_attempts:
|
| 241 |
try:
|
| 242 |
+
# 启动 Gitea 进程
|
| 243 |
gitea_process = subprocess.Popen(
|
| 244 |
['gitea', 'web', '--port', str(port)],
|
| 245 |
stdout=subprocess.PIPE,
|
| 246 |
stderr=subprocess.PIPE,
|
| 247 |
universal_newlines=True
|
| 248 |
)
|
| 249 |
+
logger.info(f"🚀 Gitea 服务器启动尝试 {attempt + 1}/{max_restart_attempts},端口: {port}")
|
| 250 |
logger.info(f"📊 访问地址: http://localhost:{port}")
|
| 251 |
+
|
| 252 |
+
# 健康检查:等待 Gitea 响应
|
| 253 |
+
start_time = time.time()
|
| 254 |
+
health_check_passed = False
|
| 255 |
+
while time.time() - start_time < health_check_timeout:
|
| 256 |
+
try:
|
| 257 |
+
result = subprocess.run(
|
| 258 |
+
['curl', '-s', '-f', f'http://localhost:{port}/'],
|
| 259 |
+
capture_output=True, text=True, timeout=5
|
| 260 |
+
)
|
| 261 |
+
if result.returncode == 0:
|
| 262 |
+
logger.info("✅ Gitea 健康检查通过")
|
| 263 |
+
health_check_passed = True
|
| 264 |
+
break
|
| 265 |
+
except subprocess.SubprocessError:
|
| 266 |
+
pass
|
| 267 |
+
time.sleep(1)
|
| 268 |
+
|
| 269 |
+
if not health_check_passed:
|
| 270 |
+
logger.error("❌ Gitea 健康检查失败,服务未就绪")
|
| 271 |
+
gitea_process.terminate()
|
| 272 |
+
error_output = gitea_process.stderr.read()
|
| 273 |
+
if error_output:
|
| 274 |
+
logger.error(f"错误信息: {error_output.strip()}")
|
| 275 |
+
attempt += 1
|
| 276 |
+
if attempt < max_restart_attempts:
|
| 277 |
+
logger.info(f"将在 {restart_delay} 秒后尝试重启 Gitea (尝试 {attempt + 1}/{max_restart_attempts})")
|
| 278 |
+
time.sleep(restart_delay)
|
| 279 |
+
else:
|
| 280 |
+
logger.error(f"❌ 达到最大重试次数,Gitea 启动失败")
|
| 281 |
+
exit(1)
|
| 282 |
+
continue
|
| 283 |
+
|
| 284 |
+
# 监控 Gitea 输出
|
| 285 |
while True:
|
| 286 |
output = gitea_process.stdout.readline()
|
| 287 |
if output == '' and gitea_process.poll() is not None:
|
|
|
|
| 299 |
logger.info(f"将在 {restart_delay} 秒后尝试重启 Gitea (尝试 {attempt + 1}/{max_restart_attempts})")
|
| 300 |
time.sleep(restart_delay)
|
| 301 |
else:
|
| 302 |
+
logger.error(f"❌ 达到最大重试次数,Gitea 启动失败")
|
| 303 |
exit(1)
|
| 304 |
else:
|
| 305 |
logger.info("✅ Gitea 服务器正常退出")
|
|
|
|
| 356 |
|
| 357 |
logger.info("✅ 所有服务已启动完成!")
|
| 358 |
logger.info("📁 目录监控: /data → Hugging Face Hub")
|
| 359 |
+
logger.info(f"🌐 Gitea 服务: http://localhost:{CONFIG['gitea_port']}")
|
| 360 |
logger.info("🛑 按 Ctrl+C 停止所有服务")
|
| 361 |
|
| 362 |
try:
|