Skip to content

Commit

Permalink
Docker pull runner
Browse files Browse the repository at this point in the history
  • Loading branch information
lsibilla committed Nov 29, 2020
1 parent 79b6a1e commit ec99510
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions runci/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def status(self):
"runci.engine.runner.compose_build",
"runci.engine.runner.compose_run",
"runci.engine.runner.docker_build",
"runci.engine.runner.docker_pull",
"runci.engine.runner.target_run",
"runci.engine.listener.terminal",
]
Expand Down
25 changes: 25 additions & 0 deletions runci/engine/runner/docker_pull.py
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)
45 changes: 45 additions & 0 deletions tests/test_runner_docker_pull.py
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()

0 comments on commit ec99510

Please sign in to comment.