This commit is contained in:
Disassembler 2018-09-06 09:41:40 +02:00
parent 6427a6ec09
commit 43c8962b0f
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499

View File

@ -49,10 +49,10 @@ class LXCImage:
if os.path.isfile(build_path): if os.path.isfile(build_path):
self.lxcfile = os.path.realpath(build_path) self.lxcfile = os.path.realpath(build_path)
self.build_context = os.path.dirname(lxcfile) self.build_dir = os.path.dirname(self.lxcfile)
else: else:
self.build_context = os.path.realpath(build_path) self.build_dir = os.path.realpath(build_path)
self.lxcfile = os.path.join(build_context, 'lxcfile') self.lxcfile = os.path.join(self.build_dir, 'lxcfile')
def build(self): def build(self):
with open(self.lxcfile, 'r') as fd: with open(self.lxcfile, 'r') as fd:
@ -89,12 +89,12 @@ class LXCImage:
self.add_layer('{}/delta0'.format(self.name)) self.add_layer('{}/delta0'.format(self.name))
def rebuild_config(self): def rebuild_config(self):
if len(layers) == 1: if len(self.layers) == 1:
rootfs_path = layers[0] rootfs_path = layers[0]
else: else:
# Multiple lower overlayfs layers are ordered from right to left (lower2:lower1:rootfs:upper) # Multiple lower overlayfs layers are ordered from right to left (lower2:lower1:rootfs:upper)
rootfs_path = 'overlay:{}:{}'.format(':'.join(layers[:-1][::-1], layers[-1])) rootfs_path = 'overlay:{}:{}'.format(':'.join(self.layers[:-1][::-1], self.layers[-1]))
mount_entries = '\n'.join(['lxc.mount.entry = {} none bind 0 0'.format(m) for m in mounts]) mount_entries = '\n'.join(['lxc.mount.entry = {} none bind 0 0'.format(m) for m in self.mounts])
with open(os.path.join(LXC_ROOT, self.name, 'config'), 'w') as fd: with open(os.path.join(LXC_ROOT, self.name, 'config'), 'w') as fd:
fd.write(CONFIG_TEMPLATE.format(name=self.name, rootfs=rootfs_path, mounts=mount_entries, uid=self.uid, gid=self.gid, cmd=self.cmd)) fd.write(CONFIG_TEMPLATE.format(name=self.name, rootfs=rootfs_path, mounts=mount_entries, uid=self.uid, gid=self.gid, cmd=self.cmd))
@ -118,7 +118,7 @@ class LXCImage:
self.rebuild_config() self.rebuild_config()
def copy_files(self, src, dst): def copy_files(self, src, dst):
src = os.path.join(build_context, src) src = os.path.join(build_dir, src)
dst = os.path.join(layers[-1], dst) dst = os.path.join(layers[-1], dst)
copy_tree(src, dst) copy_tree(src, dst)