diff --git a/Dockerfile.unix b/Dockerfile.unix index 79cc7138..cde4bc7d 100644 --- a/Dockerfile.unix +++ b/Dockerfile.unix @@ -24,20 +24,7 @@ RUN mv my_init /sbin RUN ./bootstrap_env.sh RUN ./setup_system.sh -RUN if [ ${USER_ID:-0} -ne 0 ] && [ ${GROUP_ID:-0} -ne 0 ]; then \ - userdel -f www-data && \ - if getent group www-data ; then groupdel www-data; fi && \ - groupadd -g ${GROUP_ID} www-data && \ - useradd -l -u ${USER_ID} -g www-data www-data && \ - install -d -m 0755 -o www-data -g www-data /home/www-data && \ - chown --changes --silent --no-dereference --recursive \ - --from=33:33 ${USER_ID}:${GROUP_ID} \ - /home/www-data \ - /app \ - ;fi - -RUN mkdir -p /home/www-data/nodes -RUN cp /app/config.ini /home/www-data/config.ini +RUN mkdir -p /app/nodes # thanks to github.com/phusion # this should solve reaping issues of stopped nodes diff --git a/Dockerfile.win b/Dockerfile.win index 11c1bca9..cde4bc7d 100644 --- a/Dockerfile.win +++ b/Dockerfile.win @@ -24,8 +24,7 @@ RUN mv my_init /sbin RUN ./bootstrap_env.sh RUN ./setup_system.sh -RUN mkdir -p /home/www-data/nodes -RUN cp /app/config.ini /home/www-data/config.ini +RUN mkdir -p /app/nodes # thanks to github.com/phusion # this should solve reaping issues of stopped nodes diff --git a/scripts/start_node.sh b/scripts/start_node.sh index ba7cd1de..ef105234 100644 --- a/scripts/start_node.sh +++ b/scripts/start_node.sh @@ -5,4 +5,4 @@ # 3 - snapshot # 4 - node name -nodeos --data-dir=$1 --config-dir=$2 $3 &> /home/www-data/$4.out +nodeos --data-dir=$1 --config-dir=$2 $3 &> /app/$4.out diff --git a/scripts/write_context.sh b/scripts/write_context.sh index 8a98bdb1..bf292351 100644 --- a/scripts/write_context.sh +++ b/scripts/write_context.sh @@ -1,3 +1,3 @@ #! /bin/sh -echo $1 > /home/www-data/.dune.ctx \ No newline at end of file +echo $1 > /app/.dune.ctx \ No newline at end of file diff --git a/src/dune/context.py b/src/dune/context.py index 08ef054d..366ab8f2 100644 --- a/src/dune/context.py +++ b/src/dune/context.py @@ -7,7 +7,7 @@ class ctx: class context: _file_name = ".dune.ctx" - _dir = '/home/www-data/' + _dir = '/app/' _docker = None _ctx = ctx() @@ -49,7 +49,7 @@ def get_active(self): def get_config_args(self, nod): conf, stderr, exit_code = self._docker.execute_cmd( - ['cat', '/home/www-data/nodes/' + nod.name() + '/config.ini']) + ['cat', '/app/nodes/' + nod.name() + '/config.ini']) http_port = None p2p_port = None diff --git a/src/dune/dune.py b/src/dune/dune.py index e139a215..9dcb259f 100644 --- a/src/dune/dune.py +++ b/src/dune/dune.py @@ -60,10 +60,10 @@ def set_config(self, cfg): self._cfg = cfg def data_dir(self): - return '/home/www-data/nodes/' + self.name() + return '/app/nodes/' + self.name() def config_dir(self): - return '/home/www-data/nodes/' + self.name() + return '/app/nodes/' + self.name() class dune: @@ -81,11 +81,11 @@ def __init__(self, cl_args): self._context = context(self._docker) def node_exists(self, nod): - return self._docker.dir_exists('/home/www-data/nodes/' + nod.name()) + return self._docker.dir_exists('/app/nodes/' + nod.name()) def is_node_running(self, nod): return self._docker.find_pid( - '/home/www-data/nodes/' + nod.name() + ' ') != -1 + '/app/nodes/' + nod.name() + ' ') != -1 def set_active(self, nod): if self.node_exists(nod): @@ -102,7 +102,7 @@ def create_node(self, nod): def start_node(self, nod, snapshot=None): stdout, stderr, exit_code = self._docker.execute_cmd( - ['ls', '/home/www-data/nodes']) + ['ls', '/app/nodes']) if self.is_node_running(nod): print("Node [" + nod.name() + "] is already running.") @@ -112,7 +112,7 @@ def start_node(self, nod, snapshot=None): if snapshot is not None: cmd = cmd + [ - '--snapshot /home/www-data/nodes/' + nod.name() + '/snapshots/' + + '--snapshot /app/nodes/' + nod.name() + '/snapshots/' + snapshot + ' -e'] else: cmd = cmd + [' '] @@ -123,7 +123,7 @@ def start_node(self, nod, snapshot=None): # copy config.ini to config-dir if nod.config() is None: - nod.set_config('/home/www-data/config.ini') + nod.set_config('/app/config.ini') self._docker.execute_cmd(['cp', nod.config(), nod.config_dir()]) print("Using Configuration [" + nod.config() + "]") @@ -178,7 +178,7 @@ def stop_node(self, nod): if self.node_exists(nod): if self.is_node_running(nod): pid = self._docker.find_pid( - '/home/www-data/nodes/' + nod.name() + ' ') + '/app/nodes/' + nod.name() + ' ') print("Stopping node [" + nod.name() + "]") self._docker.execute_cmd(['kill', pid]) else: @@ -190,14 +190,14 @@ def remove_node(self, nod): self.stop_node(nod) print("Removing node [" + nod.name() + "]") self._docker.execute_cmd( - ['rm', '-rf', '/home/www-data/nodes/' + nod.name()]) + ['rm', '-rf', '/app/nodes/' + nod.name()]) def destroy(self): self._docker.destroy() def stop_container(self): stdout, stderr, exit_code = self._docker.execute_cmd( - ['ls', '/home/www-data/nodes']) + ['ls', '/app/nodes']) for string in stdout.split(): if self.is_node_running(node(string)): self.stop_node(node(string)) @@ -219,7 +219,7 @@ def list_nodes(self, simple=False): "---------------------------------------------------------" "-----------------------------") stdout, stderr, exit_code = self._docker.execute_cmd( - ['ls', '/home/www-data/nodes']) + ['ls', '/app/nodes']) ctx = self._context.get_ctx() for string in stdout.split(): print(string, end='') @@ -262,26 +262,26 @@ def export_node(self, nod, directory): self.create_snapshot() self.stop_node(nod) self._docker.execute_cmd( - ['mkdir', '-p', '/home/www-data/tmp/' + nod.name()]) + ['mkdir', '-p', '/app/tmp/' + nod.name()]) self._docker.execute_cmd( - ['cp', '-R', '/home/www-data/nodes/' + nod.name() + '/blocks', - '/home/www-data/tmp/' + nod.name() + '/blocks']) + ['cp', '-R', '/app/nodes/' + nod.name() + '/blocks', + '/app/tmp/' + nod.name() + '/blocks']) self._docker.execute_cmd( - ['cp', '/home/www-data/nodes/' + nod.name() + '/config.ini', - '/home/www-data/tmp/' + nod.name() + '/config.ini']) + ['cp', '/app/nodes/' + nod.name() + '/config.ini', + '/app/tmp/' + nod.name() + '/config.ini']) self._docker.execute_cmd(['cp', '-R', - '/home/www-data/nodes/' + nod.name() + + '/app/nodes/' + nod.name() + '/protocol_features', - '/home/www-data/tmp/' + nod.name() + + '/app/tmp/' + nod.name() + '/protocol_features']) self._docker.execute_cmd( - ['cp', '-R', '/home/www-data/nodes/' + nod.name() + '/snapshots', - '/home/www-data/tmp/' + nod.name() + '/snapshots']) + ['cp', '-R', '/app/nodes/' + nod.name() + '/snapshots', + '/app/tmp/' + nod.name() + '/snapshots']) self._docker.tar_dir(nod.name(), 'tmp/' + nod.name()) - self._docker.cp_to_host('/home/www-data/' + nod.name() + '.tgz', + self._docker.cp_to_host('/app/' + nod.name() + '.tgz', directory) - self._docker.rm_file('/home/www-data/' + nod.name() + '.tgz') - self._docker.rm_file('/home/www-data/tmp/' + nod.name()) + self._docker.rm_file('/app/' + nod.name() + '.tgz') + self._docker.rm_file('/app/tmp/' + nod.name()) self.start_node(nod) else: raise dune_node_not_found(nod.name()) @@ -292,37 +292,37 @@ def import_node(self, directory, nod): self.remove_node(nod) stdout, stderr, exit_code = \ self._docker.cp_from_host(directory, - '/home/www-data/tmp.tgz') + '/app/tmp.tgz') if exit_code != 0: print(stderr) raise dune_error - self._docker.untar('/home/www-data/tmp.tgz') - self._docker.rm_file('/home/www-data/tmp.tgz') + self._docker.untar('/app/tmp.tgz') + self._docker.rm_file('/app/tmp.tgz') stdout, stderr, exit_code = self._docker.execute_cmd( - ['ls', '/home/www-data/tmp']) + ['ls', '/app/tmp']) self._docker.execute_cmd( - ['mkdir', '-p', '/home/www-data/nodes/' + nod.name()]) - self._docker.execute_cmd(['mv', '/home/www-data/tmp/' + stdout.split()[ + ['mkdir', '-p', '/app/nodes/' + nod.name()]) + self._docker.execute_cmd(['mv', '/app/tmp/' + stdout.split()[ 0] + '/blocks/blocks.index', - '/home/www-data/nodes/' + nod.name() + + '/app/nodes/' + nod.name() + '/blocks/blocks.index']) - self._docker.execute_cmd(['mv', '/home/www-data/tmp/' + stdout.split()[ + self._docker.execute_cmd(['mv', '/app/tmp/' + stdout.split()[ 0] + '/blocks/blocks.log', - '/home/www-data/nodes/' + nod.name() + + '/app/nodes/' + nod.name() + '/blocks/blocks.log']) self._docker.execute_cmd( - ['mv', '/home/www-data/tmp/' + stdout.split()[0] + '/config.ini', - '/home/www-data/nodes/' + nod.name() + '/config.ini']) - self._docker.execute_cmd(['mv', '/home/www-data/tmp/' + stdout.split()[ + ['mv', '/app/tmp/' + stdout.split()[0] + '/config.ini', + '/app/nodes/' + nod.name() + '/config.ini']) + self._docker.execute_cmd(['mv', '/app/tmp/' + stdout.split()[ 0] + '/protocol_features', - '/home/www-data/nodes/' + nod.name() + + '/app/nodes/' + nod.name() + '/protocol_features']) self._docker.execute_cmd( - ['mv', '/home/www-data/tmp/' + stdout.split()[0] + '/snapshots', - '/home/www-data/nodes/' + nod.name() + '/snapshots']) - self._docker.rm_file('/home/www-data/tmp/' + stdout.split()[0]) + ['mv', '/app/tmp/' + stdout.split()[0] + '/snapshots', + '/app/nodes/' + nod.name() + '/snapshots']) + self._docker.rm_file('/app/tmp/' + stdout.split()[0]) stdout, stderr, exit_code = self._docker.execute_cmd( - ['ls', '/home/www-data/nodes/' + nod.name() + '/snapshots']) + ['ls', '/app/nodes/' + nod.name() + '/snapshots']) self.start_node(nod, stdout.split()[0]) self.set_active(nod) @@ -343,17 +343,19 @@ def create_key(self): return stdout def export_wallet(self): - self._docker.execute_cmd(['mkdir', '_wallet']) - self._docker.execute_cmd(['cp', '-R', '/root/eosio-wallet', '_wallet/eosio-wallet']) - self._docker.execute_cmd(['cp', '-R', '.wallet.pw', '_wallet/.wallet.pw']) + self._docker.execute_cmd(['mkdir', '/app/_wallet']) + self._docker.execute_cmd(['cp', '-R', '/root/eosio-wallet/', '/app/_wallet/eosio-wallet']) + self._docker.execute_cmd(['cp', '-R', '/app/.wallet.pw', '/app/_wallet/.wallet.pw']) self._docker.tar_dir("wallet", "_wallet") self._docker.cp_to_host("/app/wallet.tgz", "wallet.tgz") def import_wallet(self, path): - self._docker.cp_from_host(path, "wallet.tgz") - self._docker.untar("wallet.tgz") - self._docker.execute_cmd(["mv", "_wallet/.wallet.pw", "/app"]) - self._docker.execute_cmd(["mv", "_wallet", "/root"]) + self._docker.cp_from_host(path, "/app/wallet.tgz") + self._docker.untar("/app/wallet.tgz") + self._docker.execute_cmd(["mv", "/app/_wallet/.wallet.pw", "/app"]) + self._docker.execute_cmd(["cp", "-R", "/app/_wallet/eosio-wallet/", "/root"]) + self._docker.execute_cmd(["rm", "-R", "/app/_wallet/"]) + self._docker.execute_cmd(["rm", "/app/wallet.tgz"]) # pylint: disable=fixme # TODO cleos has a bug displaying keys for K1 so, we need the public key