-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import asyncio | ||
|
||
from .base import RunnerBase | ||
from runci.entities.context import Context | ||
|
||
|
||
class DockerPullRunner(RunnerBase): | ||
_selector = 'docker-pull' | ||
|
||
async def run_internal(self, context: Context): | ||
images = self.spec.get("image", | ||
self.spec.get("_", None)) | ||
|
||
if images is None: | ||
raise Exception("Image name should be specified for docker-pull step") | ||
|
||
base_args = ['docker', 'pull'] | ||
|
||
tasks = [] | ||
for image in images.split(' '): | ||
args = list(base_args) | ||
args.append(image) | ||
tasks.append(asyncio.create_task(self._run_process(args))) | ||
|
||
await asyncio.wait(tasks) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import asyncio | ||
import unittest | ||
|
||
from runci.entities.config import Project, Target, Step | ||
from runci.entities.parameters import Parameters | ||
from runci.engine.core import create_context, DependencyTree | ||
from runci.engine.runner.docker_pull import DockerPullRunner | ||
from unittest.mock import patch, call | ||
|
||
|
||
class test_runner_docker_build(unittest.TestCase): | ||
step = Step("test", "docker-pull", { | ||
"image": "busybox alpine" | ||
}) | ||
|
||
project = Project( | ||
services=[], | ||
targets=[Target( | ||
name="target", | ||
dependencies=[], | ||
steps=[step] | ||
)]) | ||
parameters = Parameters(dataconnection="runci.yml", targets=["target"], verbosity=0) | ||
|
||
@patch('runci.engine.runner.docker_pull.DockerPullRunner._run_process') | ||
def test_command_line_args(self, mock): | ||
async def run(): | ||
runner = DockerPullRunner(lambda e: None, self.step.spec) | ||
context = create_context(self.project, self.parameters) | ||
await runner.run(context) | ||
|
||
asyncio.run(run()) | ||
mock.assert_has_calls([ | ||
call('docker pull busybox'.split(' ')), | ||
call('docker pull alpine'.split(' '))]) | ||
|
||
@patch('runci.engine.runner.docker_pull.DockerPullRunner.run') | ||
def test_integration(self, mock): | ||
context = create_context(self.project, self.parameters) | ||
DependencyTree(context).run() | ||
mock.assert_called_once() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |