ContainerizedService: Use the same file path inside container by default

Signed-off-by: Vitaliy Potyarkin <v.potyarkin@yadro.com>
This commit is contained in:
Vitaliy Potyarkin 2025-05-12 16:24:44 +03:00
parent d55026fe13
commit f3bda0cc9b
5 changed files with 33 additions and 23 deletions

View file

@ -102,11 +102,13 @@ class ContainerizedService:
socket._sock.close() socket._sock.close()
socket.close() socket.close()
def add_file(self, src: Path, dest: Path) -> None: def add_file(self, src: Path, dest: Path = None) -> None:
""" """
Add file from local filesystem into a running container. Add file from local filesystem into a running container.
Keeps a copy of the whole file in memory (TODO: stream directly from disk). Keeps a copy of the whole file in memory (TODO: stream directly from disk).
""" """
if dest is None:
dest = src
file = tarfile.TarInfo(str(dest)) file = tarfile.TarInfo(str(dest))
file.size = Path(src).stat().st_size file.size = Path(src).stat().st_size
if file.size > (64 << 20): if file.size > (64 << 20):
@ -120,8 +122,10 @@ class ContainerizedService:
archive.seek(0) archive.seek(0)
self._container.put_archive("/", archive) self._container.put_archive("/", archive)
def add_directory(self, src: Path, dest: Path) -> None: def add_directory(self, src: Path, dest: Path = None) -> None:
"""Add all files from directory (one by one).""" """Add all files from directory (one by one)."""
if dest is None:
dest = src
dest = Path(dest) dest = Path(dest)
for root, _, files in os.walk(src): for root, _, files in os.walk(src):
root = Path(root) root = Path(root)

View file

