Skip to content

Commit

Permalink
nexusctl
Browse files Browse the repository at this point in the history
  • Loading branch information
tuky191 committed Oct 29, 2024
1 parent 0f42ec5 commit d3c2035
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 40 deletions.
3 changes: 3 additions & 0 deletions docker/docker-compose-nollama.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include:
- ./sui/compose.yaml
- ./nexus/compose.yaml
1 change: 0 additions & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.8"
include:
- ./sui/compose.yaml
- ./ollama/compose.yaml
Expand Down
12 changes: 10 additions & 2 deletions docker/nexus/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

services:
tools:
container_name: tools
Expand All @@ -12,6 +10,11 @@ services:
restart: unless-stopped
environment:
OLLAMA_HOST: ${MODEL_URL}
logging:
driver: "json-file"
options:
max-file: "10"
max-size: "1g"
depends_on:
build-suitools:
condition: service_completed_successfully
Expand All @@ -30,6 +33,11 @@ services:
INSTALL_RUST: "true"
command: >
bash -c "source .venv/bin/activate && python start_events.py"
logging:
driver: "json-file"
options:
max-file: "10"
max-size: "1g"
environment:
RPC_URL: ${RPC_URL}
WS_URL: ${WS_URL}
Expand Down
42 changes: 37 additions & 5 deletions docker/nexusctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def detect_gpu_and_set_env():
print("NVIDIA GPU detected")
os.environ["OLLAMA_DEVICE_DRIVER"] = "nvidia"
os.environ["OLLAMA_DEVICE_COUNT"] = "all"
os.environ["OLLAMA_DEVICE_CAPABILITIES"] = "[gpu]"
os.environ["OLLAMA_DEVICE_CAPABILITIES"] = "gpu"
else:
print("No GPU detected")
os.environ["OLLAMA_DEVICE_DRIVER"] = ""
Expand All @@ -86,7 +86,7 @@ def detect_gpu_and_set_env():
print("NVIDIA GPU detected")
os.environ["OLLAMA_DEVICE_DRIVER"] = "nvidia"
os.environ["OLLAMA_DEVICE_COUNT"] = "all"
os.environ["OLLAMA_DEVICE_CAPABILITIES"] = "[gpu]"
os.environ["OLLAMA_DEVICE_CAPABILITIES"] = "gpu"
else:
print("No GPU detected")
os.environ["OLLAMA_DEVICE_DRIVER"] = ""
Expand Down Expand Up @@ -155,7 +155,6 @@ def start_ollama_serve():

def change_to_docker_directory():
try:
print(os.getcwd())
os.chdir("./docker")
print(f"Changed working directory to: {os.getcwd()}")
except FileNotFoundError:
Expand Down Expand Up @@ -197,6 +196,38 @@ def docker_compose_up():
print(f"Failed to run Docker Compose up: {e}")
sys.exit(1)

def docker_compose_build():
change_to_docker_directory()
os_type = platform.system()

compose_file = "docker-compose.yaml"
if os_type == "Darwin":
# Use a different compose file for macOS
compose_file = "docker-compose-nollama.yaml"
print("Using docker-compose-nollama.yaml for macOS")

# Override the MODEL_URL environment variable on macOS
os.environ["MODEL_URL"] = "http://host.docker.internal:11434"

# Load environment variables from the .env file
load_env_file(".env")

# Ensure the environment has the updated MODEL_URL for macOS
env_vars = os.environ.copy()
if os_type == "Darwin":
env_vars["MODEL_URL"] = "http://host.docker.internal:11434"

try:
# Use subprocess.run with env argument to override environment variables
subprocess.run(
["docker", "compose", "-f", compose_file, "build"],
check=True,
env=env_vars # Pass our modified environment with correct MODEL_URL
)
except subprocess.CalledProcessError as e:
print(f"Failed to run Docker Compose build: {e}")
sys.exit(1)

def docker_compose_down():
change_to_docker_directory()
os_type = platform.system()
Expand Down Expand Up @@ -263,10 +294,9 @@ def stop_ollama_serve():
else:
print(f"PID file {OLLAMA_PID_FILE} not found. Ollama server may not be running.")


def main():
parser = argparse.ArgumentParser(description="Control the Docker Compose deployment and overall environment.")
parser.add_argument("command", choices=["start", "stop", "delete"], help="Command to execute: start, stop, delete")
parser.add_argument("command", choices=["start", "stop", "delete", "create"], help="Command to execute: start, stop, delete, create")
args = parser.parse_args()

# Check Docker Compose version
Expand All @@ -286,6 +316,8 @@ def main():
elif args.command == "delete":
docker_compose_down()
docker_delete_volumes()
elif args.command == "create":
docker_compose_build()

