mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-21 20:33:00 +00:00
Leveraging rsync, removed need for "kiwi clean" and "kiwi conf-purge".
This commit is contained in:
parent
8fbc44e3ff
commit
268188090b
4 changed files with 3 additions and 64 deletions
|
@ -2,7 +2,6 @@ Commands for Operation:
|
||||||
up Bring up the whole instance, a project or service(s) inside a project
|
up Bring up the whole instance, a project or service(s) inside a project
|
||||||
down Bring down the whole instance, a project or service(s) inside a project
|
down Bring down the whole instance, a project or service(s) inside a project
|
||||||
update Update the whole instance, a project or service(s) inside a project
|
update Update the whole instance, a project or service(s) inside a project
|
||||||
clean Cleanly sync all configs to target folder, then relaunch affected projects
|
|
||||||
purge Remove all running docker artifacts of this instance
|
purge Remove all running docker artifacts of this instance
|
||||||
|
|
||||||
Commands for Instance Management:
|
Commands for Instance Management:
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
# local
|
# local
|
||||||
from ._hidden import ConfCopyCommand, ConfPurgeCommand, NetUpCommand
|
from ._hidden import ConfCopyCommand, NetUpCommand
|
||||||
|
|
||||||
from .build import BuildCommand
|
from .build import BuildCommand
|
||||||
from .clean import CleanCommand
|
|
||||||
from .cmd import CmdCommand
|
from .cmd import CmdCommand
|
||||||
from .config import ConfigCommand
|
from .config import ConfigCommand
|
||||||
from .disable import DisableCommand
|
from .disable import DisableCommand
|
||||||
|
@ -20,11 +19,9 @@ from .update import UpdateCommand
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'ConfCopyCommand',
|
'ConfCopyCommand',
|
||||||
'ConfPurgeCommand',
|
|
||||||
'NetUpCommand',
|
'NetUpCommand',
|
||||||
|
|
||||||
'BuildCommand',
|
'BuildCommand',
|
||||||
'CleanCommand',
|
|
||||||
'CmdCommand',
|
'CmdCommand',
|
||||||
'ConfigCommand',
|
'ConfigCommand',
|
||||||
'DisableCommand',
|
'DisableCommand',
|
||||||
|
|
|
@ -25,6 +25,7 @@ class ConfCopyCommand(SubCommand):
|
||||||
conf_dirs = [
|
conf_dirs = [
|
||||||
project.conf_dir_name()
|
project.conf_dir_name()
|
||||||
for project in Projects.from_dir().filter_enabled()
|
for project in Projects.from_dir().filter_enabled()
|
||||||
|
if project.has_configs()
|
||||||
]
|
]
|
||||||
|
|
||||||
if conf_dirs:
|
if conf_dirs:
|
||||||
|
@ -33,33 +34,12 @@ class ConfCopyCommand(SubCommand):
|
||||||
logging.info(f"Sync directories: {conf_dirs}")
|
logging.info(f"Sync directories: {conf_dirs}")
|
||||||
|
|
||||||
Rootkit('rsync').run([
|
Rootkit('rsync').run([
|
||||||
'rsync', '-r', *prefix_path_mnt(conf_dirs)
|
'rsync', '-rpt', '--delete', *prefix_path_mnt(conf_dirs)
|
||||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ConfPurgeCommand(SubCommand):
|
|
||||||
"""kiwi conf-purge"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__(
|
|
||||||
'conf-purge',
|
|
||||||
action="Removing all configs for", add_parser=False,
|
|
||||||
description="Remove all config files in target directory"
|
|
||||||
)
|
|
||||||
|
|
||||||
def _run_instance(self, runner, args):
|
|
||||||
conf_target = f"{LoadedConfig.get()['runtime:storage']}/{CONF_DIRECTORY_NAME}"
|
|
||||||
logging.info(f"Purging directories: {conf_target}")
|
|
||||||
|
|
||||||
Rootkit().run([
|
|
||||||
'rm', '-rf', prefix_path_mnt(conf_target)
|
|
||||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def _find_net(net_name):
|
def _find_net(net_name):
|
||||||
ps = Executable('docker').run([
|
ps = Executable('docker').run([
|
||||||
'network', 'ls', '--filter', f"name={net_name}", '--format', '{{.Name}}'
|
'network', 'ls', '--filter', f"name={net_name}", '--format', '{{.Name}}'
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
from ..projects import Projects
|
|
||||||
from ..subcommand import SubCommand
|
|
||||||
|
|
||||||
|
|
||||||
class CleanCommand(SubCommand):
|
|
||||||
"""kiwi clean"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__(
|
|
||||||
'clean',
|
|
||||||
action="Cleaning all configs for",
|
|
||||||
description="Cleanly sync all configs to target folder, then relaunch affected projects"
|
|
||||||
)
|
|
||||||
|
|
||||||
def _run_instance(self, runner, args):
|
|
||||||
result = True
|
|
||||||
|
|
||||||
affected_projects = [
|
|
||||||
project.get_name()
|
|
||||||
for project in Projects.from_dir()
|
|
||||||
if project.has_configs()
|
|
||||||
]
|
|
||||||
|
|
||||||
for project_name in affected_projects:
|
|
||||||
args.projects = project_name
|
|
||||||
result &= runner.run('down')
|
|
||||||
|
|
||||||
# cleanly sync configs
|
|
||||||
result &= runner.run('conf-purge')
|
|
||||||
result &= runner.run('conf-copy')
|
|
||||||
|
|
||||||
# bring projects back up
|
|
||||||
for project_name in affected_projects:
|
|
||||||
args.projects = project_name
|
|
||||||
result &= runner.run('up')
|
|
||||||
|
|
||||||
return result
|
|
Loading…
Reference in a new issue