Skip to content

Commit

Permalink
Merge pull request #86 from Stratoscale/use_host_docker_client
Browse files Browse the repository at this point in the history
Use the host's docker client
  • Loading branch information
shay-stratoscale authored May 8, 2017
2 parents 1cc644b + be02488 commit 5286e47
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions skipper/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import subprocess
from contextlib import contextmanager

DOCKER_PATH_ON_HOST = subprocess.check_output('which docker', shell=True).strip()


def run(command, fqdn_image=None, environment=None, interactive=False, net='host', volumes=None, workdir=None):
if fqdn_image is not None:
Expand Down Expand Up @@ -55,6 +57,7 @@ def _run_nested(fqdn_image, environment, command, interactive, net='host', volum
'%(workspace)s:%(workspace)s:rw,Z' % dict(workspace=workspace),
'/var/lib/osmosis:/var/lib/osmosis:rw,Z' % dict(workspace=workspace),
'/var/run/docker.sock:/var/run/docker.sock:Z',
'{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST),
'/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z',
])
for volume in volumes:
Expand Down
23 changes: 14 additions & 9 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import mock
import os
import subprocess
import mock
import unittest
from skipper import runner

from skipper.runner import DOCKER_PATH_ON_HOST

USER_ID = 1000
GROUP_ID = 2000
Expand Down Expand Up @@ -63,13 +62,14 @@ def test_run_simple_command_nested_network_exist(self, check_output_mock, popen_
'-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR),
'-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z',
'-v', '/var/run/docker.sock:/var/run/docker.sock:Z',
'-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST),
'-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z',
'-w', PROJECT_DIR,
'--entrypoint', '/opt/skipper/skipper-entrypoint.sh',
FQDN_IMAGE,
command[0]
]
popen_mock.assert_called_once_with(expected_nested_command)
popen_mock.assert_called_with(expected_nested_command)

@mock.patch('getpass.getuser', autospec=True, return_value='testuser')
@mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR)
Expand Down Expand Up @@ -97,13 +97,14 @@ def test_run_simple_command_nested_network_not_exist(self, check_output_mock, po
'-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR),
'-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z',
'-v', '/var/run/docker.sock:/var/run/docker.sock:Z',
'-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST),
'-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z',
'-w', PROJECT_DIR,
'--entrypoint', '/opt/skipper/skipper-entrypoint.sh',
FQDN_IMAGE,
command[0]
]
popen_mock.assert_called_once_with(expected_nested_command)
popen_mock.assert_called_with(expected_nested_command)

@mock.patch('getpass.getuser', autospec=True, return_value='testuser')
@mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR)
Expand Down Expand Up @@ -133,13 +134,14 @@ def test_run_simple_command_nested_with_env(self, check_output_mock, popen_mock,
'-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR),
'-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z',
'-v', '/var/run/docker.sock:/var/run/docker.sock:Z',
'-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST),
'-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z',
'-w', PROJECT_DIR,
'--entrypoint', '/opt/skipper/skipper-entrypoint.sh',
FQDN_IMAGE,
command[0]
]
popen_mock.assert_called_once_with(expected_docker_command)
popen_mock.assert_called_with(expected_docker_command)

@mock.patch('getpass.getuser', autospec=True, return_value='testuser')
@mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR)
Expand Down Expand Up @@ -168,13 +170,14 @@ def test_run_simple_command_nested_interactive(self, check_output_mock, popen_mo
'-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR),
'-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z',
'-v', '/var/run/docker.sock:/var/run/docker.sock:Z',
'-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST),
'-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z',
'-w', PROJECT_DIR,
'--entrypoint', '/opt/skipper/skipper-entrypoint.sh',
FQDN_IMAGE,
command[0]
]
popen_mock.assert_called_once_with(expected_nested_command)
popen_mock.assert_called_with(expected_nested_command)

@mock.patch('getpass.getuser', autospec=True, return_value='testuser')
@mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR)
Expand Down Expand Up @@ -202,13 +205,14 @@ def test_run_complex_command_nested(self, check_output_mock, popen_mock, grp_get
'-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR),
'-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z',
'-v', '/var/run/docker.sock:/var/run/docker.sock:Z',
'-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST),
'-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z',
'-w', PROJECT_DIR,
'--entrypoint', '/opt/skipper/skipper-entrypoint.sh',
FQDN_IMAGE,
' '.join(command)
]
popen_mock.assert_called_once_with(expected_nested_command)
popen_mock.assert_called_with(expected_nested_command)

@mock.patch('getpass.getuser', autospec=True, return_value='testuser')
@mock.patch('os.getcwd', autospec=True, return_value=PROJECT_DIR)
Expand Down Expand Up @@ -238,10 +242,11 @@ def test_run_complex_command_nested_with_env(self, check_output_mock, popen_mock
'-v', '%(workdir)s:%(workdir)s:rw,Z' % dict(workdir=WORKDIR),
'-v', '/var/lib/osmosis:/var/lib/osmosis:rw,Z',
'-v', '/var/run/docker.sock:/var/run/docker.sock:Z',
'-v', '{docker_path_on_host}:/usr/bin/docker:ro'.format(docker_path_on_host=DOCKER_PATH_ON_HOST),
'-v', '/opt/skipper/skipper-entrypoint.sh:/opt/skipper/skipper-entrypoint.sh:Z',
'-w', PROJECT_DIR,
'--entrypoint', '/opt/skipper/skipper-entrypoint.sh',
FQDN_IMAGE,
' '.join(command)
]
popen_mock.assert_called_once_with(expected_nested_command)
popen_mock.assert_called_with(expected_nested_command)

0 comments on commit 5286e47

Please sign in to comment.