Skip to content

Commit 002d1a0

Browse files
authored
Merge pull request #66 from xcube-dev/pont-46-print-urls
"xcetool image run": print server and viewer URLs
2 parents 4f33344 + 784bc9a commit 002d1a0

4 files changed

Lines changed: 51 additions & 5 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

67
## Changes in 0.1.1
78

docs/xcetool.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ a CWL file defining a corresponding application package.
1919

2020
This subcommand runs an xcengine container image. An image can also be run using the
2121
`docker run` command, but `xcetool image run` provides some additional convenience
22-
(e.g. easy configuration of the HTTP port).
23-
24-
If you give the `--server` flag, `xcetool` will run the container indefinitely as an
25-
xcube server. You can stop the container and force `xcetool` to exit by pressing
26-
ctrl-C on the command line (or by sending it an interrupt signal in some other way).
22+
(e.g. easy configuration of a server HTTP port).
23+
24+
If you use the `--server` option with `xcetool image run`, the image will be run in
25+
xcube server mode: after the code from the input notebook is used to generate datasets,
26+
those datasets will be made available in an xcube server instance. You can also use
27+
the `--port` option to select the HTTP port where the xcube server should be exposed.
28+
The server also includes an interactive web viewer component. On start-up, `xcetool`
29+
will print the URLs of the xcube server and viewer to the standard output.
30+
31+
If you give the `--server` or `--port` options, `xcetool` will run the container
32+
indefinitely as an xcube server and viewer instance. You can stop the container and
33+
force `xcetool` to exit by pressing ctrl-C on the command line (or by sending it an
34+
interrupt signal in some other way).
2735

2836
### `xcetool make-script`
2937

test/test_cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import runpy
23
import subprocess
34
from unittest.mock import patch, ANY, MagicMock
@@ -102,3 +103,27 @@ def test_image_run(runner_mock):
102103
from_saved=False,
103104
keep=False,
104105
)
106+
107+
108+
@patch("xcengine.cli.ContainerRunner")
109+
def test_image_run_print_urls(runner_mock):
110+
cli_runner = CliRunner()
111+
instance_mock = runner_mock.return_value = MagicMock()
112+
port = 32168
113+
result = cli_runner.invoke(
114+
cli, ["image", "run", "--server", "--port", str(port), "foo"]
115+
)
116+
runner_mock.assert_called_once_with(image="foo", output_dir=None)
117+
assert result.exit_code == 0
118+
instance_mock.run.assert_called_once_with(
119+
run_batch=False,
120+
host_port=port,
121+
from_saved=False,
122+
keep=False,
123+
)
124+
assert re.search(
125+
f"server.*http://localhost:{port}", result.stdout, re.IGNORECASE
126+
)
127+
assert re.search(
128+
f"viewer.*http://localhost:{port}/viewer", result.stdout, re.IGNORECASE
129+
)

xcengine/cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import pathlib
1010
import subprocess
11+
import sys
1112
import tempfile
1213

1314
import click
@@ -18,6 +19,7 @@
1819
LOGGER = logging.getLogger(__name__)
1920
logging.basicConfig(level=logging.INFO)
2021

22+
2123
@click.group(
2224
help="Create and run compute engine scripts and containers "
2325
"from IPython notebooks"
@@ -154,9 +156,11 @@ def build(
154156
)
155157
image = image_builder.build()
156158
if eoap:
159+
157160
class IndentDumper(yaml.Dumper):
158161
def increase_indent(self, flow=False, indentless=False):
159162
return super(IndentDumper, self).increase_indent(flow, False)
163+
160164
eoap.write_text(
161165
yaml.dump(
162166
image_builder.create_cwl(),
@@ -221,6 +225,14 @@ def run(
221225
is not click.core.ParameterSource.DEFAULT
222226
)
223227
actual_port = port if server or port_specified_explicitly else None
228+
if actual_port is not None:
229+
print(
230+
f"xcube server will be available at http://localhost:{actual_port}"
231+
)
232+
print(
233+
f"xcube viewer will be available at "
234+
f"http://localhost:{actual_port}/viewer"
235+
)
224236
runner.run(
225237
run_batch=batch,
226238
host_port=actual_port,

0 commit comments

Comments
 (0)