Skip to content

Commit

Permalink
Adding beta docker related modules
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkerz committed May 25, 2020
1 parent 2ad9233 commit 15c20df
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pie_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Python3.6+ only
"""
from pie import *



class Docker:
def __init__(self,options=[]):
self.options=options

def build(self,context,options=[]):
self.cmd('build',options+[context])

def run(self,image,cmd_and_args=None,options=[]):
ops=list(options)
ops.append(image)
if cmd_and_args:
ops.append(cmd_and_args)
self.cmd('run',ops)

def cmd(self,docker_cmd,cmd_options=[]):
docker_options_str=' '.join(self.options)
cmd_options_str=' '.join(cmd_options)
c=f'docker {docker_options_str} {docker_cmd} {cmd_options_str}'
print(c)
cmd(c)
41 changes: 41 additions & 0 deletions pie_docker_compose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Python3.6+ only
"""
from pie import *


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

def cmd(self, compose_cmd, compose_options=[], options=[]):
cops = [f'-f {self.docker_compose_filename}']
if self.project_name:
cops.append(f'-p {self.project_name}')
cops.extend(compose_options)
compose_options_str = ' '.join(cops)
options_str = ' '.join(options)
c = f'docker-compose {compose_options_str} {compose_cmd} {options_str}'
# --no-ansi
print(c)
cmd(c)

def service(self, service_name):
return DockerComposeService(self, service_name)

@classmethod
def set_ignore_orphans_env_variable(cls, value):
"""If you use multiple docker compose files in the same project, docker compose thinks that some services have been orphaned, but really it's just that docker compose doesn't know about the other docker compose files"""
env.set('COMPOSE_IGNORE_ORPHANS', 'True' if value else 'False')


class DockerComposeService:
def __init__(self, compose_obj, service_name):
self.compose_obj = compose_obj
self.service_name = service_name

def cmd(self, compose_cmd, compose_options=[], options=[], container_cmd=''):
options_ext = list(options)
options_ext.extend([self.service_name, container_cmd])
self.compose_obj.cmd(compose_cmd, compose_options, options_ext)

0 comments on commit 15c20df

Please sign in to comment.