Merge pull request #4 from vacp2p/Alberto/init-util

Add status-init
This commit is contained in:
Alberto Soutullo
2025-06-30 21:26:01 +02:00
committed by GitHub
4 changed files with 88 additions and 0 deletions

13
docker-utils/README.md Normal file
View File

@@ -0,0 +1,13 @@
# Docker-utils
Containers that will be needed for the experiments.
## status-init
This container is in charge of preparing `/static/configs/config.json` file for `status-backend`.
It will grab the ENR of the store nodes that will also act as bootstrap, and put it in the json file.
## status-subscriber
Simple container that will connect to `status-backend` signal to log information.

View File

@@ -0,0 +1,3 @@
FROM python:3.11-slim
COPY init_container.py /init_container.py

View File

@@ -0,0 +1,9 @@
# status-init
This container is in charge of preparing `/static/configs/config.json` file for `status-backend`.
It will grab the env variables of BOOT_ENRS and STORE_ENRS (bootstrap and store nodes) and put them it in the configuration.
## Changelog
- v1.0.0
- Working with status-backend `b22c58bd3bdd4a387dc09dccba1d866d5ae09adf`

View File

@@ -0,0 +1,63 @@
import json
import os
import sys
import logging
from pathlib import Path
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def update_config():
bootstrap_enrs = [
os.getenv(env)
for env in os.environ
if env.startswith("BOOT_ENRS") and os.getenv(env).startswith("enr:")
]
store_enrs = [
os.getenv(env)
for env in os.environ
if env.startswith("STORE_ENRS") and os.getenv(env).startswith("enr:")
]
config_path = os.getenv("CONFIG_PATH", "/static/configs/config.json")
try:
config_dir = Path(config_path).parent
config_dir.mkdir(parents=True, exist_ok=True)
logger.info(f"Ensured config folder exists at: {config_dir}")
config = {
"dst.dev": {
"wakuNodes": bootstrap_enrs,
"discV5BootstrapNodes": [],
"clusterId": int(os.getenv("CLUSTER_ID", 16)),
"storeNodes": []
}
}
for counter, enr in enumerate(store_enrs):
config["dst.dev"]["storeNodes"].append({
"id": f"store-node-{counter}",
"enr": enr,
"addr": "",
"fleet": "dst.dev"
})
with open(config_path, "w") as f:
json.dump(config, f, indent=2)
logger.info(f"Configuration successfully written to {config_path}")
except Exception as e:
logger.error(f"Failed to update config: {e}", exc_info=True)
sys.exit(1)
def main():
update_config()
if __name__ == "__main__":
main()