Beispiel #1
0
async def pull(root: Root, remote_image: str,
               local_image: Optional[str]) -> None:
    """
    Pull an image from platform registry.

    Remote image name must be URL with image:// scheme.
    Image names can contain tag.

    Examples:

    neuro pull image:myimage
    neuro pull image://myfriend/alpine:shared
    neuro pull image://username/my-alpine:production alpine:from-registry

    """

    progress = DockerImageProgress.create(tty=root.tty, quiet=root.quiet)
    remote_obj = root.client.parse.remote_image(remote_image)
    if local_image is not None:
        local_obj: Optional[LocalImage] = root.client.parse.local_image(
            local_image)
    else:
        local_obj = None
    with contextlib.closing(progress):
        result_local_image = await root.client.images.pull(remote_obj,
                                                           local_obj,
                                                           progress=progress)
    click.echo(result_local_image)
Beispiel #2
0
 def test_quiet_commit_finished(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=True)
     formatter.commit_finished(ImageCommitFinished(job_id="job-id"))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == ""
Beispiel #3
0
async def push(root: Root, local_image: str,
               remote_image: Optional[str]) -> None:
    """
    Push an image to platform registry.

    Remote image must be URL with image:// scheme.
    Image names can contain tag. If tags not specified 'latest' will
    be used as value.

    Examples:

    neuro push myimage
    neuro push alpine:latest image:my-alpine:production
    neuro push alpine image://myfriend/alpine:shared

    """

    progress = DockerImageProgress.create(tty=root.tty, quiet=root.quiet)
    local_obj = root.client.parse.local_image(local_image)
    if remote_image is not None:
        remote_obj: Optional[RemoteImage] = root.client.parse.remote_image(
            remote_image)
    else:
        remote_obj = None
    with contextlib.closing(progress):
        result_remote_image = await root.client.images.push(local_obj,
                                                            remote_obj,
                                                            progress=progress)
    click.echo(result_remote_image)
Beispiel #4
0
 def test_no_tty_commit_finished(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=False, quiet=False)
     formatter.commit_finished(ImageCommitFinished(job_id="job-id"))
     formatter.close()
     out, err = capfd.readouterr()
     assert out.startswith("Image created")
     assert err == ""
Beispiel #5
0
 def test_quiet_save(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=True)
     formatter.save(
         ImageProgressSave("job-id",
                           RemoteImage.new_external_image(name="output")))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == ""
Beispiel #6
0
 def test_tty_commit_finished(self, capfd: Any,
                              click_tty_emulation: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=False)
     formatter.commit_finished(ImageCommitFinished(job_id="job-id"))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out.startswith("Image created")
     assert CSI not in out  # no styled strings
Beispiel #7
0
 def test_quiet_commit_started(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=True)
     formatter.commit_started(
         ImageCommitStarted(
             job_id="job-id",
             target_image=RemoteImage.new_external_image("img")))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == ""
Beispiel #8
0
 def test_quiet_push(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=True)
     formatter.push(
         ImageProgressPush(LocalImage("output"),
                           RemoteImage.new_external_image(name="input")))
     formatter.step(ImageProgressStep("message1", "layer1"))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == ""
Beispiel #9
0
 def test_tty_commit_started(self, capfd: Any,
                             click_tty_emulation: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=False)
     formatter.commit_started(
         ImageCommitStarted(
             job_id="job-id",
             target_image=RemoteImage.new_external_image(name="img")))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert "img" in out
     assert CSI in out
Beispiel #10
0
 def test_no_tty_commit_started(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=False, quiet=False)
     formatter.commit_started(
         ImageCommitStarted(
             job_id="job-id",
             target_image=RemoteImage.new_neuro_image(
                 name="output",
                 tag="stream",
                 owner="bob",
                 registry="https://registry-dev.neu.ro",
                 cluster_name="test-cluster",
             ),
         ))
     formatter.close()
     out, err = capfd.readouterr()
     assert "Using remote image 'image://test-cluster/bob/output:stream'" in out
     assert f"Creating image from the job container..." in out
     assert err == ""
Beispiel #11
0
 def test_tty_save(self, capfd: Any, click_tty_emulation: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=False)
     formatter.save(
         ImageProgressSave(
             "job-id",
             RemoteImage.new_neuro_image(
                 name="output",
                 tag="stream",
                 owner="bob",
                 registry="https://registry-dev.neu.ro",
                 cluster_name="test-cluster",
             ),
         ))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert "job-id" in out
     assert "image://test-cluster/bob/output:stream" in out
     assert CSI in out
Beispiel #12
0
 def test_no_tty_save(self, capfd: Any) -> None:
     formatter = DockerImageProgress.create(tty=False, quiet=False)
     formatter.save(
         ImageProgressSave(
             "job-id",
             RemoteImage.new_neuro_image(
                 name="output",
                 tag="stream",
                 owner="bob",
                 registry="https://registry-dev.neu.ro",
                 cluster_name="test-cluster",
             ),
         ))
     formatter.close()
     out, err = capfd.readouterr()
     assert (
         "Saving job 'job-id' to image 'image://test-cluster/bob/output:stream'"
         in out)
     assert err == ""
Beispiel #13
0
 def test_tty_push(self, capfd: Any, click_tty_emulation: Any) -> None:
     formatter = DockerImageProgress.create(tty=True, quiet=False)
     formatter.push(
         ImageProgressPush(
             LocalImage("input", "latest"),
             RemoteImage.new_neuro_image(
                 name="output",
                 tag="stream",
                 owner="bob",
                 registry="https://registry-dev.neu.ro",
                 cluster_name="test-cluster",
             ),
         ))
     formatter.step(ImageProgressStep("message1", "layer1"))
     formatter.step(ImageProgressStep("message2", "layer1"))
     formatter.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert "input:latest" in out
     assert "image://test-cluster/bob/output:stream" in out
     assert "message1" in out
     assert "message2" in out
     assert CSI in out
Beispiel #14
0
async def save(root: Root, job: str, image: RemoteImage) -> None:
    """
    Save job's state to an image.

    Examples:
    neuro job save job-id image:ubuntu-patched
    neuro job save my-favourite-job image:ubuntu-patched:v1
    neuro job save my-favourite-job image://bob/ubuntu-patched
    """
    id = await resolve_job(
        job,
        client=root.client,
        status={
            JobStatus.PENDING,
            JobStatus.RUNNING,
            JobStatus.SUCCEEDED,
            JobStatus.FAILED,
        },
    )
    progress = DockerImageProgress.create(tty=root.tty, quiet=root.quiet)
    with contextlib.closing(progress):
        await root.client.jobs.save(id, image, progress=progress)
    click.echo(image)