Skip to content

Commit 793bfca

Browse files
authored
Provide default cortex client environment to streamline in-cluster initialisation (#1942)
1 parent 57077ea commit 793bfca

File tree

17 files changed

+156
-14
lines changed

17 files changed

+156
-14
lines changed

cli/cmd/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var _envListCmd = &cobra.Command{
9999
fmt.Print("[]")
100100
return
101101
}
102-
bytes, err := libjson.Marshal(cliConfig.Environments)
102+
bytes, err := libjson.Marshal(cliConfig.ConvertToUserFacingCLIConfig())
103103
if err != nil {
104104
exit.Error(err)
105105
}

cli/types/cliconfig/cli_config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ type CLIConfig struct {
2727
Environments []*Environment `json:"environments" yaml:"environments"`
2828
}
2929

30+
type UserFacingCLIConfig struct {
31+
DefaultEnvironment *string `json:"default_environment" yaml:"default_environment"`
32+
Environments []*Environment `json:"environments" yaml:"environments"`
33+
}
34+
3035
func (cliConfig *CLIConfig) Validate() error {
3136
envNames := strset.New()
3237

@@ -50,3 +55,10 @@ func (cliConfig *CLIConfig) Validate() error {
5055

5156
return nil
5257
}
58+
59+
func (cliConfig *CLIConfig) ConvertToUserFacingCLIConfig() UserFacingCLIConfig {
60+
return UserFacingCLIConfig{
61+
DefaultEnvironment: cliConfig.DefaultEnvironment,
62+
Environments: cliConfig.Environments,
63+
}
64+
}

docs/clients/python.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
## client
2323

2424
```python
25-
client(env: str) -> Client
25+
client(env: str = None) -> Client
2626
```
2727

2828
Initialize a client based on the specified environment.
29+
If no environment name is passed, it will attempt using the default environment.
2930

3031
**Arguments**:
3132

docs/workloads/batch/predictors.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ from cortex_internal.lib.log import logger as cortex_logger
218218

219219
class PythonPredictor:
220220
def predict(self, payload, batch_id):
221+
...
221222
cortex_logger.info("completed processing batch", extra={"batch_id": batch_id, "confidence": confidence})
222223
```
223224

@@ -228,3 +229,19 @@ The dictionary passed in via the `extra` will be flattened by one level. e.g.
228229
```
229230

230231
To avoid overriding essential Cortex metadata, please refrain from specifying the following extra keys: `asctime`, `levelname`, `message`, `labels`, and `process`. Log lines greater than 5 MB in size will be ignored.
232+
233+
## Cortex Python client
234+
235+
A default [Cortex Python client](../../clients/python.md#cortex.client.client) environment has been configured for your API. This can be used for deploying/deleting/updating or submitting jobs to your running cluster based on the execution flow of your batch predictor. For example:
236+
237+
```python
238+
import cortex
239+
240+
class PythonPredictor:
241+
def on_job_complete(self):
242+
...
243+
# get client pointing to the default environment
244+
client = cortex.client()
245+
# deploy API in the existing cluster using the artifacts in the previous step
246+
client.create_api(...)
247+
```

docs/workloads/realtime/predictors.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,19 @@ The dictionary passed in via the `extra` will be flattened by one level. e.g.
476476
```
477477

478478
To avoid overriding essential Cortex metadata, please refrain from specifying the following extra keys: `asctime`, `levelname`, `message`, `labels`, and `process`. Log lines greater than 5 MB in size will be ignored.
479+
480+
## Cortex Python client
481+
482+
A default [Cortex Python client](../../clients/python.md#cortex.client.client) environment has been configured for your API. This can be used for deploying/deleting/updating or submitting jobs to your running cluster based on the execution flow of your predictor. For example:
483+
484+
```python
485+
import cortex
486+
487+
class PythonPredictor:
488+
def __init__(self, config):
489+
...
490+
# get client pointing to the default environment
491+
client = cortex.client()
492+
# get the existing apis in the cluster for something important to you
493+
existing_apis = client.list_apis()
494+
```

docs/workloads/task/definitions.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,19 @@ The dictionary passed in via the `extra` will be flattened by one level. e.g.
7373
```
7474

7575
To avoid overriding essential Cortex metadata, please refrain from specifying the following extra keys: `asctime`, `levelname`, `message`, `labels`, and `process`. Log lines greater than 5 MB in size will be ignored.
76+
77+
## Cortex Python client
78+
79+
A default [Cortex Python client](../../clients/python.md#cortex.client.client) environment has been configured for your API. This can be used for deploying/deleting/updating or submitting jobs to your running cluster based on the execution flow of your task. For example:
80+
81+
```python
82+
import cortex
83+
84+
class Task:
85+
def __call__(self, config):
86+
...
87+
# get client pointing to the default environment
88+
client = cortex.client()
89+
# deploy API in the existing cluster as part of your pipeline workflow
90+
client.create_api(...)
91+
```

images/onnx-predictor-cpu/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ COPY pkg/cortex/serve/init/install-core-dependencies.sh /usr/local/cortex/instal
5454
RUN chmod +x /usr/local/cortex/install-core-dependencies.sh
5555

5656
COPY pkg/cortex/serve/ /src/cortex/serve
57+
COPY pkg/cortex/client/ /src/cortex/client
5758
ENV CORTEX_LOG_CONFIG_FILE /src/cortex/serve/log_config.yaml
5859

59-
RUN pip install --no-deps /src/cortex/serve/
60+
RUN pip install --no-deps /src/cortex/serve/ && \
61+
pip install /src/cortex/client && \
62+
rm -r /src/cortex/client
6063
RUN mv /src/cortex/serve/init/bootloader.sh /etc/cont-init.d/bootloader.sh
6164

6265
ENTRYPOINT ["/init"]

images/onnx-predictor-gpu/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ COPY pkg/cortex/serve/init/install-core-dependencies.sh /usr/local/cortex/instal
5454
RUN chmod +x /usr/local/cortex/install-core-dependencies.sh
5555

5656
COPY pkg/cortex/serve/ /src/cortex/serve
57+
COPY pkg/cortex/client/ /src/cortex/client
5758
ENV CORTEX_LOG_CONFIG_FILE /src/cortex/serve/log_config.yaml
5859

59-
RUN pip install --no-deps /src/cortex/serve/
60+
RUN pip install --no-deps /src/cortex/serve/ && \
61+
pip install /src/cortex/client && \
62+
rm -r /src/cortex/client
6063
RUN mv /src/cortex/serve/init/bootloader.sh /etc/cont-init.d/bootloader.sh
6164

6265
ENTRYPOINT ["/init"]

images/python-predictor-cpu/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ COPY pkg/cortex/serve/init/install-core-dependencies.sh /usr/local/cortex/instal
5353
RUN chmod +x /usr/local/cortex/install-core-dependencies.sh
5454

5555
COPY pkg/cortex/serve/ /src/cortex/serve
56+
COPY pkg/cortex/client/ /src/cortex/client
5657
ENV CORTEX_LOG_CONFIG_FILE /src/cortex/serve/log_config.yaml
5758

58-
RUN pip install --no-deps /src/cortex/serve/
59+
RUN pip install --no-deps /src/cortex/serve/ && \
60+
pip install /src/cortex/client && \
61+
rm -r /src/cortex/client
5962
RUN mv /src/cortex/serve/init/bootloader.sh /etc/cont-init.d/bootloader.sh
6063

6164
ENTRYPOINT ["/init"]

images/python-predictor-gpu/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ COPY pkg/cortex/serve/init/install-core-dependencies.sh /usr/local/cortex/instal
5555
RUN chmod +x /usr/local/cortex/install-core-dependencies.sh
5656

5757
COPY pkg/cortex/serve/ /src/cortex/serve
58+
COPY pkg/cortex/client/ /src/cortex/client
5859
ENV CORTEX_LOG_CONFIG_FILE /src/cortex/serve/log_config.yaml
5960

60-
RUN pip install --no-deps /src/cortex/serve/
61+
RUN pip install --no-deps /src/cortex/serve/ && \
62+
pip install /src/cortex/client && \
63+
rm -r /src/cortex/client
6164
RUN mv /src/cortex/serve/init/bootloader.sh /etc/cont-init.d/bootloader.sh
6265

6366
ENTRYPOINT ["/init"]

0 commit comments

Comments
 (0)