diff --git a/basic-runtimes/alpine.lxcfile b/basic-runtimes/alpine.lxcfile index cddc190..5aba891 100644 --- a/basic-runtimes/alpine.lxcfile +++ b/basic-runtimes/alpine.lxcfile @@ -1,3 +1,4 @@ +IMAGE build LAYER shared/alpine SCRIPT diff --git a/basic-runtimes/java.lxcfile b/basic-runtimes/java.lxcfile index 3214421..bd83c79 100644 --- a/basic-runtimes/java.lxcfile +++ b/basic-runtimes/java.lxcfile @@ -1,3 +1,4 @@ +IMAGE build LAYER shared/alpine LAYER shared/java diff --git a/basic-runtimes/libxml.lxcfile b/basic-runtimes/libxml.lxcfile index 3fe2155..e92d22d 100644 --- a/basic-runtimes/libxml.lxcfile +++ b/basic-runtimes/libxml.lxcfile @@ -1,3 +1,4 @@ +IMAGE build LAYER shared/alpine LAYER shared/libxml diff --git a/basic-runtimes/nodejs.lxcfile b/basic-runtimes/nodejs.lxcfile new file mode 100644 index 0000000..3f66221 --- /dev/null +++ b/basic-runtimes/nodejs.lxcfile @@ -0,0 +1,7 @@ +IMAGE build +LAYER shared/alpine +LAYER shared/nodejs + +SCRIPT + apk --no-cache add nodejs +RUN diff --git a/basic-runtimes/php.lxcfile b/basic-runtimes/php.lxcfile index b663d4f..47158e4 100644 --- a/basic-runtimes/php.lxcfile +++ b/basic-runtimes/php.lxcfile @@ -1,3 +1,4 @@ +IMAGE build LAYER shared/alpine LAYER shared/php diff --git a/basic-runtimes/python2.lxcfile b/basic-runtimes/python2.lxcfile index d226748..443b885 100644 --- a/basic-runtimes/python2.lxcfile +++ b/basic-runtimes/python2.lxcfile @@ -1,3 +1,4 @@ +IMAGE build LAYER shared/alpine LAYER shared/libxml LAYER shared/python2 diff --git a/basic-runtimes/python3.lxcfile b/basic-runtimes/python3.lxcfile index b7c4094..66ee91d 100644 --- a/basic-runtimes/python3.lxcfile +++ b/basic-runtimes/python3.lxcfile @@ -1,3 +1,4 @@ +IMAGE build LAYER shared/alpine LAYER shared/libxml LAYER shared/python2 diff --git a/basic-runtimes/ruby.lxcfile b/basic-runtimes/ruby.lxcfile index 208d10e..9cdb62e 100644 --- a/basic-runtimes/ruby.lxcfile +++ b/basic-runtimes/ruby.lxcfile @@ -1,3 +1,4 @@ +IMAGE build LAYER shared/alpine LAYER shared/ruby diff --git a/basic-runtimes/tomcat.lxcfile b/basic-runtimes/tomcat.lxcfile index efa6738..49f0627 100644 --- a/basic-runtimes/tomcat.lxcfile +++ b/basic-runtimes/tomcat.lxcfile @@ -1,3 +1,4 @@ +IMAGE build LAYER shared/alpine LAYER shared/java LAYER shared/tomcat diff --git a/build-all.sh b/build-all.sh index ad26911..5e4666d 100755 --- a/build-all.sh +++ b/build-all.sh @@ -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 diff --git a/lxc-build b/lxc-build index 8b8b316..1a6de5f 100755 --- a/lxc-build +++ b/lxc-build @@ -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))