File size: 2,116 Bytes
cd8bd0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import subprocess
import sys
import urllib.request
import tarfile

print("=== Starting OmniRoute Installation ===")

# Try to check Node.js version, and download v22.13.0 if missing or older
try:
    node_version = subprocess.check_output(["node", "--version"], stderr=subprocess.DEVNULL).decode().strip()
    print(f"Detected system Node.js version: {node_version}")
    major_version = int(node_version.split(".")[0].replace("v", ""))
except Exception:
    node_version = None
    major_version = 0

if major_version < 22:
    print("Node.js version is older than v22 or missing. Downloading Node.js v22.13.0 (x64)...")
    node_url = "https://nodejs.org/dist/v22.13.0/node-v22.13.0-linux-x64.tar.xz"
    tar_path = "/tmp/node.tar.xz"
    node_dir = os.path.abspath("node_runtime")
    
    if not os.path.exists(node_dir):
        print(f"Downloading from {node_url}...")
        urllib.request.urlretrieve(node_url, tar_path)
        print("Extracting Node.js binary...")
        os.makedirs(node_dir, exist_ok=True)
        subprocess.run(["tar", "-xJf", tar_path, "-C", node_dir, "--strip-components=1"], check=True)
        print("Extraction complete!")
        
    # Configure PATH to use the custom Node.js binaries
    node_bin = os.path.join(node_dir, "bin")
    os.environ["PATH"] = f"{node_bin}:{os.environ.get('PATH', '')}"
    print(f"Updated PATH: {os.environ['PATH']}")
    
    # Verify the updated version
    new_version = subprocess.check_output(["node", "--version"]).decode().strip()
    print(f"New configured Node.js version: {new_version}")

# 1. Install Node.js dependencies
print("Installing npm packages...")
subprocess.run(["npm", "install"], check=True)

# 2. Build the Next.js production build
print("Building Next.js application...")
subprocess.run(["npm", "run", "build"], check=True)

# 3. Configure environment variables for port 7860
os.environ["PORT"] = "7860"
os.environ["DATA_DIR"] = os.path.abspath("data")

# 4. Start the OmniRoute server
print("Starting OmniRoute server on port 7860...")
subprocess.run(["node", "scripts/dev/run-standalone.mjs"], check=True)