set docker to use run for commands

This commit is contained in:
ronnyabraham 2020-03-23 23:42:34 +02:00
parent 7502ce06c4
commit 99893eafae

View file

@ -1,22 +1,28 @@
from fabric.api import env, task
from fabric.operations import run
from fabric.contrib.files import upload_template
from .utils import loggify, generate_template_files_path, booleanize
from .utils import generate_template_build_path, print_console
from .utils import executize
@task
def docker_ip():
configuration = env.config
_execute = executize("run")
# in the configuration file under docker,database, if host is set to local
# use docker-machine, because it means we are probably on OSX
#
# otherwise, if host is set to anything else (like the actual ip) then just
# return the host ip address that we set in configuration
if configuration.docker.database.host == 'local':
docker_cmd = 'docker-machine ip %s' % \
configuration.docker.machine
return run(docker_cmd)
return _execute(docker_cmd)
else:
return configuration.docker.database.host
@ -26,15 +32,27 @@ def docker_run(cmd):
from fabric.context_managers import prefix
configuration = env.config
# use executize to return either the methods sudo or run from
# fabric.operations
#
# we are checking to see if the host is local or not
# if it is local, that means OSX, which means the user can directly run any
# docker commands, but if it is remote, it probably requires sudo to run
# docker commands
_execute = executize("run")
if configuration.docker.database.host != 'local':
_execute = executize("sudo")
if configuration.docker.machine:
docker_eval = "eval $(docker-machine env %s)" % \
configuration.docker.machine
with prefix(docker_eval):
run(cmd)
_execute(cmd)
else:
run(cmd)
_execute(cmd)
@task
@ -161,6 +179,7 @@ under "docker"
if env.debug:
logger.debug("build_path : %s" % build_path)
logger.debug("dockercompose_cmd : %s" % dockercompose_cmd)
else:
docker_run(dockercompose_cmd)