Run a laconicd command

This commit is contained in:
David Boreham 2023-08-06 12:29:56 -06:00
parent 73e52c4eed
commit 109c6dc8ed
3 changed files with 9 additions and 6 deletions

View File

@ -14,7 +14,7 @@
# along with this program. If not, see <http:#www.gnu.org/licenses/>. # along with this program. If not, see <http:#www.gnu.org/licenses/>.
from app.util import get_yaml from app.util import get_yaml
from app.deploy_types import DeployCommandContext, DeploymentContext from app.deploy_types import DeployCommandContext
from app.stack_state import State from app.stack_state import State
from app.deploy_util import VolumeMapping, run_container_command from app.deploy_util import VolumeMapping, run_container_command
@ -27,13 +27,15 @@ init_help_text = """Add helpful text here on setting config variables.
""" """
def setup(command_context: DeployCommandContext): def setup(command_context: DeployCommandContext, extra_args):
node_moniker = "dbdb-node" node_moniker = "dbdb-node"
chain_id = "laconic_81337-1" chain_id = "laconic_81337-1"
mounts = [ mounts = [
VolumeMapping("./path", "~/.laconicd") VolumeMapping("./path", "/root/.laconicd")
] ]
output, status = run_container_command(command_context.cluster_context, "laconicd", f"laconicd init {node_moniker} --chain-id {chain_id}", mounts) output, status = run_container_command(
command_context, "laconicd", f"laconicd init {node_moniker} --chain-id {chain_id}", mounts)
print(f"Command output: {output}")
def init(command_context: DeployCommandContext): def init(command_context: DeployCommandContext):

View File

@ -27,6 +27,7 @@ default_spec_file_content = """config:
init_help_text = """Add helpful text here on setting config variables. init_help_text = """Add helpful text here on setting config variables.
""" """
# Output a known string to a know file in the bind mounted directory ./container-output-dir # Output a known string to a know file in the bind mounted directory ./container-output-dir
# for test purposes -- test checks that the file was written. # for test purposes -- test checks that the file was written.
def setup(command_context: DeployCommandContext, extra_args): def setup(command_context: DeployCommandContext, extra_args):

View File

@ -39,7 +39,7 @@ def _container_image_from_service(stack:str, service: str):
def _volumes_to_docker(mounts: List[VolumeMapping]): def _volumes_to_docker(mounts: List[VolumeMapping]):
# Example from doc: [("/", "/host"), ("/etc/hosts", "/etc/hosts", "rw")] # Example from doc: [("/", "/host"), ("/etc/hosts", "/etc/hosts", "rw")]
result = [] result = []
for mount in mounts: for mount in mounts:
docker_volume = (mount.host_path, mount.container_path) docker_volume = (mount.host_path, mount.container_path)
@ -51,6 +51,6 @@ def run_container_command(ctx: DeployCommandContext, service: str, command: str,
docker = ctx.docker docker = ctx.docker
container_image = _container_image_from_service(ctx.stack, service) container_image = _container_image_from_service(ctx.stack, service)
docker_volumes = _volumes_to_docker(mounts) docker_volumes = _volumes_to_docker(mounts)
docker_output = docker.run(container_image, ["-c", command], entrypoint="bash", volumes=docker_volumes) docker_output = docker.run(container_image, ["-c", command], entrypoint="sh", volumes=docker_volumes)
# There doesn't seem to be a way to get an exit code from docker.run() # There doesn't seem to be a way to get an exit code from docker.run()
return (docker_output, 0) return (docker_output, 0)