Skip to content

Commit aebcbbb

Browse files
[Feature/simultaneous_queues] Improved version for scenario management (#29)
* feature: multiple queues working with different users using the default scenario configuration * fix network prefix 192.168.1 changed to 192.168.2 * Fix different queue for each user * feature: show scenarios in the dashboard depending on the role of the user * refactor: changed location of utils.py * fix: nebula-frontend port * fix: launching scenarios with same user in different frontend instance * fix: launching scenarios with same user in different frontend instance * fix: stopping only instance * fix: stopping only instance * fix: remove instance network * fix: killing other instance docker when starting new scenario * fix: stop bugs * feature: display queues for each user * Fix persistence on session and dbs * Fix persistence on session * fix: scenario database, database dashboard * Minor changes in user management * Improve update docker images * remove reconnections (more debug needed) * fix: scenario title setted to empty when theres no scenario title * fix: redirect to dashboard.py * fix: waf containers on production mode working * fix: change user in config files automatically * fix: remove unnecesary variable user * remove unused functions * fix: blockchain network endpoint * fix: deploying different scenarios with process * define NEBULA Controller API, update makefile * enable controller endpoint from the frontend * fix: connection between nodes in process deployment * refactor: fronted.log in run_frontend for frontend.log * feature: halt scenarios when RAM or GPU usage is maxed out * fix: obtain list of gpus available based in user * fix: gpus list * fix: docker ips and gpus lists * Fix generate statistics --------- Co-authored-by: FerTV <fernando.torres.vega@gmail.com>
1 parent 0ee87a8 commit aebcbbb

23 files changed

+1241
-939
lines changed

Makefile

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ PYTHON_VERSION := 3.11
33
UV_INSTALL_SCRIPT := https://astral.sh/uv/install.sh
44
PATH := $(HOME)/.local/bin:$(PATH)
55

6-
command_exists = $(shell command -v $(1) >/dev/null 2>&1 && echo true || echo false)
7-
8-
define install_uv
9-
@echo "📦 uv is not installed. Installing uv..."
10-
@curl -LsSf $(UV_INSTALL_SCRIPT) | sh
11-
endef
12-
136
.PHONY: check-uv
147
check-uv: ## Check and install uv if necessary
158
@if command -v $(UV) >/dev/null 2>&1; then \
@@ -33,33 +26,26 @@ install-python: check-uv ## Install Python with uv
3326
.PHONY: install
3427
install: install-python ## Install core dependencies
3528
@echo "📦 Installing core dependencies with uv"
36-
@$(UV) sync --group core
29+
@$(UV) sync --group controller --group core
3730
@echo "🔧 Installing pre-commit hooks"
3831
@$(UV) run pre-commit install
3932
@echo ""
40-
@echo "🐳 Building nebula-frontend docker image. Do you want to continue (overrides existing image)? (y/n)"
41-
@read ans; if [ "$${ans:-N}" = y ]; then \
42-
docker build -t nebula-frontend -f nebula/frontend/Dockerfile .; \
43-
else \
44-
echo "Skipping nebula-frontend docker build."; \
45-
fi
46-
@echo ""
47-
@echo "🐳 Building nebula-core docker image. Do you want to continue? (overrides existing image)? (y/n)"
48-
@read ans; if [ "$${ans:-N}" = y ]; then \
49-
docker build -t nebula-core .; \
50-
else \
51-
echo "Skipping nebula-core docker build."; \
52-
fi
33+
@$(MAKE) update
5334
@echo ""
5435
@$(MAKE) shell
5536

56-
.PHONY: full-install
57-
full-install: install-python ## Install all dependencies (core, docs)
58-
@echo "📦 Installing all dependencies with uv"
59-
@$(UV) sync --group core --group docs
60-
@echo "🔧 Installing pre-commit hooks"
61-
@$(UV) run pre-commit install
62-
@$(MAKE) shell
37+
.PHONY: install-production
38+
install-production: install ## Install production dependencies
39+
@echo "🐳 Updating production docker images..."
40+
@echo "🐳 Building nebula-waf"
41+
@docker build -t nebula-waf -f nebula/addons/waf/Dockerfile-waf --build-arg USER=$(USER) nebula/addons/waf
42+
@echo "🐳 Building nebula-loki"
43+
@docker build -t nebula-waf-loki -f nebula/addons/waf/Dockerfile-loki nebula/addons/waf
44+
@echo "🐳 Building nebula-promtail"
45+
@docker build -t nebula-waf-promtail -f nebula/addons/waf/Dockerfile-promtail --build-arg USER=$(USER) nebula/addons/waf
46+
@echo "🐳 Building nebula-grafana"
47+
@docker build -t nebula-waf-grafana -f nebula/addons/waf/Dockerfile-grafana --build-arg USER=$(USER) nebula/addons/waf
48+
echo "🐳 Docker images updated."
6349

6450
.PHONY: shell
6551
shell: ## Start a shell in the uv environment
@@ -79,20 +65,31 @@ shell: ## Start a shell in the uv environment
7965
echo "🚀 Created by \033[1;34mEnrique Tomás Martínez Beltrán\033[0m <\033[1;34menriquetomas@um.es\033[0m>"; \
8066
fi
8167

68+
.PHONY: update
69+
update: ## Update docker images
70+
@echo "🐳 Updating docker images..."
71+
@echo "🐳 Building nebula-frontend docker image. Do you want to continue (overrides existing image)? (y/n)"
72+
@read ans; if [ "$${ans:-N}" = y ]; then \
73+
docker build -t nebula-frontend -f nebula/frontend/Dockerfile .; \
74+
else \
75+
echo "Skipping nebula-frontend docker build."; \
76+
fi
77+
@echo ""
78+
@echo "🐳 Building nebula-core docker image. Do you want to continue? (overrides existing image)? (y/n)"
79+
@read ans; if [ "$${ans:-N}" = y ]; then \
80+
docker build -t nebula-core .; \
81+
else \
82+
echo "Skipping nebula-core docker build."; \
83+
fi
84+
echo "🐳 Docker images updated."
85+
8286
.PHONY: lock
8387
lock: ## Update the lock file
8488
@echo "🔒 This will update the lock file. Do you want to continue? (y/n)"
8589
@read ans && [ $${ans:-N} = y ] || { echo "Lock cancelled."; exit 1; }
8690
@echo "🔒 Locking dependencies..."
8791
@$(UV) lock
8892

89-
.PHONY: update-libs
90-
update-libs: ## Update libraries to the latest version
91-
@echo "🔧 This will override the versions of current libraries. Do you want to continue? (y/n)"
92-
@read ans && [ $${ans:-N} = y ] || { echo "Update cancelled."; exit 1; }
93-
@echo "📦 Updating libraries..."
94-
@$(UV) update
95-
9693
.PHONY: check
9794
check: ## Run code quality tools
9895
@echo "🛠️ Running code quality checks"
@@ -127,6 +124,12 @@ publish: ## Publish a release to PyPI
127124
.PHONY: build-and-publish
128125
build-and-publish: build publish ## Build and publish the package
129126

127+
.PHONY: doc-install
128+
full-install: install-python ## Install dependencies for documentation
129+
@echo "📦 Installing doc dependencies with uv"
130+
@$(UV) sync --group core --group docs
131+
@$(MAKE) shell
132+
130133
.PHONY: doc-test
131134
doc-test: ## Test if documentation can be built without errors
132135
@$(UV) run mkdocs build -f docs/mkdocs.yml -d _build -s
@@ -139,12 +142,6 @@ doc-build: ## Build the documentation
139142
doc-serve: ## Serve the documentation locally
140143
@$(UV) run mkdocs serve -f docs/mkdocs.yml
141144

142-
.PHONY: format
143-
format: ## Format code with black and isort
144-
@echo "🎨 Formatting code"
145-
@$(UV) run black .
146-
@$(UV) run isort .
147-
148145
.PHONY: clean
149146
clean: clean-build ## Clean up build artifacts and caches
150147
@echo "🧹 Cleaning up build artifacts and caches"

app/main.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99

1010
argparser = argparse.ArgumentParser(description="Controller of NEBULA platform", add_help=False)
1111

12+
argparser.add_argument(
13+
"-cp",
14+
"--controllerport",
15+
dest="controllerport",
16+
default=5000,
17+
help="Controller port (default: 5000)",
18+
)
19+
1220
argparser.add_argument(
1321
"--grafanaport",
1422
dest="grafanaport",
@@ -38,6 +46,14 @@
3846
help="Frontend port (default: 6060)",
3947
)
4048

49+
argparser.add_argument(
50+
"-sp",
51+
"--statsport",
52+
dest="statsport",
53+
default=8080,
54+
help="Statistics port (default: 8080)",
55+
)
56+
4157
argparser.add_argument("-t", "--test", dest="test", action="store_true", default=False, help="Run tests")
4258

4359
argparser.add_argument(
@@ -49,42 +65,41 @@
4965
default=None,
5066
help="Stop NEBULA platform or nodes only (use '--stop nodes' to stop only the nodes)",
5167
)
52-
argparser.add_argument(
53-
"-sp",
54-
"--statsport",
55-
dest="statsport",
56-
default=8080,
57-
help="Statistics port (default: 8080)",
58-
)
68+
5969
argparser.add_argument("-s", "--simulation", action="store_false", dest="simulation", help="Run simulation")
70+
6071
argparser.add_argument(
6172
"-c",
6273
"--config",
6374
dest="config",
6475
default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "config"),
6576
help="Config directory path",
6677
)
78+
6779
argparser.add_argument(
6880
"-l",
6981
"--logs",
7082
dest="logs",
7183
default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "logs"),
7284
help="Logs directory path",
7385
)
86+
7487
argparser.add_argument(
7588
"-ce",
7689
"--certs",
7790
dest="certs",
7891
default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "certs"),
7992
help="Certs directory path",
8093
)
94+
8195
argparser.add_argument(
8296
"-e",
8397
"--env",
8498
dest="env",
8599
default=os.path.join(os.path.dirname(os.path.abspath(__file__)), ".env"),
86100
help=".env file path",
87101
)
102+
88103
argparser.add_argument(
89104
"-p",
90105
"--production",
@@ -93,6 +108,7 @@
93108
default=False,
94109
help="Production mode",
95110
)
111+
96112
argparser.add_argument(
97113
"-ad",
98114
"--advanced",
@@ -101,20 +117,23 @@
101117
default=False,
102118
help="Advanced analytics",
103119
)
120+
104121
argparser.add_argument(
105122
"-v",
106123
"--version",
107124
action="version",
108125
version="%(prog)s " + nebula.__version__,
109126
help="Show version",
110127
)
128+
111129
argparser.add_argument(
112130
"-a",
113131
"--about",
114132
action="version",
115133
version="Created by Enrique Tomás Martínez Beltrán",
116134
help="Show author",
117135
)
136+
118137
argparser.add_argument("-h", "--help", action="help", default=argparse.SUPPRESS, help="Show help")
119138

