Skip to content

adding warning when default docker container is used on Windows #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cwltool/draft2tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@
_logger_validation_warnings, compute_checksums,
normalizeFilesDirs, shortname, uniquename)
from .stdfsaccess import StdFsAccess
from .utils import aslist, docker_windows_path_adjust, convert_pathsep_to_unix
from .utils import aslist, docker_windows_path_adjust, convert_pathsep_to_unix, windows_default_container_id, onWindows
from six.moves import map

ACCEPTLIST_EN_STRICT_RE = re.compile(r"^[a-zA-Z0-9._+-]+$")
ACCEPTLIST_EN_RELAXED_RE = re.compile(r".*") # Accept anything
ACCEPTLIST_RE = ACCEPTLIST_EN_STRICT_RE
DEFAULT_CONTAINER_MSG="""We are on Microsoft Windows and not all components of this CWL description have a
container specified. This means that these steps will be executed in the default container,
which is %s.

Note, this could affect portability if this CWL description relies on non-POSIX features
or commands in this container. For best results add the following to your CWL
description's hints section:

hints:
DockerRequirement:
dockerPull: %s
"""

_logger = logging.getLogger("cwltool")

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

if dockerReq and use_container:
return DockerCommandLineJob()
Expand Down
4 changes: 2 additions & 2 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from .software_requirements import DependenciesConfiguration, get_container_from_software_requirements, SOFTWARE_REQUIREMENTS_ENABLED
from .stdfsaccess import StdFsAccess
from .update import ALLUPDATES, UPDATES
from .utils import onWindows
from .utils import onWindows, windows_default_container_id
from ruamel.yaml.comments import Comment, CommentedSeq, CommentedMap


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

# If caller provided custom arguments, it may be not every expected
# option is set, so fill in no-op defaults to avoid crashing when
Expand Down
1 change: 1 addition & 0 deletions cwltool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from six.moves import zip_longest
from typing import Any,Callable, Dict, List, Tuple, Text, Union

windows_default_container_id = "frolvlad/alpine-bash"

def aslist(l): # type: (Any) -> List[Any]
if isinstance(l, list):
Expand Down
25 changes: 25 additions & 0 deletions tests/test_docker_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import absolute_import
import unittest
from mock import mock
from cwltool.utils import windows_default_container_id
from cwltool.draft2tool import DEFAULT_CONTAINER_MSG, CommandLineTool


class TestDefaultDockerWarning(unittest.TestCase):

# Test to check warning when default docker Container is used on Windows
@mock.patch("cwltool.draft2tool.onWindows",return_value = True)
@mock.patch("cwltool.draft2tool._logger")
def test_default_docker_warning(self,mock_logger,mock_windows):

class TestCommandLineTool(CommandLineTool):
def __init__(self, **kwargs):
self.requirements=[]
self.hints=[]

def find_default_container(args, builder):
return windows_default_container_id

TestObject = TestCommandLineTool()
TestObject.makeJobRunner()
mock_logger.warning.assert_called_with(DEFAULT_CONTAINER_MSG%(windows_default_container_id, windows_default_container_id))