From 8a65b6a0f4241ef63bacc369ffaab1022cbfbc57 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Wed, 5 Sep 2018 21:21:07 +0200 Subject: [PATCH] copy_tree --- activemq/lxcfile | 2 +- basic-runtimes/tomcat.lxcfile | 2 +- ckan-datapusher/lxcfile | 2 +- ckan/lxcfile | 2 +- lxc-build | 20 +++++++++++++++----- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/activemq/lxcfile b/activemq/lxcfile index 877156f..1af566d 100644 --- a/activemq/lxcfile +++ b/activemq/lxcfile @@ -20,7 +20,7 @@ SCRIPT sed -i "s/-Xms64M -Xmx1G/-Xms32M -Xmx256M/" /srv/activemq/bin/env RUN -COPY lxc/ / +COPY lxc CMD /bin/s6-svscan /etc/services.d diff --git a/basic-runtimes/tomcat.lxcfile b/basic-runtimes/tomcat.lxcfile index 49f0627..c89300a 100644 --- a/basic-runtimes/tomcat.lxcfile +++ b/basic-runtimes/tomcat.lxcfile @@ -17,4 +17,4 @@ SCRIPT rm -f /tmp/apache-tomcat-8.tgz RUN -COPY lxc-tomcat/ / +COPY lxc-tomcat diff --git a/ckan-datapusher/lxcfile b/ckan-datapusher/lxcfile index b2d29ec..258a031 100644 --- a/ckan-datapusher/lxcfile +++ b/ckan-datapusher/lxcfile @@ -35,7 +35,7 @@ SCRIPT rm -rf /root/.cache RUN -COPY lxc/ / +COPY lxc VOLUME /etc/ssl/services.pem etc/ssl/services.pem VOLUME /srv/ckan-datapusher/conf etc/ckan-datapusher diff --git a/ckan/lxcfile b/ckan/lxcfile index 6856b4b..e53d817 100644 --- a/ckan/lxcfile +++ b/ckan/lxcfile @@ -47,7 +47,7 @@ SCRIPT rm -rf /root/.cache RUN -COPY lxc/ / +COPY lxc MOUNT /srv/ckan/conf etc/ckan MOUNT /srv/ckan/data srv/ckan/storage diff --git a/lxc-build b/lxc-build index 879d2fb..92d12ef 100755 --- a/lxc-build +++ b/lxc-build @@ -74,7 +74,7 @@ def fix_world(): world_items.extend(last_world) world_items = sorted(set(world_items)) if world_items != sorted(last_world): - os.makedirs(os.path.join(LXC_ROOT, layers[-1], 'etc/apk')) + os.makedirs(os.path.join(LXC_ROOT, layers[-1], 'etc/apk', 0o755, True)) with open(os.path.join(LXC_ROOT, layers[-1], 'etc/apk/world'), 'w') as fd: fd.writelines(world_items) @@ -86,10 +86,21 @@ def run_script(): subprocess.run(['lxc-execute', '-n', image, '--', '/bin/sh', '-lc', '/run.sh'], check=True) os.unlink(script_filename) +def copy_tree(src, dst): + if not os.path.isdir(src): + shutil.copy2(src, dst) + else: + os.makedirs(dst, exist_ok=True) + for name in os.listdir(src): + copy_tree(os.path.join(src, name), os.path.join(dst, name)) + shutil.copystat(src, dst) + def copy_files(src, dst): src = os.path.join(build_context, src) dst = os.path.join(LXC_ROOT, layers[-1], dst) - shutil.copytree(src, dst) + print('SRC: {}'.format(src)) + print('DST: {}'.format(dst)) + copy_tree(src, dst) with open(lxcfile, 'r') as fd: recipe = fd.readlines() @@ -100,8 +111,7 @@ for line in recipe: in_script = False run_script() elif in_script: - if line and not line.startswith('#'): - script.append(line) + script.append(line) elif line == 'SCRIPT': script = [] in_script = True @@ -115,7 +125,7 @@ for line in recipe: fix_world() elif line.startswith('COPY'): srcdst = line.split() - copy_files(srcdst[1], srcdst[2]) + copy_files(srcdst[1], srcdst[2] if len(srcdst) == 3 else '') elif line.startswith('MOUNT'): mounts.append(line.split()[1]) rebuild_config()