-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwisecube_install.py
70 lines (51 loc) · 2.1 KB
/
wisecube_install.py
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
import docker
import yaml
import os
import subprocess
POSTGRES_VOLUME = "wisecube_postgres_data"
WISECUBE_NETWORK = "wisecube-net"
PROJECT_NAME = "wisecube-stack"
docker_client = docker.from_env()
def create_docker_volume(volume_name):
existing_volume = docker_client.volumes.list(filters={"name": volume_name})
if existing_volume:
print(f"Volume '{volume_name}' already exists.")
return None
docker_client.volumes.create(name=volume_name)
print("Docker volume '{}' created successfully!".format(volume_name))
def create_docker_network(network_name):
existing_networks = docker_client.networks.list(names=[network_name])
if existing_networks:
print(f"Network '{network_name}' already exists.")
return
docker_client.networks.create(name=network_name)
print("Docker network '{}' created successfully!".format(network_name))
def update_docker_compose(apy_key):
# Load the Docker Compose file
with open('compose_template.yaml', 'r') as file:
compose_data = yaml.safe_load(file)
compose_data['services']['wisecube-pythia']['environment'] = ["OPENAI_API_KEY=" + apy_key]
with open('docker-compose.yaml', 'w') as file:
yaml.dump(compose_data, file)
def run_docker_compose(compose_file):
compose_file = os.path.abspath(compose_file)
result = -1
try:
result = os.system("docker compose -f {} -p {} up -d".format(compose_file, PROJECT_NAME))
if result != 0:
raise Exception()
print("Docker Compose file is running.")
except subprocess.CalledProcessError as e:
print("Failed to run Docker Compose file:", e, result.stderr)
raise Exception("Failed to run Docker Compose file:", e)
def main():
print("Configure the Wisecube Stack!")
api_key = input("1. Enter your openapi key: ")
if api_key is None:
raise Exception("No openapi key was provided!")
create_docker_volume(POSTGRES_VOLUME)
create_docker_network(WISECUBE_NETWORK)
update_docker_compose(apy_key=api_key)
run_docker_compose("docker-compose.yaml")
if __name__ == "__main__":
main()