diff --git a/crisiscleanup/lxcfile b/crisiscleanup/lxcfile index e00c3dd..b6f48ec 100644 --- a/crisiscleanup/lxcfile +++ b/crisiscleanup/lxcfile @@ -1,9 +1,11 @@ +IMAGE crisiscleanup LAYER shared/alpine LAYER shared/ruby LAYER shared/nodejs LAYER shared/libxml +LAYER crisiscleanup/crisiscleanup -LAYERFIX /usr/bin/fix-apk +FIXLAYER /usr/bin/fix-apk ENV RAILS_ENV production diff --git a/zz-extra/fix-apk b/zz-extra/fix-apk old mode 100644 new mode 100755 index 1092e7b..992f8b5 --- a/zz-extra/fix-apk +++ b/zz-extra/fix-apk @@ -6,29 +6,35 @@ import sys def fix_installed(layers): installed = [] for layer in layers[:-1]: - with open(os.path.join(layer, 'lib/apk/db/installed'), 'r') as fd: - buffer = [] - for line in df: - if line.startswith('C:'): - buffer = ''.join(buffer) - if buffer not in installed: - installed.append(buffer) - buffer = [] - buffer.append(line) - os.makedirs(os.path.join(layers[-1], 'lib/apk/db', 0o755, True)) - with open(os.path.join(layers[-1], 'lib/apk/db/installed'), 'w') as fd: - fd.writelines(world_items) + try: + with open(os.path.join(layer, 'lib/apk/db/installed'), 'r') as fd: + buffer = [] + for line in fd: + if line.startswith('C:'): + buffer = ''.join(buffer) + if buffer not in installed: + installed.append(buffer) + buffer = [] + buffer.append(line) + except: + continue + os.makedirs(os.path.join(layers[-1], 'lib/apk/db'), 0o755, True) + with open(os.path.join(layers[-1], 'lib/apk/db/installed'), 'w') as fd: + fd.writelines(installed) def fix_world(layers): world = [] for layer in layers[:-1]: - with open(os.path.join(layer, 'etc/apk/world'), 'r') as fd: - for line in fd: - if line in world: - world.append(world) - os.makedirs(os.path.join(layers[-1], 'etc/apk', 0o755, True)) - with open(os.path.join(layers[-1], 'etc/apk/world'), 'w') as fd: - fd.writelines(world_items) + try: + with open(os.path.join(layer, 'etc/apk/world'), 'r') as fd: + for line in fd: + if line not in world: + world.append(world) + except: + continue + os.makedirs(os.path.join(layers[-1], 'etc/apk'), 0o755, True) + with open(os.path.join(layers[-1], 'etc/apk/world'), 'w') as fd: + fd.writelines(world) -fix_installed(sys.argv) -fix_world(sys.argv) +fix_installed(sys.argv[1:]) +fix_world(sys.argv[1:]) diff --git a/zz-extra/lxc-build b/zz-extra/lxc-build index 50d2315..a3f0235 100755 --- a/zz-extra/lxc-build +++ b/zz-extra/lxc-build @@ -86,14 +86,14 @@ class LXCImage: self.set_name(line.split()[1]) elif line.startswith('LAYER'): self.add_layer(line.split()[1]) - elif line.startswith('LAYERFIX'): - self.fix_layers(line.split()[1]) + elif line.startswith('FIXLAYER'): + self.fix_layer(line.split()[1]) elif line.startswith('COPY'): srcdst = line.split() self.copy_files(srcdst[1], srcdst[2] if len(srcdst) == 3 else '') elif line.startswith('MOUNT'): - srcdst = line.split() - self.add_mount(srcdst[1], srcdst[2]) + mount = line.split() + self.add_mount(mount[1], mount[2]) elif line.startswith('ENV'): env = line.split() self.add_env(env[1], env[2]) @@ -109,14 +109,14 @@ class LXCImage: def rebuild_config(self): if len(self.layers) == 1: - rootfs_path = self.layers[0] + rootfs = self.layers[0] else: # Multiple lower overlayfs layers are ordered from right to left (lower2:lower1:rootfs:upper) - 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 self.mounts]) - env_entries = '\n'.join(['lxc.environment = {}'.format(e) for e in self.env]) + rootfs = 'overlay:{}:{}'.format(':'.join(self.layers[:-1][::-1]), self.layers[-1]) + mounts = '\n'.join(self.mounts) + env = '\n'.join(self.env) 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, env=env_entries, uid=self.uid, gid=self.gid, cmd=self.cmd, cwd=self.cwd)) + fd.write(CONFIG_TEMPLATE.format(name=self.name, rootfs=rootfs, mounts=mounts, env=env, uid=self.uid, gid=self.gid, cmd=self.cmd, cwd=self.cwd)) def run_script(self, script): sh = os.path.join(self.layers[-1], 'run.sh') @@ -136,7 +136,7 @@ class LXCImage: os.makedirs(layer, 0o755, True) self.rebuild_config() - def fix_layers(self, cmd): + def fix_layer(self, cmd): subprocess.run([cmd]+self.layers, check=True) def copy_files(self, src, dst): @@ -145,11 +145,11 @@ class LXCImage: copy_tree(src, dst) def add_mount(self, src, dst): - self.mounts.append('{} {}'.format(src, dst)) + self.mounts.append('lxc.mount.entry = {} {} none bind 0 0'.format(src, dst)) self.rebuild_config() def add_env(self, key, value): - self.env.append('{}={}'.format(key, value)) + self.env.append('lxc.environment = {}={}'.format(key, value)) self.rebuild_config() def set_user(self, uid, gid):