1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-12-25 18:42:59 +00:00

Leveraging rsync, removed need for "kiwi clean" and "kiwi conf-purge".

This commit is contained in:
Jörn-Michael Miehe 2020-08-25 15:41:27 +02:00
parent 8fbc44e3ff
commit 268188090b
4 changed files with 3 additions and 64 deletions

View file

@ -2,7 +2,6 @@ Commands for Operation:
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
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
Commands for Instance Management:

View file

@ -1,8 +1,7 @@
# local
from ._hidden import ConfCopyCommand, ConfPurgeCommand, NetUpCommand
from ._hidden import ConfCopyCommand, NetUpCommand
from .build import BuildCommand
from .clean import CleanCommand
from .cmd import CmdCommand
from .config import ConfigCommand
from .disable import DisableCommand
@ -20,11 +19,9 @@ from .update import UpdateCommand
__all__ = [
'ConfCopyCommand',
'ConfPurgeCommand',
'NetUpCommand',
'BuildCommand',
'CleanCommand',
'CmdCommand',
'ConfigCommand',
'DisableCommand',

View file

@ -25,6 +25,7 @@ class ConfCopyCommand(SubCommand):
conf_dirs = [
project.conf_dir_name()
for project in Projects.from_dir().filter_enabled()
if project.has_configs()
]
if conf_dirs:
@ -33,33 +34,12 @@ class ConfCopyCommand(SubCommand):
logging.info(f"Sync directories: {conf_dirs}")
Rootkit('rsync').run([
'rsync', '-r', *prefix_path_mnt(conf_dirs)
'rsync', '-rpt', '--delete', *prefix_path_mnt(conf_dirs)
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
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):
ps = Executable('docker').run([
'network', 'ls', '--filter', f"name={net_name}", '--format', '{{.Name}}'

View file

@ -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