Skip to content

Commit

Permalink
Adding handling for multiple docker compose files
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkerz committed Feb 5, 2021
1 parent ed5a245 commit ad8dbfa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,44 @@ Use???
class Lookup:
def __init__(self,**entries):
self.__dict__.update(entries)






New text:

Are you sick of typing

python3.6 -m venv .venv
.venv\scripts\activate.bat | . .venv/bin/activate
pip install -r requirements.txt
python manage.py generate_swagger


Why not code this in an OS agnostic way:

python3.6 pie.py create_venv
python3.6 pie.py generate_swagger

key_values
# windows/linux aliases

or `pie create_venv`


# autocomplete


> pie configurable --my_string=with --params=3 next_task


pie_core:
cmd, env, py_venv

pie_docker
pie_docker_compose
pie_powershell
pie_ssh? - depends on binary package
20 changes: 15 additions & 5 deletions pie_docker_compose.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
"""
Python3.6+ only
"""
__VERSION__='0.0.2'
__VERSION__='0.0.3'


from pathlib import Path

from pie import *


def _path_or_list_to_list(s):
if isinstance(s,str) or isinstance(s,Path):
return [s]
elif isinstance(s,(list,tuple)):
return list(s)
return []


def _make_list_parameter_safe(ls):
return list(ls) if ls is not None else []


class DockerCompose:
def __init__(self,docker_compose_filename,project_name=None):
self.docker_compose_filename=docker_compose_filename
def __init__(self,docker_compose_filenames=None,project_name=None):
self.docker_compose_filenames=_path_or_list_to_list(docker_compose_filenames)
self.project_name=project_name


def cmd(self,compose_cmd,compose_options=None,options=None):
"""
Builds a command and runs it like this:
docker-compose -f <self.docker_compose_filename> [-p <self.project_name>] <compose_options> <compose_cmd> <cmd_options>
docker-compose -f <self.docker_compose_filenames...> [-p <self.project_name>] <compose_options> <compose_cmd> <cmd_options>
"""
compose_options=_make_list_parameter_safe(compose_options)
options=_make_list_parameter_safe(options)
c_ops=[f'-f {self.docker_compose_filename}']
c_ops=[f'-f {fn}' for fn in self.docker_compose_filenames]
if self.project_name:
c_ops.append(f'-p {self.project_name}')
c_ops.extend(compose_options)
Expand Down

0 comments on commit ad8dbfa

Please sign in to comment.