mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 19:51:35 +01:00
docker: fix after args refactor
This commit is contained in:
committed by
Ciro Santilli 六四事件 法轮功
parent
22e26aa002
commit
9a2e630fed
33
run-docker
33
run-docker
@@ -4,18 +4,19 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import common
|
import common
|
||||||
|
import shell_helpers
|
||||||
from shell_helpers import LF
|
from shell_helpers import LF
|
||||||
|
|
||||||
container_name = kwargs['repo_short_id']
|
container_name = common.consts['repo_short_id']
|
||||||
container_hostname = kwargs['repo_short_id']
|
container_hostname = common.consts['repo_short_id']
|
||||||
image_name = kwargs['repo_short_id']
|
image_name = common.consts['repo_short_id']
|
||||||
target_dir = '/root/{}'.format(kwargs['repo_short_id'])
|
target_dir = '/root/{}'.format(common.consts['repo_short_id'])
|
||||||
docker = ['sudo', 'docker']
|
docker = ['sudo', 'docker']
|
||||||
def create(args):
|
def create(args):
|
||||||
self.sh.run_cmd(docker + ['build', '-t', image_name, '.', LF])
|
sh.run_cmd(docker + ['build', '-t', image_name, '.', LF])
|
||||||
# --privileged for KVM:
|
# --privileged for KVM:
|
||||||
# https://stackoverflow.com/questions/48422001/launching-qemu-kvm-from-inside-docker-container
|
# https://stackoverflow.com/questions/48422001/launching-qemu-kvm-from-inside-docker-container
|
||||||
self.sh.run_cmd(
|
sh.run_cmd(
|
||||||
docker +
|
docker +
|
||||||
[
|
[
|
||||||
'create', LF,
|
'create', LF,
|
||||||
@@ -32,34 +33,34 @@ def create(args):
|
|||||||
)
|
)
|
||||||
def destroy(args):
|
def destroy(args):
|
||||||
stop(args)
|
stop(args)
|
||||||
self.sh.run_cmd(docker + ['rm', container_name, LF])
|
sh.run_cmd(docker + ['rm', container_name, LF])
|
||||||
self.sh.run_cmd(docker + ['rmi', image_name, LF])
|
sh.run_cmd(docker + ['rmi', image_name, LF])
|
||||||
def sh(args):
|
def sh_func(args):
|
||||||
start(args)
|
start(args)
|
||||||
if args:
|
if args:
|
||||||
sh_args = args
|
sh_args = args
|
||||||
else:
|
else:
|
||||||
sh_args = ['bash']
|
sh_args = ['bash']
|
||||||
self.sh.run_cmd(
|
sh.run_cmd(
|
||||||
docker + ['exec', '-i', '-t', container_name] +
|
docker + ['exec', '-i', '-t', container_name] +
|
||||||
sh_args +
|
sh_args +
|
||||||
[LF],
|
[LF],
|
||||||
)
|
)
|
||||||
def start(args):
|
def start(args):
|
||||||
self.sh.run_cmd(docker + ['start', container_name, LF])
|
sh.run_cmd(docker + ['start', container_name, LF])
|
||||||
def stop(args):
|
def stop(args):
|
||||||
self.sh.run_cmd(docker + ['stop', container_name, LF])
|
sh.run_cmd(docker + ['stop', container_name, LF])
|
||||||
cmd_action_map = {
|
cmd_action_map = {
|
||||||
'create': lambda args: create(args),
|
'create': lambda args: create(args),
|
||||||
'DESTROY': lambda args: destroy(args),
|
'DESTROY': lambda args: destroy(args),
|
||||||
'sh': lambda args: sh(args),
|
'sh': lambda args: sh_func(args),
|
||||||
'start': lambda args: start(args),
|
'start': lambda args: start(args),
|
||||||
'stop': lambda args: stop(args),
|
'stop': lambda args: stop(args),
|
||||||
}
|
}
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--dry-run', default=False, action='store_true')
|
||||||
parser.add_argument('cmd', choices=cmd_action_map)
|
parser.add_argument('cmd', choices=cmd_action_map)
|
||||||
parser.add_argument('args', nargs='*')
|
parser.add_argument('args', nargs='*')
|
||||||
self.add_dry_run_argument(parser)
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
self.setup_dry_run_arguments(args)
|
sh = shell_helpers.ShellHelpers(dry_run=args.dry_run)
|
||||||
cmd_action_map[kwargs['cmd']](kwargs['args'])
|
cmd_action_map[args.cmd](args.args)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class ShellHelpers:
|
|||||||
:param dry_run: don't run the commands, just potentially print them. Debug aid.
|
:param dry_run: don't run the commands, just potentially print them. Debug aid.
|
||||||
:type dry_run: Bool
|
:type dry_run: Bool
|
||||||
|
|
||||||
:param quiet: don't print the commands.
|
:param quiet: don't print the commands
|
||||||
:type dry_run: Bool
|
:type dry_run: Bool
|
||||||
'''
|
'''
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
|
|||||||
Reference in New Issue
Block a user