From f5ecced7da78811c43d383782bb5022d2f72a481 Mon Sep 17 00:00:00 2001 From: Egor Sklyarov Date: Fri, 4 Aug 2023 13:27:59 +0400 Subject: [PATCH 1/2] Fix service logs with gateway URL --- cli/dstack/_internal/cli/utils/run.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/dstack/_internal/cli/utils/run.py b/cli/dstack/_internal/cli/utils/run.py index 8968ab97f..4130fd437 100644 --- a/cli/dstack/_internal/cli/utils/run.py +++ b/cli/dstack/_internal/cli/utils/run.py @@ -19,7 +19,7 @@ from dstack._internal.cli.utils.watcher import LocalCopier, SSHCopier, Watcher from dstack._internal.core.app import AppSpec from dstack._internal.core.instance import InstanceType -from dstack._internal.core.job import Job, JobErrorCode, JobHead, JobStatus +from dstack._internal.core.job import ConfigurationType, Job, JobErrorCode, JobHead, JobStatus from dstack._internal.core.plan import RunPlan from dstack._internal.core.request import RequestStatus from dstack._internal.core.run import RunHead @@ -345,8 +345,13 @@ def _run_container_ssh_tunnel(hub_client: HubClient, run_name: str, ports_lock: def _poll_logs_ws(hub_client: HubClient, job: Job, ports: Dict[int, int]): + hostname = "127.0.0.1" + if job.configuration_type == ConfigurationType.SERVICE: + hostname = job.gateway.hostname + ports = {**ports, job.gateway.service_port: job.gateway.public_port} + def on_message(ws: WebSocketApp, message): - message = fix_urls(message, job, ports, hostname="127.0.0.1") + message = fix_urls(message, job, ports, hostname=hostname) sys.stdout.buffer.write(message) sys.stdout.buffer.flush() From 21bf9d940386b39b0f2026849f66df732a99250d Mon Sep 17 00:00:00 2001 From: Egor Sklyarov Date: Fri, 4 Aug 2023 13:34:31 +0400 Subject: [PATCH 2/2] Add service configuration to README --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f924f2d6..90317414f 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ A configuration is a YAML file that describes what you want to run. > you can name the configuration file `.dstack.yml` or `app.dstack.yml`. You can define > these configurations anywhere within your project. -Configurations can be of two types: `dev-environment` and `task`. +Configurations can be of three types: `dev-environment`, `task`, and `service`. Below is a configuration that runs a dev environment with a pre-built environment to which you can connect via VS Code Desktop. @@ -84,6 +84,17 @@ commands: - python app.py ``` +A service configuration makes a web application available through the gateway. +Below is a configuration for a simple web server. + +```yaml +type: service +gateway: my.domain.com +port: 80:8000 +commands: + - python -m http.server 8000 +``` + ## CLI To run a configuration, use the [`dstack run`](https://dstack.ai/docs/reference/cli/run.md) command and pass the path to the