Unverified Commit 5a93ed49 authored by Yifan Xiong's avatar Yifan Xiong Committed by GitHub
Browse files

Support `sb deploy` without pulling image (#466)

Support `--no-image-pull` in `sb deploy` to skip image pull to use local
cached images.
parent a55002de
...@@ -97,6 +97,7 @@ sb deploy [--docker-image] ...@@ -97,6 +97,7 @@ sb deploy [--docker-image]
[--host-list] [--host-list]
[--host-password] [--host-password]
[--host-username] [--host-username]
[--no-image-pull]
[--output-dir] [--output-dir]
[--private-key] [--private-key]
``` ```
...@@ -112,6 +113,7 @@ sb deploy [--docker-image] ...@@ -112,6 +113,7 @@ sb deploy [--docker-image]
| `--host-list` `-l` | `None` | Comma separated host list. | | `--host-list` `-l` | `None` | Comma separated host list. |
| `--host-password` | `None` | Host password or key passphase if needed. | | `--host-password` | `None` | Host password or key passphase if needed. |
| `--host-username` | `None` | Host username if needed. | | `--host-username` | `None` | Host username if needed. |
| `--no-image-pull` | `False` | Skip pull and use local Docker image. |
| `--output-dir` | `None` | Path to output directory, outputs/{datetime} will be used if not specified. | | `--output-dir` | `None` | Path to output directory, outputs/{datetime} will be used if not specified. |
| `--private-key` | `None` | Path to private key if needed. | | `--private-key` | `None` | Path to private key if needed. |
......
...@@ -44,6 +44,7 @@ def load_arguments(self, command): ...@@ -44,6 +44,7 @@ def load_arguments(self, command):
ac.argument('docker_username', type=str, help='Docker registry username if authentication is needed.') ac.argument('docker_username', type=str, help='Docker registry username if authentication is needed.')
ac.argument('docker_password', type=str, help='Docker registry password if authentication is needed.') ac.argument('docker_password', type=str, help='Docker registry password if authentication is needed.')
ac.argument('no_docker', action='store_true', help='Run on host directly without Docker.') ac.argument('no_docker', action='store_true', help='Run on host directly without Docker.')
ac.argument('no_image_pull', action='store_true', help='Skip pull and use local Docker image.')
ac.argument( ac.argument(
'host_file', options_list=('--host-file', '-f'), type=str, help='Path to Ansible inventory host file.' 'host_file', options_list=('--host-file', '-f'), type=str, help='Path to Ansible inventory host file.'
) )
......
...@@ -99,6 +99,7 @@ def process_runner_arguments( ...@@ -99,6 +99,7 @@ def process_runner_arguments(
docker_username=None, docker_username=None,
docker_password=None, docker_password=None,
no_docker=False, no_docker=False,
no_image_pull=False,
host_file=None, host_file=None,
host_list=None, host_list=None,
host_username=None, host_username=None,
...@@ -115,6 +116,7 @@ def process_runner_arguments( ...@@ -115,6 +116,7 @@ def process_runner_arguments(
docker_username (str, optional): Docker registry username if authentication is needed. Defaults to None. docker_username (str, optional): Docker registry username if authentication is needed. Defaults to None.
docker_password (str, optional): Docker registry password if authentication is needed. Defaults to None. docker_password (str, optional): Docker registry password if authentication is needed. Defaults to None.
no_docker (bool, optional): Run on host directly without Docker. Defaults to False. no_docker (bool, optional): Run on host directly without Docker. Defaults to False.
no_image_pull (bool, optional): Skip pull and use local Docker image. Defaults to False.
host_file (str, optional): Path to Ansible inventory host file. Defaults to None. host_file (str, optional): Path to Ansible inventory host file. Defaults to None.
host_list (str, optional): Comma separated host list. Defaults to None. host_list (str, optional): Comma separated host list. Defaults to None.
host_username (str, optional): Host username if needed. Defaults to None. host_username (str, optional): Host username if needed. Defaults to None.
...@@ -149,6 +151,7 @@ def process_runner_arguments( ...@@ -149,6 +151,7 @@ def process_runner_arguments(
'password': docker_password, 'password': docker_password,
'registry': split_docker_domain(docker_image)[0], 'registry': split_docker_domain(docker_image)[0],
'skip': no_docker, 'skip': no_docker,
'pull': not no_image_pull,
} }
) )
# Ansible config # Ansible config
...@@ -209,6 +212,7 @@ def deploy_command_handler( ...@@ -209,6 +212,7 @@ def deploy_command_handler(
docker_image='superbench/superbench', docker_image='superbench/superbench',
docker_username=None, docker_username=None,
docker_password=None, docker_password=None,
no_image_pull=False,
host_file=None, host_file=None,
host_list=None, host_list=None,
host_username=None, host_username=None,
...@@ -228,6 +232,7 @@ def deploy_command_handler( ...@@ -228,6 +232,7 @@ def deploy_command_handler(
docker_image (str, optional): Docker image URI. Defaults to superbench/superbench:latest. docker_image (str, optional): Docker image URI. Defaults to superbench/superbench:latest.
docker_username (str, optional): Docker registry username if authentication is needed. Defaults to None. docker_username (str, optional): Docker registry username if authentication is needed. Defaults to None.
docker_password (str, optional): Docker registry password if authentication is needed. Defaults to None. docker_password (str, optional): Docker registry password if authentication is needed. Defaults to None.
no_image_pull (bool, optional): Skip pull and use local Docker image. Defaults to False.
host_file (str, optional): Path to Ansible inventory host file. Defaults to None. host_file (str, optional): Path to Ansible inventory host file. Defaults to None.
host_list (str, optional): Comma separated host list. Defaults to None. host_list (str, optional): Comma separated host list. Defaults to None.
host_username (str, optional): Host username if needed. Defaults to None. host_username (str, optional): Host username if needed. Defaults to None.
...@@ -243,6 +248,7 @@ def deploy_command_handler( ...@@ -243,6 +248,7 @@ def deploy_command_handler(
docker_username=docker_username, docker_username=docker_username,
docker_password=docker_password, docker_password=docker_password,
no_docker=False, no_docker=False,
no_image_pull=no_image_pull,
host_file=host_file, host_file=host_file,
host_list=host_list, host_list=host_list,
host_username=host_username, host_username=host_username,
...@@ -298,6 +304,7 @@ def run_command_handler( ...@@ -298,6 +304,7 @@ def run_command_handler(
docker_username=docker_username, docker_username=docker_username,
docker_password=docker_password, docker_password=docker_password,
no_docker=no_docker, no_docker=no_docker,
no_image_pull=False,
host_file=host_file, host_file=host_file,
host_list=host_list, host_list=host_list,
host_username=host_username, host_username=host_username,
......
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
shell: | shell: |
docker pull {{ docker_image }} docker pull {{ docker_image }}
become: yes become: yes
when: docker_pull | default(true)
throttle: 32 throttle: 32
- name: Starting Container - name: Starting Container
shell: | shell: |
......
...@@ -183,6 +183,7 @@ def deploy(self): # pragma: no cover ...@@ -183,6 +183,7 @@ def deploy(self): # pragma: no cover
'ssh_port': random.randint(1 << 14, (1 << 15) - 1), 'ssh_port': random.randint(1 << 14, (1 << 15) - 1),
'output_dir': str(self._output_path), 'output_dir': str(self._output_path),
'docker_image': self._docker_config.image, 'docker_image': self._docker_config.image,
'docker_pull': bool(self._docker_config.pull),
} }
if bool(self._docker_config.username) and bool(self._docker_config.password): if bool(self._docker_config.username) and bool(self._docker_config.password):
extravars.update( extravars.update(
......
...@@ -60,6 +60,12 @@ def test_sb_deploy(self, mocked_failure_count): ...@@ -60,6 +60,12 @@ def test_sb_deploy(self, mocked_failure_count):
mocked_failure_count.return_value = 0 mocked_failure_count.return_value = 0
self.cmd('sb deploy --host-list localhost', checks=[NoneCheck()]) self.cmd('sb deploy --host-list localhost', checks=[NoneCheck()])
@mock.patch('superbench.runner.SuperBenchRunner.get_failure_count')
def test_sb_deploy_skippull(self, mocked_failure_count):
"""Test sb deploy without docker pull."""
mocked_failure_count.return_value = 0
self.cmd('sb deploy --host-list localhost --no-image-pull', checks=[NoneCheck()])
def test_sb_deploy_no_host(self): def test_sb_deploy_no_host(self):
"""Test sb deploy, no host_file or host_list provided, should fail.""" """Test sb deploy, no host_file or host_list provided, should fail."""
self.cmd('sb deploy', expect_failure=True) self.cmd('sb deploy', expect_failure=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment