fixlayer
This commit is contained in:
parent
c7c949eead
commit
344b6be624
@ -1,9 +1,11 @@
|
|||||||
|
IMAGE crisiscleanup
|
||||||
LAYER shared/alpine
|
LAYER shared/alpine
|
||||||
LAYER shared/ruby
|
LAYER shared/ruby
|
||||||
LAYER shared/nodejs
|
LAYER shared/nodejs
|
||||||
LAYER shared/libxml
|
LAYER shared/libxml
|
||||||
|
LAYER crisiscleanup/crisiscleanup
|
||||||
|
|
||||||
LAYERFIX /usr/bin/fix-apk
|
FIXLAYER /usr/bin/fix-apk
|
||||||
|
|
||||||
ENV RAILS_ENV production
|
ENV RAILS_ENV production
|
||||||
|
|
||||||
|
48
zz-extra/fix-apk
Normal file → Executable file
48
zz-extra/fix-apk
Normal file → Executable file
@ -6,29 +6,35 @@ import sys
|
|||||||
def fix_installed(layers):
|
def fix_installed(layers):
|
||||||
installed = []
|
installed = []
|
||||||
for layer in layers[:-1]:
|
for layer in layers[:-1]:
|
||||||
with open(os.path.join(layer, 'lib/apk/db/installed'), 'r') as fd:
|
try:
|
||||||
buffer = []
|
with open(os.path.join(layer, 'lib/apk/db/installed'), 'r') as fd:
|
||||||
for line in df:
|
buffer = []
|
||||||
if line.startswith('C:'):
|
for line in fd:
|
||||||
buffer = ''.join(buffer)
|
if line.startswith('C:'):
|
||||||
if buffer not in installed:
|
buffer = ''.join(buffer)
|
||||||
installed.append(buffer)
|
if buffer not in installed:
|
||||||
buffer = []
|
installed.append(buffer)
|
||||||
buffer.append(line)
|
buffer = []
|
||||||
os.makedirs(os.path.join(layers[-1], 'lib/apk/db', 0o755, True))
|
buffer.append(line)
|
||||||
with open(os.path.join(layers[-1], 'lib/apk/db/installed'), 'w') as fd:
|
except:
|
||||||
fd.writelines(world_items)
|
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):
|
def fix_world(layers):
|
||||||
world = []
|
world = []
|
||||||
for layer in layers[:-1]:
|
for layer in layers[:-1]:
|
||||||
with open(os.path.join(layer, 'etc/apk/world'), 'r') as fd:
|
try:
|
||||||
for line in fd:
|
with open(os.path.join(layer, 'etc/apk/world'), 'r') as fd:
|
||||||
if line in world:
|
for line in fd:
|
||||||
world.append(world)
|
if line not in world:
|
||||||
os.makedirs(os.path.join(layers[-1], 'etc/apk', 0o755, True))
|
world.append(world)
|
||||||
with open(os.path.join(layers[-1], 'etc/apk/world'), 'w') as fd:
|
except:
|
||||||
fd.writelines(world_items)
|
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_installed(sys.argv[1:])
|
||||||
fix_world(sys.argv)
|
fix_world(sys.argv[1:])
|
||||||
|
@ -86,14 +86,14 @@ class LXCImage:
|
|||||||
self.set_name(line.split()[1])
|
self.set_name(line.split()[1])
|
||||||
elif line.startswith('LAYER'):
|
elif line.startswith('LAYER'):
|
||||||
self.add_layer(line.split()[1])
|
self.add_layer(line.split()[1])
|
||||||
elif line.startswith('LAYERFIX'):
|
elif line.startswith('FIXLAYER'):
|
||||||
self.fix_layers(line.split()[1])
|
self.fix_layer(line.split()[1])
|
||||||
elif line.startswith('COPY'):
|
elif line.startswith('COPY'):
|
||||||
srcdst = line.split()
|
srcdst = line.split()
|
||||||
self.copy_files(srcdst[1], srcdst[2] if len(srcdst) == 3 else '')
|
self.copy_files(srcdst[1], srcdst[2] if len(srcdst) == 3 else '')
|
||||||
elif line.startswith('MOUNT'):
|
elif line.startswith('MOUNT'):
|
||||||
srcdst = line.split()
|
mount = line.split()
|
||||||
self.add_mount(srcdst[1], srcdst[2])
|
self.add_mount(mount[1], mount[2])
|
||||||
elif line.startswith('ENV'):
|
elif line.startswith('ENV'):
|
||||||
env = line.split()
|
env = line.split()
|
||||||
self.add_env(env[1], env[2])
|
self.add_env(env[1], env[2])
|
||||||
@ -109,14 +109,14 @@ class LXCImage:
|
|||||||
|
|
||||||
def rebuild_config(self):
|
def rebuild_config(self):
|
||||||
if len(self.layers) == 1:
|
if len(self.layers) == 1:
|
||||||
rootfs_path = self.layers[0]
|
rootfs = self.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(self.layers[:-1][::-1]), self.layers[-1])
|
rootfs = '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])
|
mounts = '\n'.join(self.mounts)
|
||||||
env_entries = '\n'.join(['lxc.environment = {}'.format(e) for e in self.env])
|
env = '\n'.join(self.env)
|
||||||
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, 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):
|
def run_script(self, script):
|
||||||
sh = os.path.join(self.layers[-1], 'run.sh')
|
sh = os.path.join(self.layers[-1], 'run.sh')
|
||||||
@ -136,7 +136,7 @@ class LXCImage:
|
|||||||
os.makedirs(layer, 0o755, True)
|
os.makedirs(layer, 0o755, True)
|
||||||
self.rebuild_config()
|
self.rebuild_config()
|
||||||
|
|
||||||
def fix_layers(self, cmd):
|
def fix_layer(self, cmd):
|
||||||
subprocess.run([cmd]+self.layers, check=True)
|
subprocess.run([cmd]+self.layers, check=True)
|
||||||
|
|
||||||
def copy_files(self, src, dst):
|
def copy_files(self, src, dst):
|
||||||
@ -145,11 +145,11 @@ class LXCImage:
|
|||||||
copy_tree(src, dst)
|
copy_tree(src, dst)
|
||||||
|
|
||||||
def add_mount(self, 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()
|
self.rebuild_config()
|
||||||
|
|
||||||
def add_env(self, key, value):
|
def add_env(self, key, value):
|
||||||
self.env.append('{}={}'.format(key, value))
|
self.env.append('lxc.environment = {}={}'.format(key, value))
|
||||||
self.rebuild_config()
|
self.rebuild_config()
|
||||||
|
|
||||||
def set_user(self, uid, gid):
|
def set_user(self, uid, gid):
|
||||||
|
Loading…
Reference in New Issue
Block a user