Added header and footer to generated Dockerfile.

This commit is contained in:
Fabio Manganiello 2023-08-20 14:05:22 +02:00
parent f66c4aa071
commit 700b8e1d16
Signed by: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -36,6 +36,31 @@ class DockerfileGenerator:
BaseImage.UBUNTU: PackageManagers.APT,
}
_header = textwrap.dedent(
"""
# This Dockerfile was automatically generated by Platydock.
#
# You can build a Platypush image from it by running
# `docker build -t platypush .` in the same folder as this file,
# or copy it to the root a Platypush source folder to install the
# checked out version instead of downloading it first.
#
# You can then run your new image through:
# docker run --rm --name platypush \\
# -v /path/to/your/config/dir:/etc/platypush \\
# -v /path/to/your/workdir:/var/lib/platypush \\
# -p 8080:8080 \\
# platypush\n
"""
)
_footer = textwrap.dedent(
"""
# You can customize the name of your installation by passing
# --device-id=... to the launched command.
"""
)
def __init__(self, cfgfile: str, image: BaseImage, gitref: str) -> None:
self.cfgfile = os.path.abspath(os.path.expanduser(cfgfile))
self.image = image
@ -72,6 +97,8 @@ class DockerfileGenerator:
with open(base_file, 'r') as f:
file_lines = [line.rstrip() for line in f.readlines()]
new_file_lines.extend(self._header.split('\n'))
for line in file_lines:
if re.match(
r'RUN /install/platypush/install/scripts/[A-Za-z0-9_-]+/install.sh',
@ -96,6 +123,8 @@ class DockerfileGenerator:
is_after_expose_cmd = True
continue
elif line.startswith('CMD'):
new_file_lines.extend(self._footer.split('\n'))
new_file_lines.append(line)