Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Improve handling of environment file specification (#63)
* Stop running container on SIGINT (#62)
* `xcetool image run --server` prints server and viewer urls (#46)

## Changes in 0.1.1

Expand Down
18 changes: 13 additions & 5 deletions docs/xcetool.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ a CWL file defining a corresponding application package.

This subcommand runs an xcengine container image. An image can also be run using the
`docker run` command, but `xcetool image run` provides some additional convenience
(e.g. easy configuration of the HTTP port).

If you give the `--server` flag, `xcetool` will run the container indefinitely as an
xcube server. You can stop the container and force `xcetool` to exit by pressing
ctrl-C on the command line (or by sending it an interrupt signal in some other way).
(e.g. easy configuration of a server HTTP port).

If you use the `--server` option with `xcetool image run`, the image will be run in
xcube server mode: after the code from the input notebook is used to generate datasets,
those datasets will be made available in an xcube server instance. You can also use
the `--port` option to select the HTTP port where the xcube server should be exposed.
The server also includes an interactive web viewer component. On start-up, `xcetool`
will print the URLs of the xcube server and viewer to the standard output.

If you give the `--server` or `--port` options, `xcetool` will run the container
indefinitely as an xcube server and viewer instance. You can stop the container and
force `xcetool` to exit by pressing ctrl-C on the command line (or by sending it an
interrupt signal in some other way).

### `xcetool make-script`

Expand Down
25 changes: 25 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import runpy
import subprocess
from unittest.mock import patch, ANY, MagicMock
Expand Down Expand Up @@ -102,3 +103,27 @@ def test_image_run(runner_mock):
from_saved=False,
keep=False,
)


@patch("xcengine.cli.ContainerRunner")
def test_image_run_print_urls(runner_mock):
cli_runner = CliRunner()
instance_mock = runner_mock.return_value = MagicMock()
port = 32168
result = cli_runner.invoke(
cli, ["image", "run", "--server", "--port", str(port), "foo"]
)
runner_mock.assert_called_once_with(image="foo", output_dir=None)
assert result.exit_code == 0
instance_mock.run.assert_called_once_with(
run_batch=False,
host_port=port,
from_saved=False,
keep=False,
)
assert re.search(
f"server.*http://localhost:{port}", result.stdout, re.IGNORECASE
)
assert re.search(
f"viewer.*http://localhost:{port}/viewer", result.stdout, re.IGNORECASE
)
12 changes: 12 additions & 0 deletions xcengine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import pathlib
import subprocess
import sys
import tempfile

import click
Expand All @@ -18,6 +19,7 @@
LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


@click.group(
help="Create and run compute engine scripts and containers "
"from IPython notebooks"
Expand Down Expand Up @@ -154,9 +156,11 @@ def build(
)
image = image_builder.build()
if eoap:

class IndentDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(IndentDumper, self).increase_indent(flow, False)

eoap.write_text(
yaml.dump(
image_builder.create_cwl(),
Expand Down Expand Up @@ -221,6 +225,14 @@ def run(
is not click.core.ParameterSource.DEFAULT
)
actual_port = port if server or port_specified_explicitly else None
if actual_port is not None:
print(
f"xcube server will be available at http://localhost:{actual_port}"
)
print(
f"xcube viewer will be available at "
f"http://localhost:{actual_port}/viewer"
)
runner.run(
run_batch=batch,
host_port=actual_port,
Expand Down