From bbd8342880f372e7f1f1efc3377bc994b6dafcf2 Mon Sep 17 00:00:00 2001 From: "@RandyMcMillan" Date: Tue, 14 Mar 2023 16:32:33 -0400 Subject: [PATCH 1/6] plebnet_generate.py: up-generic.sh: --- plebnet_generate.py | 18 ++++++++++++++---- up-generic.sh | 11 ++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) mode change 100644 => 100755 plebnet_generate.py diff --git a/plebnet_generate.py b/plebnet_generate.py old mode 100644 new mode 100755 index 9100161..8036795 --- a/plebnet_generate.py +++ b/plebnet_generate.py @@ -1,9 +1,20 @@ -# Generates docker-compose for n nodes. +#!/usr/bin/env python3 +# Generates docker-compose from command line. +# +# For each service identified at command line, this we identify other dependent services and add them to the config. # + -from omegaconf import OmegaConf import sys +sys.path.append('.') +sys.path.append("/usr/local/lib/python3.7/site-packages") +sys.path.append("/usr/local/lib/python3.8/site-packages") +sys.path.append("/usr/local/lib/python3.9/site-packages") +sys.path.append("/usr/local/lib/python3.10/site-packages") +sys.path.append("/usr/local/lib/python3.11/site-packages") +#print(sys.path) + +from omegaconf import OmegaConf architectures = { "Intel x64": 'x86_64-linux-gnu', @@ -12,8 +23,7 @@ 'ARM64 linux': 'aarch64-linux-gnu', } -from omegaconf import OmegaConf - +# + cli_args = OmegaConf.from_cli() try: diff --git a/up-generic.sh b/up-generic.sh index b8fd092..e735c08 100755 --- a/up-generic.sh +++ b/up-generic.sh @@ -16,17 +16,18 @@ sudo rm -rf volumes mkdir volumes for (( i=0; i<=$bitcoind-1; i++ )) do - mkdir volumes/bitcoin_datadir_$i + mkdir -p volumes/bitcoin_datadir_$i done for (( i=0; i<=$lnd-1; i++ )) do - mkdir volumes/lnd_datadir_$i + mkdir -p volumes/lnd_datadir_$i done +rm -rf volumes/tor_*dir_* for (( i=0; i<=$tor-1; i++ )) do - mkdir volumes/tor_datadir_$i - mkdir volumes/tor_servicesdir_$i - mkdir volumes/tor_torrcdir_$i + mkdir -p volumes/tor_datadir_$i + mkdir -p volumes/tor_servicesdir_$i + mkdir -p volumes/tor_torrcdir_$i done docker-compose build --build-arg TRIPLET=$TRIPLET From dc330bef12f56c6f056a0bebf73365e444365468 Mon Sep 17 00:00:00 2001 From: "@RandyMcMillan" Date: Tue, 14 Mar 2023 16:36:08 -0400 Subject: [PATCH 2/6] up-generic.sh: refactor for submodule --- up-generic.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/up-generic.sh b/up-generic.sh index e735c08..d5c268b 100755 --- a/up-generic.sh +++ b/up-generic.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash +source ../.venv/bin/activate #This is for internal testing only : ${TRIPLET:=x86_64-linux-gnu} : ${bitcoind=1} From c23b719bb5263ea8c475303a3a98e59e8a47ec17 Mon Sep 17 00:00:00 2001 From: "@RandyMcMillan" Date: Tue, 14 Mar 2023 17:24:49 -0400 Subject: [PATCH 3/6] plebnet_generate.py: recast node_count as int --- plebnet_generate.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plebnet_generate.py b/plebnet_generate.py index 8036795..5a6c301 100755 --- a/plebnet_generate.py +++ b/plebnet_generate.py @@ -72,7 +72,10 @@ def get_service_values(i, node_counts, **kwargs): for service in list(conf.services): service_nodes = node_counts[service] print(service, service_nodes) - for i in range(service_nodes): + # print(type(service)) + # print(type(service_nodes)) + int_node_count = int(service_nodes) + for i in range(int_node_count): service_values = get_service_values(i, node_counts, TRIPLET=triplet) service_name = '{}-{}'.format(service, str(i)) conf.services[service_name] = get_service( From 297a4fe1a66ec32c29e9104a7b22060674e511ac Mon Sep 17 00:00:00 2001 From: "@RandyMcMillan" Date: Tue, 14 Mar 2023 17:26:56 -0400 Subject: [PATCH 4/6] up-generic.sh: --- up-generic.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/up-generic.sh b/up-generic.sh index d5c268b..303eac6 100755 --- a/up-generic.sh +++ b/up-generic.sh @@ -1,12 +1,9 @@ -#!/usr/bin/env bash -source ../.venv/bin/activate -#This is for internal testing only : ${TRIPLET:=x86_64-linux-gnu} -: ${bitcoind=1} +: ${bitcoind=5} : ${lnd=1} : ${tor=1} -python plebnet_generate.py TRIPLET=$TRIPLET bitcoind=$bitcoind lnd=$lnd tor=$tor +$(which python3) plebnet_generate.py TRIPLET=$TRIPLET bitcoind=$bitcoind lnd=$lnd tor=$tor #Remove docker-compose down From ff775b23234ce995e66e1dec71dddc29899f8139 Mon Sep 17 00:00:00 2001 From: "@RandyMcMillan" Date: Tue, 14 Mar 2023 17:35:22 -0400 Subject: [PATCH 5/6] .gitignore: .venv --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index eb22288..4ccd7b3 100644 --- a/.gitignore +++ b/.gitignore @@ -363,4 +363,4 @@ z.sh volumes/ backup/ docker-compose.yaml - +.venv From f9c92360b59238358f47ce061a0132d4e94c48cc Mon Sep 17 00:00:00 2001 From: "@RandyMcMillan" Date: Tue, 14 Mar 2023 19:35:08 -0400 Subject: [PATCH 6/6] GNUmakefile: make - use venv --- GNUmakefile | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 GNUmakefile diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..cd671dd --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,91 @@ +SHELL := /bin/bash + +PWD ?= pwd_unknown + +THIS_FILE := $(lastword $(MAKEFILE_LIST)) +export THIS_FILE +TIME := $(shell date +%s) +export TIME + +ifeq ($(docker),) +DOCKER := $(shell which docker) +else +DOCKER := $(docker) +endif +export DOCKER + +ifeq ($(compose),) +DOCKER_COMPOSE := $(shell which docker-compose) +else +DOCKER_COMPOSE := $(compose) +endif +export DOCKER_COMPOSE + + + +PYTHON := $(shell which python) +export PYTHON +PYTHON2 := $(shell which python2) +export PYTHON2 +PYTHON3 := $(shell which python3) +export PYTHON3 + +PIP := $(shell which pip) +export PIP +PIP2 := $(shell which pip2) +export PIP2 +PIP3 := $(shell which pip3) +export PIP3 + +python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python3 --version 2>&1))) +python_version_major := $(word 1,${python_version_full}) +python_version_minor := $(word 2,${python_version_full}) +python_version_patch := $(word 3,${python_version_full}) + +my_cmd.python.3 := $(PYTHON3) some_script.py3 +my_cmd := ${my_cmd.python.${python_version_major}} + +PYTHON_VERSION := ${python_version_major}.${python_version_minor}.${python_version_patch} +PYTHON_VERSION_MAJOR := ${python_version_major} +PYTHON_VERSION_MINOR := ${python_version_minor} + +export python_version_major +export python_version_minor +export python_version_patch +export PYTHON_VERSION + +# PROJECT_NAME defaults to name of the current directory. +ifeq ($(project),) +PROJECT_NAME := $(notdir $(PWD)) +else +PROJECT_NAME := $(project) +endif +export PROJECT_NAME + + + + +.PHONY: venv +venv: + test -d .venv || $(PYTHON3) -m virtualenv .venv + ( \ + source .venv/bin/activate; pip install -r requirements.txt; \ + ); + @echo "To activate (venv)" + @echo "try:" + @echo ". .venv/bin/activate" + @echo "or:" + @echo "make test-venv" +##: test-venv source .venv/bin/activate; pip install -r requirements.txt; +test-venv: + # insert test commands here + test -d .venv || $(PYTHON3) -m virtualenv .venv + ( \ + source .venv/bin/activate; pip install -r requirements.txt; \ + ); +####################### +.PHONY: prune-network +prune-network: + $(DOCKER_COMPOSE) -p $(PROJECT_NAME) down + docker network rm $(PROJECT_NAME)_default 2>/dev/null || echo "retry..." +####################### \ No newline at end of file