Skip to content

Commit c69a07b

Browse files
authored
Feature/api database (#55)
* refactor: - controller.py renamed to hub.py - database.py renamed to postgress.py - database services in controller.py moved to databases folder * feature: database adapter created * feature: database api implemented * refactor: using apiutils for hub endpoints * refactor: database and hub endpoints * refactor: extras column added to nodes table * refactor: database_api endpoints * feature: added extras column for addons in the node table * fix: dashboard and user issues * refactor: payload for request * chore: init.py added for database files * chore: init file added for postgres * chore: init file added to adapaters * fix: typo in init file
1 parent dbc45ca commit c69a07b

22 files changed

Lines changed: 1969 additions & 931 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ update-dockers: ## Update docker images
7676
fi
7777
@echo "🐳 Building nebula-database docker image. Do you want to continue (overrides existing image)? (y/n)"
7878
@read ans; if [ "$${ans:-N}" = y ]; then \
79-
docker build -t nebula-database -f nebula/database/Dockerfile .; \
79+
docker build -t nebula-database -f nebula/database/adapters/postgress/docker/Dockerfile .; \
8080
docker build -t nebula-pgweb -f nebula/database/pgweb/Dockerfile .; \
8181
else \
8282
echo "Skipping nebula-database docker build."; \

app/deployer.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from watchdog.observers import Observer
1818

1919
from nebula.addons.env import check_environment
20-
from nebula.controller.web_app_controller import TermEscapeCodeFormatter
20+
from nebula.controller.hub import TermEscapeCodeFormatter
2121
from nebula.controller.scenarios import ScenarioManagement
2222
from nebula.utils import DockerUtils, FileUtils, SocketUtils
2323

@@ -638,7 +638,7 @@ def __init__(self, args):
638638
sys.exit(1)
639639

640640
self.controller_port = int(args.controllerport) if hasattr(args, "controllerport") else 5050
641-
self.federation_controller_port = int(args.federationcontrollerport) if hasattr(args, "federationcontrollerport") else 5051
641+
self.federation_controller_port = int(args.federationcontrollerport) if hasattr(args, "federationcontrollerport") else 5052
642642
self.waf_port = int(args.wafport) if hasattr(args, "wafport") else 6000
643643
self.frontend_port = int(args.webport) if hasattr(args, "webport") else 6060
644644
self.grafana_port = int(args.grafanaport) if hasattr(args, "grafanaport") else 6040
@@ -853,7 +853,7 @@ def start(self):
853853
# Check ports available
854854
if not SocketUtils.is_port_open(self.controller_port):
855855
self.controller_port = SocketUtils.find_free_port(start_port=self.controller_port)
856-
856+
857857
if not SocketUtils.is_port_open(self.federation_controller_port):
858858
self.federation_controller_port = SocketUtils.find_free_port(start_port=self.federation_controller_port)
859859

@@ -1045,17 +1045,24 @@ def run_database(self):
10451045
"POSTGRES_USER": "nebula",
10461046
"POSTGRES_PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
10471047
"POSTGRES_DB": "nebula",
1048+
"NEBULA_DATABASE_LOG": "/nebula/app/logs/database.log",
1049+
"DB_HOST": "localhost",
1050+
"DB_PORT": 5432,
1051+
"DB_USER": "nebula",
1052+
"DB_PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
1053+
"NEBULA_ADMIN_PASSWORD": os.environ.get("NEBULA_ADMIN_PASSWORD")
10481054
}
1049-
host_sql_path = os.path.join(self.root_path, "nebula/database/init-configs.sql")
1055+
host_sql_path = os.path.join(self.root_path, "nebula/database/adapters/postgress/docker/init-configs.sql")
10501056
db_data_path = os.path.join(self.databases_dir, "postgres-data")
10511057
os.makedirs(db_data_path, exist_ok=True)
10521058

10531059
pg_host_config = client.api.create_host_config(
10541060
binds=[
1061+
f"{self.root_path}:/nebula",
10551062
f"{host_sql_path}:/docker-entrypoint-initdb.d/init-configs.sql",
10561063
f"{db_data_path}:/var/lib/postgresql/data",
10571064
],
1058-
port_bindings={5432: 5432},
1065+
port_bindings={5432: 5432, 5051: 5051},
10591066
)
10601067
pg_networking_config = client.api.create_networking_config(
10611068
{f"{network_name}": client.api.create_endpoint_config(ipv4_address=f"{base}.125")}
@@ -1068,6 +1075,7 @@ def run_database(self):
10681075
environment=pg_environment,
10691076
host_config=pg_host_config,
10701077
networking_config=pg_networking_config,
1078+
ports=[5432, 5051],
10711079
)
10721080
client.api.start(pg_container)
10731081
Deployer._add_container_to_metadata(pg_container_name)
@@ -1132,11 +1140,7 @@ def run_controller(self):
11321140
"NEBULA_FEDERATION_CONTROLLER_PORT" : self.federation_controller_port,
11331141
"NEBULA_CONTROLLER_HOST": self.controller_host,
11341142
"NEBULA_FRONTEND_PORT": self.frontend_port,
1135-
"DB_HOST": self.get_container_name("nebula-database"),
1136-
"DB_PORT": 5432,
1137-
"DB_USER": "nebula",
1138-
"DB_PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
1139-
"NEBULA_ADMIN_PASSWORD": os.environ.get("NEBULA_ADMIN_PASSWORD")
1143+
"NEBULA_DATABASE_API_URL": f"http://{self.get_container_name('nebula-database')}:5051"
11401144
}
11411145

11421146
volumes = ["/nebula", "/var/run/docker.sock"]

app/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"-fcp",
2222
"--federationcontrollerport",
2323
dest="federationcontrollerport",
24-
default=5051,
25-
help="federation controller port port (default: 5051)",
24+
default=5052,
25+
help="federation controller port port (default: 5052)",
2626
)
2727

2828
argparser.add_argument(

0 commit comments

Comments
 (0)