Skip to content
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

Use the host's docker client #86

Merged
merged 1 commit into from
May 8, 2017
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
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)