set docker to use run for commands
This commit is contained in:
parent
7502ce06c4
commit
99893eafae
1 changed files with 24 additions and 5 deletions
|
|
@ -1,22 +1,28 @@
|
||||||
from fabric.api import env, task
|
from fabric.api import env, task
|
||||||
|
|
||||||
from fabric.operations import run
|
|
||||||
|
|
||||||
from fabric.contrib.files import upload_template
|
from fabric.contrib.files import upload_template
|
||||||
|
|
||||||
from .utils import loggify, generate_template_files_path, booleanize
|
from .utils import loggify, generate_template_files_path, booleanize
|
||||||
from .utils import generate_template_build_path, print_console
|
from .utils import generate_template_build_path, print_console
|
||||||
|
from .utils import executize
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def docker_ip():
|
def docker_ip():
|
||||||
configuration = env.config
|
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':
|
if configuration.docker.database.host == 'local':
|
||||||
docker_cmd = 'docker-machine ip %s' % \
|
docker_cmd = 'docker-machine ip %s' % \
|
||||||
configuration.docker.machine
|
configuration.docker.machine
|
||||||
|
|
||||||
return run(docker_cmd)
|
return _execute(docker_cmd)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return configuration.docker.database.host
|
return configuration.docker.database.host
|
||||||
|
|
@ -26,15 +32,27 @@ def docker_run(cmd):
|
||||||
from fabric.context_managers import prefix
|
from fabric.context_managers import prefix
|
||||||
configuration = env.config
|
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:
|
if configuration.docker.machine:
|
||||||
docker_eval = "eval $(docker-machine env %s)" % \
|
docker_eval = "eval $(docker-machine env %s)" % \
|
||||||
configuration.docker.machine
|
configuration.docker.machine
|
||||||
|
|
||||||
with prefix(docker_eval):
|
with prefix(docker_eval):
|
||||||
run(cmd)
|
_execute(cmd)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
run(cmd)
|
_execute(cmd)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
|
|
@ -161,6 +179,7 @@ under "docker"
|
||||||
if env.debug:
|
if env.debug:
|
||||||
logger.debug("build_path : %s" % build_path)
|
logger.debug("build_path : %s" % build_path)
|
||||||
logger.debug("dockercompose_cmd : %s" % dockercompose_cmd)
|
logger.debug("dockercompose_cmd : %s" % dockercompose_cmd)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
docker_run(dockercompose_cmd)
|
docker_run(dockercompose_cmd)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue