Skip to content

Commit

Permalink
Merge pull request #108 from dbpunk-labs/105-check-the-required-docke…
Browse files Browse the repository at this point in the history
…r-version

feat: support environment check
  • Loading branch information
imotai authored Oct 4, 2023
2 parents 9d379e9 + efd3456 commit a0596de
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
66 changes: 63 additions & 3 deletions up/src/og_up/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,55 @@ def refresh(
live.refresh()


def check_the_env(live, segments, need_docker=True):
# check the python version
spinner = Spinner("dots", style="status.spinner", speed=1.0, text="")
step = "Check the environment"
segments.append((spinner, step, ""))
refresh(live, segments)
version_ctrl = sys.version.split(" ")[0].split(".")
if version_ctrl[0] != "3":
old_segment = segments.pop()
segments.append(("❌", "Check the environment", "Python3 is required"))
refresh(live, segments)
return False, "Python3 is required"
if int(version_ctrl[1]) < 10:
old_segment = segments.pop()
segments.append(("❌", "Check the environment", "Python3.10 is required"))
refresh(live, segments)
return False, "Python3.10 is required"
if need_docker:
command = ["docker", "version", "--help"]
all_output = ""
result_code = 0
for code, output in run_with_realtime_print(command):
result_code = code
all_output += output
if result_code != 0:
old_segment = segments.pop()
segments.append(("❌", "Check the environment", "Docker is required"))
refresh(live, segments)
return False, "Docker is required"
if all_output.find("json") < 0:
old_segment = segments.pop()
segments.append(("❌", "Check the environment", "Please upgrade the docker"))
refresh(live, segments)
return False, "Upgrade the docker"
command = ["docker", "ps"]
result_code = 0
for code, _ in run_with_realtime_print(command):
result_code = code
if result_code != 0:
old_segment = segments.pop()
segments.append(("❌", "Check the environment", "Docker is not running"))
refresh(live, segments)
return False, "Docker is not running"
old_segment = segments.pop()
segments.append(("✅", "Check the environment", ""))
refresh(live, segments)
return True, ""


def get_latest_release_version(repo_name, live, segments):
"""
get the latest release version
Expand Down Expand Up @@ -267,7 +316,7 @@ def generate_agent_openai(
fd.write("max_file_size=202400000\n")
fd.write("max_iterations=8\n")
fd.write("log_level=debug\n")
segments.append(("✅", "Generate Agent Config", f"{agent_dir}/.env"))
segments.append(("✅", "Generate agent config", f"{agent_dir}/.env"))
refresh(live, segments)


Expand All @@ -282,7 +331,7 @@ def generate_agent_codellama(live, segments, install_dir, admin_key):
fd.write("max_file_size=202400000\n")
fd.write("max_iterations=8\n")
fd.write("log_level=debug\n")
segments.append(("✅", "Generate Agent Config", f"{agent_dir}/.env"))
segments.append(("✅", "Generate agent config", f"{agent_dir}/.env"))
refresh(live, segments)


Expand All @@ -299,7 +348,7 @@ def generate_kernel_env(live, segments, install_dir, rpc_key):
fd.write("rpc_host=127.0.0.1\n")
fd.write("rpc_port=9527\n")
fd.write(f"rpc_key={rpc_key}\n")
segments.append(("✅", "Generate Kernel Config", f"{kernel_dir}/.env"))
segments.append(("✅", "Generate kernel config", f"{kernel_dir}/.env"))
refresh(live, segments)


Expand Down Expand Up @@ -544,14 +593,25 @@ def init_octogen(
with Live(Group(*segments), console=console) as live:
run_install_cli(live, segments)
if choice == "4":
check_result, _ = check_the_env(live, segments, need_docker=False)
if not check_result:
segments.append(("❌", "Setup octogen failed", ""))
refresh(live, segments)
return
update_cli_config(live, segments, key, real_cli_dir, api_base)
segments.append(("👍", "Setup octogen done", ""))
refresh(live, segments)
return
check_result, _ = check_the_env(live, segments, need_docker=True)
if not check_result:
segments.append(("❌", "Setup octogen failed", ""))
refresh(live, segments)
return
if octogen_version:
version = octogen_version
else:
version = get_latest_release_version(repo_name, live, segments)

code = load_docker_image(version, image_name, live, segments)
if code != 0:
return
Expand Down
16 changes: 16 additions & 0 deletions up/tests/up_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from og_up.up import random_str
from og_up.up import generate_agent_common, generate_agent_azure_openai, generate_agent_openai, generate_agent_codellama
from og_up.up import generate_kernel_env
from og_up.up import check_the_env
from rich.console import Group
from dotenv import dotenv_values

Expand Down Expand Up @@ -97,6 +98,21 @@ def test_generate_agent_env_azure_openai():
assert config["admin_key"] == admin_key, "bad admin key"


@pytest.mark.skipif(sys.platform.startswith("win"), reason="skip on windows")
def test_check_the_env():
console = Console()
segments = []
with Live(Group(*segments), console=console) as live:
result, msg = check_the_env(live, segments)
assert result

def test_check_the_env_win():
console = Console()
segments = []
with Live(Group(*segments), console=console) as live:
result, msg = check_the_env(live, segments, need_docker=False)
assert result

def test_run_print():
use_dir = os.path.expanduser("~")
command = ["ls", use_dir]
Expand Down

0 comments on commit a0596de

Please sign in to comment.