Skip to content

Commit d29215a

Browse files
authored
Add dependencies to task definition (#1927)
1 parent afe1007 commit d29215a

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

docs/workloads/task/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
definition:
88
path: <string> # path to a python file with a Task class definition, relative to the Cortex root (required)
99
config: <string: value> # arbitrary dictionary passed to the callable method of the Task class (can be overridden by config passed in job submission) (optional)
10+
dependencies: # (optional)
11+
pip: <string> # relative path to requirements.txt (default: requirements.txt)
12+
conda: <string> # relative path to conda-packages.txt (default: conda-packages.txt)
13+
shell: <string> # relative path to a shell script for system package installation (default: dependencies.sh)
1014
python_path: <string> # path to the root of your Python folder that will be appended to PYTHONPATH (default: folder containing cortex.yaml)
1115
image: <string> # docker image to use for the Task (default: quay.io/cortexlabs/python-predictor-cpu:master, quay.io/cortexlabs/python-predictor-gpu:master-cuda10.2-cudnn8, or quay.io/cortexlabs/python-predictor-inf:master based on compute)
1216
env: <string: string> # dictionary of environment variables

pkg/operator/operator/k8s.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,18 @@ func getTaskEnvVars(api *spec.API, container string) []kcore.EnvVar {
521521
Name: "CORTEX_PROJECT_DIR",
522522
Value: path.Join(_emptyDirMountPath, "project"),
523523
},
524+
kcore.EnvVar{
525+
Name: "CORTEX_DEPENDENCIES_PIP",
526+
Value: api.TaskDefinition.Dependencies.Pip,
527+
},
528+
kcore.EnvVar{
529+
Name: "CORTEX_DEPENDENCIES_CONDA",
530+
Value: api.TaskDefinition.Dependencies.Conda,
531+
},
532+
kcore.EnvVar{
533+
Name: "CORTEX_DEPENDENCIES_SHELL",
534+
Value: api.TaskDefinition.Dependencies.Shell,
535+
},
524536
kcore.EnvVar{
525537
Name: "CORTEX_CACHE_DIR",
526538
Value: _specCacheDir,

pkg/types/spec/validations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ func taskDefinitionValidation() *cr.StructFieldValidation {
311311
AllowEmpty: true,
312312
},
313313
},
314+
dependencyPathValidation(),
314315
},
315316
},
316317
}

pkg/types/userconfig/api.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ type Predictor struct {
6565
}
6666

6767
type TaskDefinition struct {
68-
Path string `json:"path" yaml:"path"`
69-
PythonPath *string `json:"python_path" yaml:"python_path"`
70-
Image string `json:"image" yaml:"image"`
71-
LogLevel LogLevel `json:"log_level" yaml:"log_level"`
72-
Config map[string]interface{} `json:"config" yaml:"config"`
73-
Env map[string]string `json:"env" yaml:"env"`
68+
Path string `json:"path" yaml:"path"`
69+
PythonPath *string `json:"python_path" yaml:"python_path"`
70+
Image string `json:"image" yaml:"image"`
71+
LogLevel LogLevel `json:"log_level" yaml:"log_level"`
72+
Config map[string]interface{} `json:"config" yaml:"config"`
73+
Env map[string]string `json:"env" yaml:"env"`
74+
Dependencies *Dependencies `json:"dependencies" yaml:"dependencies"`
7475
}
7576

7677
type MultiModels struct {
@@ -373,6 +374,14 @@ func (api *API) UserStr(provider types.ProviderType) string {
373374
return sb.String()
374375
}
375376

377+
func (dependencies Dependencies) UserStr() string {
378+
var sb strings.Builder
379+
sb.WriteString(fmt.Sprintf("%s: %s\n", PipKey, dependencies.Pip))
380+
sb.WriteString(fmt.Sprintf("%s: %s\n", CondaKey, dependencies.Conda))
381+
sb.WriteString(fmt.Sprintf("%s: %s\n", ShellKey, dependencies.Shell))
382+
return sb.String()
383+
}
384+
376385
func (trafficSplit *TrafficSplit) UserStr() string {
377386
var sb strings.Builder
378387
sb.WriteString(fmt.Sprintf("%s: %s\n", NameKey, trafficSplit.Name))
@@ -399,6 +408,8 @@ func (task *TaskDefinition) UserStr() string {
399408
d, _ := yaml.Marshal(&task.Env)
400409
sb.WriteString(s.Indent(string(d), " "))
401410
}
411+
sb.WriteString(fmt.Sprintf("%s:\n", DependenciesKey))
412+
sb.WriteString(s.Indent(task.Dependencies.UserStr(), " "))
402413

403414
return sb.String()
404415
}
@@ -450,6 +461,9 @@ func (predictor *Predictor) UserStr() string {
450461
d, _ := yaml.Marshal(&predictor.Env)
451462
sb.WriteString(s.Indent(string(d), " "))
452463
}
464+
sb.WriteString(fmt.Sprintf("%s:\n", DependenciesKey))
465+
sb.WriteString(s.Indent(predictor.Dependencies.UserStr(), " "))
466+
453467
return sb.String()
454468
}
455469

pkg/types/userconfig/config_key.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ const (
4545
ConfigKey = "config"
4646
EnvKey = "env"
4747

48+
// Predictor/TaskDefinition.Dependencies
49+
DependenciesKey = "dependencies"
50+
PipKey = "pip"
51+
ShellKey = "shell"
52+
CondaKey = "conda"
53+
4854
// MultiModelReloading
4955
MultiModelReloadingKey = "multi_model_reloading"
5056

0 commit comments

Comments
 (0)