Skip to content

Commit

Permalink
Add deploy setup command
Browse files Browse the repository at this point in the history
  • Loading branch information
dboreham committed Jul 19, 2023
1 parent 43d9861 commit dcfd7e3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
28 changes: 27 additions & 1 deletion app/data/stacks/mainnet-laconic/deploy/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>.

from dataclasses import dataclass
from app.util import get_yaml
from app.stack_state import State

Expand All @@ -24,6 +25,27 @@
init_help_text = """Add helpful text here on setting config variables.
"""

@dataclass
class VolumeMapping:
host_path: str
container_path: str


# In order to make this, we need the ability to run the stack
# In theory we can make this same way as we would run deploy up
def run_container_command(ctx, ontainer, command, mounts):
deploy_context = ctx.obj
pass


def setup(ctx):
node_moniker = "dbdb-node"
chain_id = "laconic_81337-1"
mounts = [
VolumeMapping("./path", "~/.laconicd")
]
output, status = run_container_command(ctx, "laconicd", f"laconicd init {node_moniker} --chain-id {chain_id}", mounts)


def init(command_context):
print(init_help_text)
Expand All @@ -33,4 +55,8 @@ def init(command_context):

def get_state(command_context):
print("Here we get state")
return State.CONFIGURED
return State.CONFIGURED


def change_state(command_context):
pass
2 changes: 2 additions & 0 deletions app/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from app.util import include_exclude_check, get_parsed_stack_config, global_options2
from app.deployment_create import create as deployment_create
from app.deployment_create import init as deployment_init
from app.deployment_create import setup as deployment_setup


class DeployCommandContext(object):
Expand Down Expand Up @@ -420,3 +421,4 @@ class ConfigDirective:

command.add_command(deployment_init)
command.add_command(deployment_create)
command.add_command(deployment_setup)
12 changes: 0 additions & 12 deletions app/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,3 @@ def logs(ctx, extra_args):
@click.pass_context
def status(ctx):
print(f"Context: {ctx.parent.obj}")



#from importlib import resources, util
# TODO: figure out how to do this dynamically
#stack = "mainnet-laconic"
#module_name = "commands"
#spec = util.spec_from_file_location(module_name, "./app/data/stacks/" + stack + "/deploy/commands.py")
#imported_stack = util.module_from_spec(spec)
#spec.loader.exec_module(imported_stack)
#command.add_command(imported_stack.init)
#command.add_command(imported_stack.create)
24 changes: 24 additions & 0 deletions app/deployment_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ def call_stack_deploy_init(stack):
return imported_stack.init(None)


# TODO: fold this with function above
def call_stack_deploy_setup(stack):
# Link with the python file in the stack
# Call a function in it
# If no function found, return None
python_file_path = get_stack_file_path(stack).parent.joinpath("deploy", "commands.py")
spec = util.spec_from_file_location("commands", python_file_path)
imported_stack = util.module_from_spec(spec)
spec.loader.exec_module(imported_stack)
return imported_stack.setup(None)


@click.command()
@click.option("--output", required=True, help="Write yaml spec file here")
@click.pass_context
Expand Down Expand Up @@ -158,3 +170,15 @@ def create(ctx, spec_file, deployment_dir):
source_config_dir = data_dir.joinpath("config", pod)
if os.path.exists(source_config_dir):
copytree(source_config_dir, os.path.join(deployment_dir, "config", pod))


@click.command()
@click.option("--node-moniker", help="Help goes here")
@click.option("--key-name", help="Help goes here")
@click.option("--initialize-network", is_flag=True, default=False, help="Help goes here")
@click.option("--join-network", is_flag=True, default=False, help="Help goes here")
@click.option("--create-network", is_flag=True, default=False, help="Help goes here")
@click.pass_context
def setup(ctx, node_moniker, key_name, initialize_network, join_network, create_network):
stack = global_options(ctx).stack
call_stack_deploy_setup(stack)

0 comments on commit dcfd7e3

Please sign in to comment.