forked from platypush/platypush
Refactor/documentation round for platydock.
This commit is contained in:
parent
10c0e5fcad
commit
ce68250b4d
1 changed files with 74 additions and 64 deletions
|
@ -10,7 +10,7 @@ import pathlib
|
|||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
from typing import Iterable
|
||||
from typing import Iterable, Sequence
|
||||
|
||||
from platypush.config import Config
|
||||
from platypush.utils.manifest import (
|
||||
|
@ -70,7 +70,6 @@ class DockerfileGenerator:
|
|||
"""
|
||||
Generate a Dockerfile based on a configuration file.
|
||||
|
||||
:param cfgfile: Path to the configuration file.
|
||||
:return: The content of the generated Dockerfile.
|
||||
"""
|
||||
import platypush
|
||||
|
@ -131,6 +130,11 @@ class DockerfileGenerator:
|
|||
return '\n'.join(new_file_lines)
|
||||
|
||||
def _generate_git_clone_command(self) -> str:
|
||||
"""
|
||||
Generates a git clone command in Dockerfile that checks out the repo
|
||||
and the right git reference, if the application sources aren't already
|
||||
available under /install.
|
||||
"""
|
||||
pkg_manager = self._pkg_manager_by_base_image[self.image]
|
||||
install_cmd = ' '.join(pkg_manager.value.install)
|
||||
uninstall_cmd = ' '.join(pkg_manager.value.uninstall)
|
||||
|
@ -148,26 +152,13 @@ class DockerfileGenerator:
|
|||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _get_exposed_ports() -> Iterable[int]:
|
||||
@classmethod
|
||||
def from_cmdline(cls, args: Sequence[str]) -> 'DockerfileGenerator':
|
||||
"""
|
||||
:return: The listen ports used by the backends enabled in the configuration
|
||||
file.
|
||||
"""
|
||||
backends_config = Config.get_backends()
|
||||
return {
|
||||
int(port)
|
||||
for port in (
|
||||
backends_config.get('http', {}).get('port'),
|
||||
backends_config.get('tcp', {}).get('port'),
|
||||
)
|
||||
if port
|
||||
}
|
||||
Create a DockerfileGenerator instance from command line arguments.
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Generates a Dockerfile based on the configuration file.
|
||||
:param args: Command line arguments.
|
||||
:return: A DockerfileGenerator instance.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='platydock',
|
||||
|
@ -210,10 +201,10 @@ def main():
|
|||
'option which branch, tag or commit hash to use. Defaults to master.',
|
||||
)
|
||||
|
||||
opts, _ = parser.parse_known_args(sys.argv[1:])
|
||||
opts, _ = parser.parse_known_args(args)
|
||||
if opts.show_usage:
|
||||
parser.print_help()
|
||||
return 0
|
||||
sys.exit(0)
|
||||
|
||||
if not opts.cfgfile:
|
||||
opts.cfgfile = os.path.join(
|
||||
|
@ -226,11 +217,30 @@ def main():
|
|||
file=sys.stderr,
|
||||
)
|
||||
|
||||
dockerfile = DockerfileGenerator(
|
||||
opts.cfgfile, image=opts.image, gitref=opts.gitref
|
||||
).generate()
|
||||
return cls(opts.cfgfile, image=opts.image, gitref=opts.gitref)
|
||||
|
||||
print(dockerfile)
|
||||
@staticmethod
|
||||
def _get_exposed_ports() -> Iterable[int]:
|
||||
"""
|
||||
:return: The listen ports used by the backends enabled in the configuration
|
||||
file.
|
||||
"""
|
||||
backends_config = Config.get_backends()
|
||||
return {
|
||||
int(port)
|
||||
for port in (
|
||||
backends_config.get('http', {}).get('port'),
|
||||
backends_config.get('tcp', {}).get('port'),
|
||||
)
|
||||
if port
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Generates a Dockerfile based on the configuration file.
|
||||
"""
|
||||
print(DockerfileGenerator.from_cmdline(sys.argv[1:]).generate())
|
||||
return 0
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue