"git@developer.sourcefind.cn:tsoc/superbenchmark.git" did not exist on "c387d9c0923e5d380237e75d53a9d50651e3c782"
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]
[--host-list]
[--host-password]
[--host-username]
[--no-image-pull]
[--output-dir]
[--private-key]
```
......@@ -112,6 +113,7 @@ sb deploy [--docker-image]
| `--host-list` `-l` | `None` | Comma separated host list. |
| `--host-password` | `None` | Host password or key passphase 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. |
| `--private-key` | `None` | Path to private key if needed. |
......
......@@ -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_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_image_pull', action='store_true', help='Skip pull and use local Docker image.')
ac.argument(
'host_file', options_list=('--host-file', '-f'), type=str, help='Path to Ansible inventory host file.'
)
......
......@@ -99,6 +99,7 @@ def process_runner_arguments(
docker_username=None,
docker_password=None,
no_docker=False,
no_image_pull=False,
host_file=None,
host_list=None,
host_username=None,
......@@ -115,6 +116,7 @@ def process_runner_arguments(
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.
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_list (str, optional): Comma separated host list. Defaults to None.
host_username (str, optional): Host username if needed. Defaults to None.
......@@ -149,6 +151,7 @@ def process_runner_arguments(
'password': docker_password,
'registry': split_docker_domain(docker_image)[0],
'skip': no_docker,
'pull': not no_image_pull,
}
)
# Ansible config
......@@ -209,6 +212,7 @@ def deploy_command_handler(
docker_image='superbench/superbench',
docker_username=None,
docker_password=None,
no_image_pull=False,
host_file=None,
host_list=None,
host_username=None,
......@@ -228,6 +232,7 @@ def deploy_command_handler(
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_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_list (str, optional): Comma separated host list. Defaults to None.
host_username (str, optional): Host username if needed. Defaults to None.
......@@ -243,6 +248,7 @@ def deploy_command_handler(
docker_username=docker_username,
docker_password=docker_password,
no_docker=False,
no_image_pull=no_image_pull,
host_file=host_file,
host_list=host_list,
host_username=host_username,
......@@ -298,6 +304,7 @@ def run_command_handler(
docker_username=docker_username,
docker_password=docker_password,
no_docker=no_docker,
no_image_pull=False,
host_file=host_file,
host_list=host_list,
host_username=host_username,
......
......@@ -92,6 +92,7 @@
shell: |
docker pull {{ docker_image }}
become: yes
when: docker_pull | default(true)
throttle: 32
- name: Starting Container
shell: |
......
......@@ -183,6 +183,7 @@ def deploy(self): # pragma: no cover
'ssh_port': random.randint(1 << 14, (1 << 15) - 1),
'output_dir': str(self._output_path),
'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):
extravars.update(
......
......@@ -60,6 +60,12 @@ def test_sb_deploy(self, mocked_failure_count):
mocked_failure_count.return_value = 0
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):
"""Test sb deploy, no host_file or host_list provided, should fail."""
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