Some lxc-build fixes

This commit is contained in:
Disassembler 2018-09-05 18:25:27 +02:00
parent 26075bad79
commit 1608b7a93f
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
11 changed files with 62 additions and 49 deletions

View File

@ -1,3 +1,4 @@
IMAGE build
LAYER shared/alpine
SCRIPT

View File

@ -1,3 +1,4 @@
IMAGE build
LAYER shared/alpine
LAYER shared/java

View File

@ -1,3 +1,4 @@
IMAGE build
LAYER shared/alpine
LAYER shared/libxml

View File

@ -0,0 +1,7 @@
IMAGE build
LAYER shared/alpine
LAYER shared/nodejs
SCRIPT
apk --no-cache add nodejs
RUN

View File

@ -1,3 +1,4 @@
IMAGE build
LAYER shared/alpine
LAYER shared/php

View File

@ -1,3 +1,4 @@
IMAGE build
LAYER shared/alpine
LAYER shared/libxml
LAYER shared/python2

View File

@ -1,3 +1,4 @@
IMAGE build
LAYER shared/alpine
LAYER shared/libxml
LAYER shared/python2

View File

@ -1,3 +1,4 @@
IMAGE build
LAYER shared/alpine
LAYER shared/ruby

View File

@ -1,3 +1,4 @@
IMAGE build
LAYER shared/alpine
LAYER shared/java
LAYER shared/tomcat

View File

@ -3,8 +3,8 @@ set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))
# Copy lxc-build
cp ${SOURCE_DIR}/lxc-build /usr/bin/lxc-build
# Alias lxc-build
alias lxc-build=${SOURCE_DIR}/lxc-build
# Build basic Alpine LXC image
mkdir -p /var/lib/lxc/shared/alpine
@ -12,12 +12,13 @@ wget https://github.com/gliderlabs/docker-alpine/raw/2bfe6510ee31d86cfeb2f37587f
touch /var/lib/lxc/shared/alpine/etc/resolv.conf
lxc-build ${SOURCE_DIR}/basic-runtimes/alpine.lxcfile
# Build runtime overlays
# Build shared overlays
lxc-build ${SOURCE_DIR}/basic-runtimes/java.lxcfile
lxc-build ${SOURCE_DIR}/basic-runtimes/libxml.lxcfile
#lxc-build ${SOURCE_DIR}/basic-runtimes/php.lxcfile
lxc-build ${SOURCE_DIR}/basic-runtimes/python2.lxcfile
lxc-build ${SOURCE_DIR}/basic-runtimes/python3.lxcfile
#lxc-build ${SOURCE_DIR}/basic-runtimes/nodejs.lxcfile
#lxc-build ${SOURCE_DIR}/basic-runtimes/ruby.lxcfile
#lxc-build ${SOURCE_DIR}/basic-runtimes/tomcat.lxcfile

View File

@ -5,15 +5,6 @@ import shutil
import subprocess
import sys
image = 'build'
layers = []
mounts = []
uid = 0
gid = 0
cmd = '/bin/sh'
script = []
in_script = False
LXC_ROOT = '/var/lib/lxc'
CONFIG_TEMPLATE = '''# Image name
lxc.uts.name = {image}
@ -46,47 +37,22 @@ lxc.cap.drop = sys_admin
lxc.include = /usr/share/lxc/config/alpine.common.conf
'''
image = None
layers = []
mounts = []
uid = 0
gid = 0
cmd = '/bin/sh'
script = []
in_script = False
if os.path.isfile(sys.argv[1]):
lxcfile = os.path.realpath(sys.argv[1])
build_context = os.path.basepath(lxcfile)
build_context = os.path.dirname(lxcfile)
else:
build_context = os.path.realpath(sys.argv[1])
lxcfile = os.path.join(build_context, 'lxcfile')
def main():
with open(lxcfile, 'r') as fd:
recipe = fd.readlines()
for line in recipe:
if line == 'RUN':
in_script = False
run_script()
elif in_script and not line and not line.startswith('#'):
script.append()
elif line == 'SCRIPT':
script = []
in_script = True
elif line.startswith('IMAGE'):
image = line.split()[1]
os.makedirs(os.path.join(LXC_ROOT, image), 0o755, True)
elif line.startswith('LAYER'):
layers.append(line.split()[1])
rebuild_config()
fix_world()
elif line.startswith('COPY'):
copy_files(*line.split()[1:2])
elif line.startswith('MOUNT'):
mounts.append(line.split()[1])
rebuild_config()
elif line.startswith('USER'):
uid = line.split()[1]
gid = line.split()[2]
rebuild_config()
elif line.startswith('CMD'):
cmd = line.split()[1]
rebuild_config()
layers.append('{}/delta0'.format(image))
def rebuild_config():
rootfs_layers = [os.path.join(LXC_ROOT, l) for l in layers]
for layer in rootfs_layers:
@ -125,5 +91,36 @@ def copy_files(src, dst):
dst = os.path.join(LXC_ROOT, layers[-1], dst)
shutil.copytree(src, dst)
if __name__ == '__init__':
main()
with open(lxcfile, 'r') as fd:
recipe = fd.readlines()
for line in recipe:
if line == 'RUN':
in_script = False
run_script()
elif in_script and not line and not line.startswith('#'):
script.append()
elif line == 'SCRIPT':
script = []
in_script = True
elif line.startswith('IMAGE'):
image = line.split()[1]
os.makedirs(os.path.join(LXC_ROOT, image), 0o755, True)
elif line.startswith('LAYER'):
layers.append(line.split()[1])
rebuild_config()
elif line == 'FIXWORLD':
fix_world()
elif line.startswith('COPY'):
copy_files(*line.split()[1:2])
elif line.startswith('MOUNT'):
mounts.append(line.split()[1])
rebuild_config()
elif line.startswith('USER'):
uid = line.split()[1]
gid = line.split()[2]
rebuild_config()
elif line.startswith('CMD'):
cmd = line.split()[1]
rebuild_config()
layers.append('{}/delta0'.format(image))