Skip to content

Commit

Permalink
Make data explorer non-blocking with docker compose (#731)
Browse files Browse the repository at this point in the history
Small PR to avoid showing the localhost url before the image is build
  • Loading branch information
PhilippeMoussalli authored Jan 2, 2024
1 parent 0f40ee2 commit 2c51c07
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 139 deletions.
14 changes: 7 additions & 7 deletions docs/data_explorer.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ together with the Fondant python package.
=== "Console"

```bash
fondant explore --base_path $BASE_PATH
fondant explore start --base_path $BASE_PATH
```

=== "Python"
Expand All @@ -71,22 +71,22 @@ or `--auth-azure` to
mount your default local cloud credentials to the pipeline. Or You can also use
the `--extra-volumnes` flag to specify credentials or local files you need to mount.

To stop the data explorer service you can use the following commands:

Example:

=== "Console"

```bash
export BASE_PATH=gs://foo/bar
fondant explore --base_path $BASE_PATH
fondant explore stop
```

=== "Python"

```python
from fondant.explore import run_explorer_app

BASE_PATH = "gs://foo/bar"
run_explorer_app(base_path=BASE_PATH)
from fondant.explore import stop_explorer_app

stop_explorer_app()
```


Expand Down
2 changes: 1 addition & 1 deletion docs/guides/build_a_simple_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The pipeline execution will start, initiating the download of the dataset from H
After the pipeline has completed, you can explore the pipeline result using the fondant explorer:

```bash
fondant explore --base_path ./data
fondant explore start --base_path ./data
```

You can open your browser at `localhost:8501` to explore the loaded data.
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/first_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fondant run local pipeline.py
Congrats, you just ran your first Fondant pipeline!
To visually inspect the results between every pipeline step, you can use the fondant explorer:
```
fondant explore --base_path ./data-dir
fondant explore start --base_path ./data-dir
```

### Building your own pipeline
Expand Down
43 changes: 35 additions & 8 deletions src/fondant/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,41 +107,52 @@ def register_explore(parent_parser):
Example:
fondant explore --base_path gs://foo/bar \
fondant explore start --base_path gs://foo/bar \
-c $HOME/.config/gcloud/application_default_credentials.json:/root/.config/gcloud/application_default_credentials.json
""",
),
)
auth_group = parser.add_mutually_exclusive_group()

parser.add_argument(
explore_subparser = parser.add_subparsers()
start_parser = explore_subparser.add_parser(name="start", help="Start explorer app")
stop_parser = explore_subparser.add_parser(name="stop", help="Stop explorer app")

auth_group = start_parser.add_mutually_exclusive_group()

start_parser.add_argument(
"--base_path",
"-b",
type=str,
help="""Base path that contains the data produced by a Fondant pipeline (local or remote)
.""",
)
parser.add_argument(
start_parser.add_argument(
"--container",
"-r",
type=str,
default="fndnt/data_explorer",
help="Docker container to use. Defaults to fndnt/data_explorer.",
)
parser.add_argument(
start_parser.add_argument(
"--tag",
"-t",
type=str,
default=version("fondant") if version("fondant") != "0.1.dev0" else "latest",
help="Docker image tag to use.",
)
parser.add_argument(
start_parser.add_argument(
"--port",
"-p",
type=int,
default=8501,
help="Port to expose the container on.",
)
start_parser.add_argument(
"--output-path",
type=str,
default=".fondant/explorer-compose.yaml",
help="The path to the Docker Compose specification.",
)

auth_group.add_argument(
"--auth-gcp",
Expand Down Expand Up @@ -172,10 +183,18 @@ def register_explore(parent_parser):
nargs="+",
)

parser.set_defaults(func=explore)
stop_parser.add_argument(
"--output-path",
type=str,
default=".fondant/explorer-compose.yaml",
help="The path to the Docker Compose specification.",
)

start_parser.set_defaults(func=start_explore)
stop_parser.set_defaults(func=stop_explore)

def explore(args):

def start_explore(args):
from fondant.explore import run_explorer_app

if not shutil.which("docker"):
Expand All @@ -202,6 +221,14 @@ def explore(args):
)


def stop_explore(args):
from fondant.explore import stop_explorer_app

stop_explorer_app(
output_path=args.output_path,
)


def register_build(parent_parser):
parser = parent_parser.add_parser(
"build",
Expand Down
17 changes: 17 additions & 0 deletions src/fondant/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@
import os
import re
import typing as t
from dataclasses import dataclass
from enum import Enum

import pyarrow as pa

from fondant.core.exceptions import InvalidTypeSchema


@dataclass
class DockerVolume:
"""Dataclass representing a DockerVolume.
(https://docs.docker.com/compose/compose-file/05-services/#volumes).
Args:
type: the mount type volume (bind, volume)
source: the source of the mount, a path on the host for a bind mount
target: the path in the container where the volume is mounted.
"""

type: str
source: str
target: str


class CloudCredentialsMount(Enum):
home_directory = os.path.expanduser("~")
AWS = f"{home_directory}/credentials:/root/.aws/credentials"
Expand Down
Loading

0 comments on commit 2c51c07

Please sign in to comment.