120139
args = argparser.parse_args()

docs/_prebuilt/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ frontend, controller, and nodes.
125125

126126
## Possible issues during the installation or execution
127127

128-
If frontend is not working, check the logs in app/logs/server.log
128+
If frontend is not working, check the logs in app/logs/frontend.log
129129

130130
If any of the following errors appear, take a look at the docker logs of
131131
the nebula-frontend container:

nebula/addons/waf/Dockerfile-grafana

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
FROM grafana/grafana:latest
22

3+
ARG USER
4+
ENV USER=${USER}
5+
36
COPY ./grafana/dashboard_config.yml /etc/grafana/provisioning/dashboards/local.yml
47
COPY ./grafana/automatic.yml /etc/grafana/provisioning/datasources/automatic.yml
58
COPY ./grafana/dashboard.json /var/lib/grafana/dashboards/dashboard.json
9+
10+
RUN sed -i "s|http://nebula|http://$USER|g" /etc/grafana/provisioning/datasources/automatic.yml

nebula/addons/waf/Dockerfile-loki

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
FROM grafana/loki:latest
2+
3+
COPY loki-config.yml /mnt/config/loki-config.yml

nebula/addons/waf/Dockerfile-promtail

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
FROM grafana/promtail:latest
2+
3+
ARG USER
4+
ENV USER=${USER}
5+
6+
COPY promtail-config.yml /etc/promtail/config.yml
7+
8+
RUN sed -i "s|http://nebula|http://$USER|g" /etc/promtail/config.yml

