File size: 3,021 Bytes
b9ba589
 
5b9367d
b9ba589
 
 
 
 
 
5b9367d
b9ba589
ecb7a1f
 
 
5b9367d
 
b9ba589
 
5b9367d
ecb7a1f
 
b9ba589
 
 
ecb7a1f
b9ba589
5b9367d
ecb7a1f
b9ba589
5b9367d
b9ba589
 
5b9367d
b9ba589
5b9367d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9ba589
5b9367d
 
 
b9ba589
 
 
5b9367d
 
edbbeec
5b9367d
b9ba589
72b329b
b9ba589
5b9367d
b9ba589
5b9367d
ecb7a1f
 
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
#!/bin/bash

echo "[boot] Configuring Kaggle credentials..."
if [ -n "$KAGGLE_USERNAME" ] && [ -n "$KAGGLE_KEY" ]; then
    mkdir -p ~/.kaggle
    printf '{"username":"%s","key":"%s"}' "$KAGGLE_USERNAME" "$KAGGLE_KEY" > ~/.kaggle/kaggle.json
    chmod 600 ~/.kaggle/kaggle.json
fi

echo "[boot] Configuring YouTube client secrets..."
if [ -n "$YOUTUBE_CLIENT_ID" ] && [ -n "$YOUTUBE_CLIENT_SECRET" ]; then
    python3 -c "
import json,os
d={'installed':{'client_id':os.environ['YOUTUBE_CLIENT_ID'],'project_id':'yt-ai-bot','auth_uri':'https://accounts.google.com/o/oauth2/auth','token_uri':'https://oauth2.googleapis.com/token','auth_provider_x509_cert_url':'https://www.googleapis.com/oauth2/v1/certs','client_secret':os.environ['YOUTUBE_CLIENT_SECRET'],'redirect_uris':['http://localhost']}}
open('/app/client_secrets.json','w').write(json.dumps(d))
print('[boot] client_secrets.json written')"
fi

echo "[boot] Pulling state from HF Dataset..."
python3 -c "
import sys; sys.path.insert(0,'/app')
try:
    from sync_hub import pull_state
    from pathlib import Path
    pull_state(Path('/app'))
except Exception as e:
    print(f'[boot] Hub pull skipped: {e}')
"

echo "[boot] Starting nginx..."
nginx

echo "[boot] Starting Ollama..."
OLLAMA_HOST=127.0.0.1 ollama serve &

echo "[boot] Starting status server on port 8080..."
python3 -c "
import http.server, threading, os, time

class Handler(http.server.BaseHTTPRequestHandler):
    def do_GET(self):
        try:
            log = open('/app/pipeline.log').read()[-3000:]
        except:
            log = 'No log yet.'
        body = f'''<!DOCTYPE html><html><head><meta charset=utf-8>
<meta http-equiv=refresh content=30>
<title>YT Pipeline</title>
<style>body{{font-family:monospace;background:#111;color:#0f0;padding:20px}}
pre{{background:#000;padding:10px;overflow-x:auto;white-space:pre-wrap}}</style>
</head><body>
<h2>YouTube Shorts Pipeline</h2>
<p>Space is running. Pipeline log (last 3000 chars, auto-refreshes every 30s):</p>
<pre>{log}</pre>
</body></html>'''.encode()
        self.send_response(200)
        self.send_header('Content-Type','text/html')
        self.send_header('Content-Length',str(len(body)))
        self.end_headers()
        self.wfile.write(body)
    def log_message(self, *a): pass

httpd = http.server.HTTPServer(('0.0.0.0', 8080), Handler)
print('[status] Server running on port 8080')
httpd.serve_forever()
" &

echo "[boot] Waiting for Ollama..."
for i in $(seq 1 60); do
    if curl -sf http://127.0.0.1:11434/api/tags > /dev/null 2>&1; then
        echo "[boot] Ollama ready after ${i}s"; break
    fi
    sleep 2
done

echo "[boot] Pulling qwen2.5-coder:7b-instruct..."
ollama pull qwen2.5-coder:7b-instruct

echo "[boot] Starting pipeline..."
python3 /app/automation.py >> /app/pipeline.log 2>&1 &
echo "[boot] Pipeline PID: $!"

echo "[boot] Trying OpenClaw (optional)..."
export OLLAMA_HOST=http://127.0.0.1:11434
openclaw gateway start || echo "[boot] OpenClaw unavailable, status server is active"

sleep infinity