Skip to content

Commit da4930f

Browse files
authored
Merge pull request #492 from kapilkd13/defaultcontainerWarning
adding warning when default docker container is used on Windows
2 parents c67f57e + 94c872a commit da4930f

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

cwltool/draft2tool.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@
2828
_logger_validation_warnings, compute_checksums,
2929
normalizeFilesDirs, shortname, uniquename)
3030
from .stdfsaccess import StdFsAccess
31-
from .utils import aslist, docker_windows_path_adjust, convert_pathsep_to_unix
31+
from .utils import aslist, docker_windows_path_adjust, convert_pathsep_to_unix, windows_default_container_id, onWindows
3232
from six.moves import map
3333

3434
ACCEPTLIST_EN_STRICT_RE = re.compile(r"^[a-zA-Z0-9._+-]+$")
3535
ACCEPTLIST_EN_RELAXED_RE = re.compile(r".*") # Accept anything
3636
ACCEPTLIST_RE = ACCEPTLIST_EN_STRICT_RE
37+
DEFAULT_CONTAINER_MSG="""We are on Microsoft Windows and not all components of this CWL description have a
38+
container specified. This means that these steps will be executed in the default container,
39+
which is %s.
3740
41+
Note, this could affect portability if this CWL description relies on non-POSIX features
42+
or commands in this container. For best results add the following to your CWL
43+
description's hints section:
44+
45+
hints:
46+
DockerRequirement:
47+
dockerPull: %s
48+
"""
3849

3950
_logger = logging.getLogger("cwltool")
4051

@@ -190,6 +201,8 @@ def makeJobRunner(self, use_container=True): # type: (Optional[bool]) -> JobBas
190201
"dockerPull": default_container
191202
})
192203
dockerReq = self.requirements[0]
204+
if default_container == windows_default_container_id and use_container and onWindows():
205+
_logger.warning(DEFAULT_CONTAINER_MSG%(windows_default_container_id, windows_default_container_id))
193206

194207
if dockerReq and use_container:
195208
return DockerCommandLineJob()

cwltool/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from .software_requirements import DependenciesConfiguration, get_container_from_software_requirements, SOFTWARE_REQUIREMENTS_ENABLED
4040
from .stdfsaccess import StdFsAccess
4141
from .update import ALLUPDATES, UPDATES
42-
from .utils import onWindows
42+
from .utils import onWindows, windows_default_container_id
4343
from ruamel.yaml.comments import Comment, CommentedSeq, CommentedMap
4444

4545

@@ -712,7 +712,7 @@ def main(argsl=None, # type: List[str]
712712
# If On windows platform, A default Docker Container is Used if not explicitely provided by user
713713
if onWindows() and not args.default_container:
714714
# This docker image is a minimal alpine image with bash installed(size 6 mb). source: https://github.com/frol/docker-alpine-bash
715-
args.default_container = "frolvlad/alpine-bash"
715+
args.default_container = windows_default_container_id
716716

717717
# If caller provided custom arguments, it may be not every expected
718718
# option is set, so fill in no-op defaults to avoid crashing when

cwltool/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from six.moves import zip_longest
1111
from typing import Any,Callable, Dict, List, Tuple, Text, Union
1212

13+
windows_default_container_id = "frolvlad/alpine-bash"
1314

1415
def aslist(l): # type: (Any) -> List[Any]
1516
if isinstance(l, list):

tests/test_docker_warning.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import absolute_import
2+
import unittest
3+
from mock import mock
4+
from cwltool.utils import windows_default_container_id
5+
from cwltool.draft2tool import DEFAULT_CONTAINER_MSG, CommandLineTool
6+
7+
8+
class TestDefaultDockerWarning(unittest.TestCase):
9+
10+
# Test to check warning when default docker Container is used on Windows
11+
@mock.patch("cwltool.draft2tool.onWindows",return_value = True)
12+
@mock.patch("cwltool.draft2tool._logger")
13+
def test_default_docker_warning(self,mock_logger,mock_windows):
14+
15+
class TestCommandLineTool(CommandLineTool):
16+
def __init__(self, **kwargs):
17+
self.requirements=[]
18+
self.hints=[]
19+
20+
def find_default_container(args, builder):
21+
return windows_default_container_id
22+
23+
TestObject = TestCommandLineTool()
24+
TestObject.makeJobRunner()
25+
mock_logger.warning.assert_called_with(DEFAULT_CONTAINER_MSG%(windows_default_container_id, windows_default_container_id))

0 commit comments

Comments
 (0)