mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
docker: move to component
This commit is contained in:
126
build-docker
126
build-docker
@@ -1,75 +1,79 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import common
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import tarfile
|
import tarfile
|
||||||
import time
|
|
||||||
|
|
||||||
parser = common.get_argparse(argparse_args={
|
import common
|
||||||
'description': '''\
|
|
||||||
|
|
||||||
|
class DockerComponent(common.Component):
|
||||||
|
def get_argparse_args(self):
|
||||||
|
return {
|
||||||
|
'description': '''\
|
||||||
Build a guest root filesystem based on prebuilt Docker Ubuntu root filesystems.
|
Build a guest root filesystem based on prebuilt Docker Ubuntu root filesystems.
|
||||||
|
|
||||||
See also:https://github.com/cirosantilli/linux-kernel-module-cheat#ubuntu-guest-setup
|
See also:https://github.com/cirosantilli/linux-kernel-module-cheat#ubuntu-guest-setup
|
||||||
'''
|
'''
|
||||||
},
|
}
|
||||||
default_args={'docker': True},
|
|
||||||
)
|
def do_build(self, args):
|
||||||
common.add_build_arguments(parser)
|
build_dir = self.get_build_dir(args)
|
||||||
args = common.setup(parser)
|
container_name = 'lkmc-guest'
|
||||||
container_name = 'lkmc-guest'
|
target_dir = os.path.join('/root', 'linux-kernel-module-cheat')
|
||||||
#common.rmrf(common.docker_build_dir)
|
os.makedirs(build_dir, exist_ok=True)
|
||||||
if not args.clean:
|
containers = subprocess.check_output([
|
||||||
start_time = time.time()
|
'docker',
|
||||||
target_dir = os.path.join('/root', 'linux-kernel-module-cheat')
|
'ps',
|
||||||
os.makedirs(common.docker_build_dir, exist_ok=True)
|
'-a',
|
||||||
containers = subprocess.check_output([
|
'--format', '{{.Names}}',
|
||||||
'docker',
|
]).decode()
|
||||||
'ps',
|
if container_name in containers.split():
|
||||||
'-a',
|
common.run_cmd([
|
||||||
'--format', '{{.Names}}',
|
'docker',
|
||||||
]).decode()
|
'rm',
|
||||||
if container_name in containers.split():
|
container_name,
|
||||||
|
])
|
||||||
common.run_cmd([
|
common.run_cmd([
|
||||||
'docker',
|
'docker',
|
||||||
'rm',
|
'create',
|
||||||
|
'--name', container_name,
|
||||||
|
'--net',
|
||||||
|
'host',
|
||||||
|
'-i',
|
||||||
|
'--privileged',
|
||||||
|
'-t',
|
||||||
|
'-w', target_dir,
|
||||||
|
'-v', '{}:{}'.format(common.root_dir, target_dir),
|
||||||
|
'ubuntu:18.04',
|
||||||
|
'bash',
|
||||||
|
])
|
||||||
|
common.run_cmd([
|
||||||
|
'docker',
|
||||||
|
'export',
|
||||||
|
'-o',
|
||||||
|
common.docker_tar_file,
|
||||||
container_name,
|
container_name,
|
||||||
])
|
])
|
||||||
common.run_cmd([
|
tar = tarfile.open(common.docker_tar_file)
|
||||||
'docker',
|
tar.extractall(common.docker_tar_dir)
|
||||||
'create',
|
tar.close()
|
||||||
'--name', container_name,
|
# sudo not required in theory
|
||||||
'--net',
|
# https://askubuntu.com/questions/1046828/how-to-run-libguestfs-tools-tools-such-as-virt-make-fs-without-sudo
|
||||||
'host',
|
common.run_cmd([
|
||||||
'-i',
|
'virt-make-fs',
|
||||||
'--privileged',
|
'--format', 'raw',
|
||||||
'-t',
|
'--size', '+1G',
|
||||||
'-w', target_dir,
|
'--type', 'ext2',
|
||||||
'-v', '{}:{}'.format(common.root_dir, target_dir),
|
common.docker_tar_dir,
|
||||||
'ubuntu:18.04',
|
common.docker_rootfs_raw_file,
|
||||||
'bash',
|
])
|
||||||
])
|
common.raw_to_qcow2(prebuilt=True)
|
||||||
common.run_cmd([
|
|
||||||
'docker',
|
def get_build_dir(self, args):
|
||||||
'export',
|
return common.docker_build_dir
|
||||||
'-o',
|
|
||||||
common.docker_tar_file,
|
def get_default_args(self):
|
||||||
container_name,
|
return {'docker': True}
|
||||||
])
|
|
||||||
tar = tarfile.open(common.docker_tar_file)
|
DockerComponent().build()
|
||||||
tar.extractall(common.docker_tar_dir)
|
|
||||||
tar.close()
|
|
||||||
# sudo not required in theory
|
|
||||||
# https://askubuntu.com/questions/1046828/how-to-run-libguestfs-tools-tools-such-as-virt-make-fs-without-sudo
|
|
||||||
common.run_cmd([
|
|
||||||
'virt-make-fs',
|
|
||||||
'--format', 'raw',
|
|
||||||
'--size', '+1G',
|
|
||||||
'--type', 'ext2',
|
|
||||||
common.docker_tar_dir,
|
|
||||||
common.docker_rootfs_raw_file,
|
|
||||||
])
|
|
||||||
common.raw_to_qcow2(prebuilt=True)
|
|
||||||
end_time = time.time()
|
|
||||||
common.print_time(end_time - start_time)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user