From a1f640ce0a2ee33d1003c54543469abf10231385 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 20 Dec 2018 01:04:28 +0100 Subject: [PATCH] Added support for config include files to Docker images too --- platypush/platydock/__init__.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/platypush/platydock/__init__.py b/platypush/platydock/__init__.py index a39969a2..59d2e342 100755 --- a/platypush/platydock/__init__.py +++ b/platypush/platydock/__init__.py @@ -66,13 +66,25 @@ def generate_dockerfile(deps, ports, cfgfile, devdir): RUN mkdir -p /usr/local/share/platypush\n ''').lstrip() + srcdir = os.path.dirname(cfgfile) cfgfile_copy = os.path.join(devdir, 'config.yaml') - with open(cfgfile) as src_f: - with open(cfgfile_copy, 'w') as dest_f: - for line in src_f: - dest_f.write(line) + subprocess.call(['cp', cfgfile, cfgfile_copy]) + content += 'COPY config.yaml /etc/platypush/\n' + + for include in Config._included_files: + incdir = os.path.relpath(os.path.dirname(include), srcdir) + destdir = os.path.join(devdir, incdir) + + try: + os.makedirs(destdir) + except FileExistsError: + pass + + subprocess.call(['cp', include, destdir]) + content += 'RUN mkdir -p /etc/platypush/' + incdir + '\n' + content += 'COPY ' + os.path.relpath(include, srcdir) + \ + ' /etc/platypush/' + incdir + '\n' - content += 'COPY config.yaml /etc/platypush/' content += textwrap.dedent( '''