From 3e4182a48077bb4bd602b7a79622265234d7c518 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Tue, 1 Sep 2015 17:40:56 -0700 Subject: [PATCH 1/3] Stub 'run' on Windows Adapted from @dopry's work in https://github.com/docker/compose/pull/1900 Signed-off-by: Aanand Prasad --- compose/cli/main.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index 9b03ea676..0fc09efe6 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -8,7 +8,6 @@ import sys from inspect import getdoc from operator import attrgetter -import dockerpty from docker.errors import APIError from requests.exceptions import ReadTimeout @@ -31,6 +30,11 @@ from .log_printer import LogPrinter from .utils import get_version_info from .utils import yesno +WINDOWS = (sys.platform == 'win32') + +if not WINDOWS: + import dockerpty + log = logging.getLogger(__name__) console_handler = logging.StreamHandler(sys.stderr) @@ -335,6 +339,14 @@ class TopLevelCommand(Command): """ service = project.get_service(options['SERVICE']) + detach = options['-d'] + + if WINDOWS and not detach: + raise UserError( + "Interactive mode is not yet supported on Windows.\n" + "Please pass the -d flag when using `docker-compose run`." + ) + if options['--allow-insecure-ssl']: log.warn(INSECURE_SSL_WARNING) @@ -349,7 +361,7 @@ class TopLevelCommand(Command): ) tty = True - if options['-d'] or options['-T'] or not sys.stdin.isatty(): + if detach or options['-T'] or not sys.stdin.isatty(): tty = False if options['COMMAND']: @@ -360,8 +372,8 @@ class TopLevelCommand(Command): container_options = { 'command': command, 'tty': tty, - 'stdin_open': not options['-d'], - 'detach': options['-d'], + 'stdin_open': not detach, + 'detach': detach, } if options['-e']: @@ -407,7 +419,7 @@ class TopLevelCommand(Command): raise e - if options['-d']: + if detach: service.start_container(container) print(container.name) else: From 4ae7f00412e539b9643e83c3eba65718af703f96 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Tue, 1 Sep 2015 17:41:09 -0700 Subject: [PATCH 2/3] Build Windows binary Signed-off-by: Aanand Prasad --- script/build-windows.ps1 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 script/build-windows.ps1 diff --git a/script/build-windows.ps1 b/script/build-windows.ps1 new file mode 100644 index 000000000..284e44f35 --- /dev/null +++ b/script/build-windows.ps1 @@ -0,0 +1,24 @@ +$ErrorActionPreference = "Stop" +Set-PSDebug -trace 1 + +# Remove virtualenv +if (Test-Path venv) { + Remove-Item -Recurse -Force .\venv +} + +# Remove .pyc files +Get-ChildItem -Recurse -Include *.pyc | foreach ($_) { Remove-Item $_.FullName } + +# Create virtualenv +virtualenv .\venv + +# Install dependencies +.\venv\Scripts\easy_install "http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/pywin32-219.win32-py2.7.exe/download" +.\venv\Scripts\pip install -r requirements.txt +.\venv\Scripts\pip install -r requirements-build.txt +.\venv\Scripts\pip install . + +# Build binary +.\venv\Scripts\pyinstaller .\docker-compose.spec +Move-Item -Force .\dist\docker-compose .\dist\docker-compose-Windows-x86_64.exe +.\dist\docker-compose-Windows-x86_64.exe --version From fb304981536722ef42c9688b0688d4be048ccfd1 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Fri, 18 Sep 2015 17:37:09 +0100 Subject: [PATCH 3/3] Catch WindowsError in call_silently Signed-off-by: Aanand Prasad --- compose/cli/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compose/cli/utils.py b/compose/cli/utils.py index 0b7ac683d..26a38af06 100644 --- a/compose/cli/utils.py +++ b/compose/cli/utils.py @@ -85,7 +85,12 @@ def call_silently(*args, **kwargs): Like subprocess.call(), but redirects stdout and stderr to /dev/null. """ with open(os.devnull, 'w') as shutup: - return subprocess.call(*args, stdout=shutup, stderr=shutup, **kwargs) + try: + return subprocess.call(*args, stdout=shutup, stderr=shutup, **kwargs) + except WindowsError: + # On Windows, subprocess.call() can still raise exceptions. Normalize + # to POSIXy behaviour by returning a nonzero exit code. + return 1 def is_mac():