@ -364,6 +364,7 @@ def neogo_config(neogo_deployment, adm_config, alphabet_wallets):
dict( dict(
letter=letter, letter=letter,
index=index, index=index,
wallet=alphabet_dir / f"{letter}.json",
password=credentials[letter], password=credentials[letter],
) )
) )
@ -395,14 +396,15 @@ def neogo(neogo_deployment, neogo_config, alphabet_deployment, frostfs_adm, _net
nodes = [] nodes = []
for index in range(neogo_deployment.node_count): for index in range(neogo_deployment.node_count):
letter = glagolic[index] letter = glagolic[index]
config_file = config_dir / f"{letter}.json"
node = ContainerizedService( node = ContainerizedService(
command=f"neo-go node --config-file /neogo/{letter}.json --privnet --debug", command=f"neo-go node --config-file '{config_file}' --privnet --debug",
image=f"{neogo_deployment.image}:{neogo_deployment.version}", image=f"{neogo_deployment.image}:{neogo_deployment.version}",
name=f"{neogo_deployment.prefix}{index+1}", name=f"{neogo_deployment.prefix}{index+1}",
network=_network, network=_network,
) )
node.add_file(wallet_dir / f"{letter}.json", f"/wallet/{letter}.json") node.add_file(wallet_dir / f"{letter}.json")
node.add_file(config_dir / f"{letter}.json", f"/neogo/{letter}.json") node.add_file(config_file)
node.start() node.start()
nodes.append(node) nodes.append(node)
@ -433,8 +435,8 @@ def frostfs_adm(adm_deployment, adm_config, alphabet_deployment, _network):
network=_network, network=_network,
) )
wallet_dir = alphabet_deployment.dir wallet_dir = alphabet_deployment.dir
adm.add_directory(wallet_dir, wallet_dir) adm.add_directory(wallet_dir)
adm.add_file(config_file, config_file) adm.add_file(config_file)
yield adm yield adm
adm.destroy() adm.destroy()
@ -446,7 +448,7 @@ def frostfs_bootstrap(frostfs_contract, frostfs_adm, neogo) -> Mapping[str, str]
def morph(command: str) -> str: def morph(command: str) -> str:
output[command] = frostfs_adm(f"morph {command}") output[command] = frostfs_adm(f"morph {command}")
frostfs_adm.add_directory(frostfs_contract, frostfs_contract) frostfs_adm.add_directory(frostfs_contract)
morph(f"init --contracts '{frostfs_contract}'") morph(f"init --contracts '{frostfs_contract}'")
morph( morph(
"ape add-rule-chain " "ape add-rule-chain "
@ -512,6 +514,7 @@ def innerring_config(innerring_deployment, neogo, adm_config, alphabet_wallets):
dict( dict(
letter=letter, letter=letter,
index=index, index=index,
wallet=alphabet_dir / f"{letter}.json",
password=credentials[letter], password=credentials[letter],
neogo=neogo[index].name, neogo=neogo[index].name,
) )
@ -533,15 +536,16 @@ def innerring(innerring_deployment, innerring_config, frostfs_locode, frostfs_bo
nodes = [] nodes = []
for index in range(alphabet_deployment.node_count): for index in range(alphabet_deployment.node_count):
letter = glagolic[index] letter = glagolic[index]
config_file = config_dir / f"{letter}.json"
node = ContainerizedService( node = ContainerizedService(
command=f"frostfs-ir --config /innerring/{letter}.json", command=f"frostfs-ir --config '{config_file}'",
image=f"{innerring_deployment.image}:{innerring_deployment.version}", image=f"{innerring_deployment.image}:{innerring_deployment.version}",
name=f"{innerring_deployment.prefix}{index+1}", name=f"{innerring_deployment.prefix}{index+1}",
network=_network, network=_network,
) )
node.add_file(wallet_dir / f"{letter}.json", f"/wallet/{letter}.json") node.add_file(wallet_dir / f"{letter}.json")
node.add_file(config_dir / f"{letter}.json", f"/innerring/{letter}.json") node.add_file(config_file)
node.add_file(frostfs_locode, f"/innerring/locode.db") node.add_file(frostfs_locode, "/innerring/locode.db")
node.start() node.start()
nodes.append(node) nodes.append(node)
yield nodes yield nodes
@ -582,7 +586,7 @@ def storage_config(storage_deployment, neogo, frostfs_adm, innerring):
_update(config, override) _update(config, override)
with open(storage_deployment.dir / f"config-{index}.json", "w") as c: with open(storage_deployment.dir / f"config-{index}.json", "w") as c:
json.dump(config, c, ensure_ascii=False, indent=True, sort_keys=True) json.dump(config, c, ensure_ascii=False, indent=True, sort_keys=True)
frostfs_adm.add_file(wallet, wallet) frostfs_adm.add_file(wallet)
frostfs_adm(f"morph refill-gas --storage-wallet '{wallet}' --gas 50.0") frostfs_adm(f"morph refill-gas --storage-wallet '{wallet}' --gas 50.0")
configs.append(config) configs.append(config)
yield configs, storage_deployment.dir yield configs, storage_deployment.dir
@ -594,14 +598,15 @@ def storage(storage_deployment, storage_config, frostfs_adm, _network):
nodes = [] nodes = []
configs, _ = storage_config configs, _ = storage_config
for index, config in enumerate(configs): for index, config in enumerate(configs):
config_file = storage_deployment.dir / f"config-{index}.json"
node = ContainerizedService( node = ContainerizedService(
command=f"frostfs-node --config /storage/config.json", command=f"frostfs-node --config '{config_file}'",
image=f"{storage_deployment.image}:{storage_deployment.version}", image=f"{storage_deployment.image}:{storage_deployment.version}",
name=f"{storage_deployment.prefix}{index+1}", name=f"{storage_deployment.prefix}{index+1}",
network=_network, network=_network,
) )
node.add_file(config["node"]["wallet"]["path"], config["node"]["wallet"]["path"]) node.add_file(config["node"]["wallet"]["path"])
node.add_file(storage_deployment.dir / f"config-{index}.json", f"/storage/config.json") node.add_file(config_file)
node.start() node.start()
nodes.append(node) nodes.append(node)
for index, node in enumerate(nodes): for index, node in enumerate(nodes):
@ -655,14 +660,15 @@ def httpgw(httpgw_deployment, httpgw_config, _network):
nodes = [] nodes = []
configs, _ = httpgw_config configs, _ = httpgw_config
for index, config in enumerate(configs): for index, config in enumerate(configs):
config_file = httpgw_deployment.dir / f"config-{index}.json"
node = ContainerizedService( node = ContainerizedService(
command=f"frostfs-http-gw --config /httpgw/config.json", command=f"frostfs-http-gw --config '{config_file}'",
image=f"{httpgw_deployment.image}:{httpgw_deployment.version}", image=f"{httpgw_deployment.image}:{httpgw_deployment.version}",
name=f"{httpgw_deployment.prefix}{index+1}", name=f"{httpgw_deployment.prefix}{index+1}",
network=_network, network=_network,
) )
node.add_file(config["wallet"]["path"], config["wallet"]["path"]) node.add_file(config["wallet"]["path"])
node.add_file(httpgw_deployment.dir / f"config-{index}.json", f"/httpgw/config.json") node.add_file(config_file)
node.start() node.start()
nodes.append(node) nodes.append(node)
ready = re.compile(r"starting server.*\:80") ready = re.compile(r"starting server.*\:80")

View file

@ -9,7 +9,7 @@ control:
# Wallet settings # Wallet settings
wallet: wallet:
path: /wallet/{letter}.json path: {wallet}
password: {password} password: {password}
# Profiler section # Profiler section

View file

@ -46,7 +46,7 @@ ApplicationConfiguration:
Consensus: Consensus:
Enabled: true Enabled: true
UnlockWallet: UnlockWallet:
Path: "/wallet/{letter}.json" Path: "{wallet}"
Password: "{password}" Password: "{password}"
RPC: RPC:
Addresses: Addresses:
@ -58,7 +58,7 @@ ApplicationConfiguration:
P2PNotary: P2PNotary:
Enabled: true Enabled: true
UnlockWallet: UnlockWallet:
Path: "/wallet/{letter}.json" Path: "{wallet}"
Password: "{password}" Password: "{password}"
Prometheus: Prometheus:
Addresses: Addresses:

View file

@ -43,7 +43,7 @@ node:
attribute_0: "User-Agent:FrostFS component tests" attribute_0: "User-Agent:FrostFS component tests"
attribute_1: "Price:{price}" attribute_1: "Price:{price}"
persistent_state: persistent_state:
path: /storage/state path: /storage.state
grpc: grpc:
- endpoint: :8802 - endpoint: :8802