if __name__ == "__main__":
main()
16 changes: 7 additions & 9 deletions docker/ollama/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
version: "3.8"

services:
ollama:
image: talus-network/ollama:${LLAMA_MODEL_VERSION_TAG}
container_name: ollama
# deploy:
# resources:
# reservations:
# devices:
# - driver: nvidia
# count: all
# capabilities: [gpu]
deploy:
resources:
reservations:
devices:
- driver: ${OLLAMA_DEVICE_DRIVER}
count: ${OLLAMA_DEVICE_COUNT}
capabilities: ["${OLLAMA_DEVICE_CAPABILITIES}"]
build:
context: "."
args:
Expand Down
14 changes: 0 additions & 14 deletions docker/sui/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
build-suitools:
restart: "no"
Expand Down Expand Up @@ -39,7 +37,6 @@ services:
- RPC_URL=${RPC_URL}

volumes:
- ./genesis/files:/opt/sui/genesis
- shared:/app/shared
- ./bin/publish_package.sh:/opt/sui/publish_package.sh:ro
- ./genesis/static/client.yaml:/opt/sui/config/client.yaml:rw
Expand All @@ -64,15 +61,12 @@ services:
volumes:
- validator1-db:/opt/sui/db:rw
- genesis:/opt/sui/config
# - ./genesis/files/validator1-8080.yaml:/opt/sui/config/validator.yaml:ro
# - ./genesis/files/genesis.blob:/opt/sui/config/genesis.blob:ro
command:
[
"/usr/local/bin/sui-node",
"--config-path",
"/opt/sui/config/validator1-8080.yaml",
]
# command: ["tail", "-f", "/dev/null"]

restart: on-failure
logging:
Expand All @@ -99,8 +93,6 @@ services:
volumes:
- validator2-db:/opt/sui/db:rw
- genesis:/opt/sui/config
# - ./genesis/files/validator2-8080.yaml:/opt/sui/config/validator.yaml:ro
# - ./genesis/files/genesis.blob:/opt/sui/config/genesis.blob:ro
command:
[
"/usr/local/bin/sui-node",
Expand Down Expand Up @@ -132,8 +124,6 @@ services:
volumes:
- validator3-db:/opt/sui/db:rw
- genesis:/opt/sui/config
# - ./genesis/files/validator3-8080.yaml:/opt/sui/config/validator.yaml:ro
# - ./genesis/files/genesis.blob:/opt/sui/config/genesis.blob:ro
command:
[
"/usr/local/bin/sui-node",
Expand Down Expand Up @@ -165,8 +155,6 @@ services:
volumes:
- validator4-db:/opt/sui/db:rw
- genesis:/opt/sui/config
# - ./genesis/files/validator4-8080.yaml:/opt/sui/config/validator.yaml:ro
# - ./genesis/files/genesis.blob:/opt/sui/config/genesis.blob:ro
command:
[
"/usr/local/bin/sui-node",
Expand Down Expand Up @@ -203,7 +191,6 @@ services:
- fullnode1-db:/opt/sui/db:rw
- genesis:/opt/sui/config
- ./genesis/static/fullnode.yaml:/opt/sui/config/fullnode.yaml:ro
# - ./genesis/files/genesis.blob:/opt/sui/config/genesis.blob:ro
- ./genesis/static/client.yaml:/opt/sui/config/client.yaml:rw
healthcheck:
test:
Expand Down Expand Up @@ -262,7 +249,6 @@ services:
volumes:
- genesis:/opt/sui/config
- ./genesis/static/client.yaml:/opt/sui/config/client.yaml:rw
# - ./genesis/files/genesis.blob:/opt/sui/config/genesis.blob:ro
- ./genesis/static/sui.keystore:/opt/sui/config/sui.keystore:ro
command:
[
Expand Down
13 changes: 4 additions & 9 deletions examples/example.just
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ default:
# Runs an example that prompts the user for a description of their post.
[no-cd]
ig-post-planner:
#!/usr/bin/env bash
source .venv/bin/activate
python3 examples/main.py "ig_post_planner"
docker exec -it examples /bin/bash -c "source .venv/bin/activate && python examples/main.py ig_post_planner"

# Runs an example that prompts the user for description of their trip.
[no-cd]
trip-planner:
#!/usr/bin/env bash
source .venv/bin/activate
python3 examples/main.py "trip_planner"
docker exec -it examples /bin/bash -c "source .venv/bin/activate && python examples/main.py trip_planner"

# Runs an example that prompts the user for description of their cluster.
[no-cd]
cli-cluster:
#!/usr/bin/env bash
source .venv/bin/activate
python3 examples/main.py "cli_cluster"
docker exec -it examples /bin/bash -c "source .venv/bin/activate && python examples/main.py cli_cluster"

0 comments on commit d3c2035

Please sign in to comment.