nebula/addons/waf/Dockerfile-waf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ FROM owasp/modsecurity-crs:3.3.5-nginx-202310170110
33

44
ARG NGINX_VERSION=1.24.0
55

6+
ARG USER
7+
ENV USER=${USER}
8+
69
# Installed necessary packages
710
RUN apt-get update && apt-get install -y libmaxminddb0 libmaxminddb-dev mmdb-bin git wget
811
RUN apt install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
@@ -37,6 +40,9 @@ RUN wget https://git.io/GeoLite2-Country.mmdb -P /usr/share/GeoIP/
3740

3841
# nginx configuration files
3942
COPY default.conf /etc/nginx/templates/conf.d/default.conf.template
43+
44+
RUN sed -i "s|http://nebula|http://${USER}|g" /etc/nginx/templates/conf.d/default.conf.template
45+
4046
COPY nginx.conf /etc/nginx/templates/nginx.conf.template
4147

4248
# owasp crs

nebula/addons/waf/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ server {
1212
listen 80 default_server;
1313

1414
server_name localhost;
15-
set $upstream http://nebula-frontend; # Change this
15+
set $upstream http://nebula-nebula-frontend; # Change this
1616
set $always_redirect off;
1717
modsecurity on;
1818
location /nebula {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
datasources:
22
- name: Loki
33
type: loki
4-
url: http://loki:3100
4+
url: http://nebula-nebula-waf-loki:3100
55
isDefault: true
66
editable: true

nebula/addons/waf/promtail-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ positions:
66
filename: /tmp/positions.yaml
77

88
clients:
9-
- url: http://loki:3100/loki/api/v1/push
9+
- url: http://nebula-nebula-waf-loki:3100/loki/api/v1/push
1010

1111
scrape_configs:
1212
- job_name: nginx

0 commit comments

Comments
 (0)