Skip to content

Commit

Permalink
switching from docker compose to docker run
Browse files Browse the repository at this point in the history
  • Loading branch information
lunamidori5 committed Jun 24, 2024
1 parent 738b0a2 commit 206b62a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
2 changes: 1 addition & 1 deletion other_files/midori_program_ver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
`Antioquia Brushfinch` ->| 24.6.18.0 |<-
`Antioquia Brushfinch` ->| 24.6.24.0 |<-
17 changes: 16 additions & 1 deletion other_files/model_installer/edit_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def backend_installer(self, docker_compose_yaml, client, client_openai, ver_os_i

with open(f"./files/{item_os}/docker-compose.yaml", "w") as f:
f.write(compose_yaml)

except Exception as e:
s.log(f"Something went wrong, {str(e)}")
s.log("Most likely the backend does not use a docker compose file.")
Expand All @@ -190,6 +191,7 @@ def backend_uninstaller(self, docker_compose_yaml, client, ver_os_info):
containers = client.containers.list()
backend_checker = s.backends_checking()
os_checker = platform.release()
backend_info = s.backend_info(client)

list_of_supported_backends = backend_checker.check_json()

Expand Down Expand Up @@ -227,11 +229,24 @@ def backend_uninstaller(self, docker_compose_yaml, client, ver_os_info):
for item in requested_backends:
s.log(f"Uninstalling {item}")
backend_checker.remove_backend(item)
docker_name, dockerimage = backend_info.check_for_backend(f"{item}-midori-ai-backend")

## OLD CODE NEEDED FOR SOME OS, WILL BE REMOVED SOON
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if "Unraid" in os_checker:
docker_commands.append(f"docker compose -f /app/files/{item}/docker-compose.yaml down --rmi all")
else:
docker_commands.append(f"docker compose -f ./files/{item}/docker-compose.yaml down --rmi all")
docker_commands.append(f"rm -rf ./files/{item}")

## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docker_commands.append(f"docker container kill {dockerimage.id}")
docker_commands.append(f"docker container remove {dockerimage.id}")

docker_commands.append(f"docker image prune -f")

docker_commands.append(f"rm -rf /app/files/{item}")

s.log("Running commands inside of the Midori AI Subsystem!")
for item_docker in docker_commands:
Expand Down
58 changes: 56 additions & 2 deletions other_files/model_installer/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,5 +598,59 @@ def get_local_ip():
return local_ip

def known_gpus():
known_niv_gpus = ["NVIDIA", "Quadro", "Tesla"]
return known_niv_gpus
known_gpus = ["NVIDIA", "Quadro", "Tesla"]
return known_gpus

class backend_info:
"""
A class to manage information about the backend, specifically checking for and linking to a Docker container.
Attributes:
client: A Docker client object.
Methods:
check_for_backend(docker_name): Checks if a Docker container with the specified name is running and links to it if found.
"""
def __init__(self, client):
"""
Initializes the backend_info_puller class with necessary attributes.
Parameters:
client: A Docker client object. This is assumed to be pre-configured and connected to the Docker daemon.
"""
self.client = client

def check_for_backend(self, docker_name):
"""
Checks for a running Docker container with a name that includes the specified docker_name.
If found, it retrieves the container object and returns its name and object.
Parameters:
docker_name: A string representing the name (or part of the name) of the Docker container to search for.
Returns:
A tuple containing:
- named_docker: The name of the found Docker container as a string.
- container: The Docker container object.
Returns (None, None) if a container matching the docker_name is not found.
"""

log(f"Checking for Docker Image")

containers = self.client.containers.list()

for container in containers:
log(f"Checking Name: {container.name}, ID: {container.id}")

# Check if there is a container with a name containing `service_name`
if docker_name in str(container.name):
# Get the container object
log(f"Found {docker_name}, Linking the Subsystem to: {container.name} / {container.id}")
container = self.client.containers.get(container.name)
named_docker = container.name
log(f"Midori AI Subsystem found and linked to {named_docker}")
return named_docker, container

# No container found matching the docker_name
return None, None

0 comments on commit 206b62a

Please sign in to comment.