dstackai / dstack

dstack is an open-source alternative to Kubernetes, designed to simplify development, training, and deployment of AI across any cloud or on-prem. It supports NVIDIA, AMD, and TPU.
https://dstack.ai/docs
Mozilla Public License 2.0
1.32k stars 98 forks source link

[Feature]: Allow to specify required env variables in task/service/dev-environment configuration when a mapping is used #1511

Open un-def opened 1 month ago

un-def commented 1 month ago

Problem

env setting in task/service/dev-environment configurations has two formats, it's either a list of strings or a mapping. When the list format is used, it's possible to specify a variable without value, in this case the value must be provided via a CLI argument or an enviroment variable:

env:
  - REQUIRED_VAR
  - VAR_WITH_EMPTY_VALUE=
$ dstack apply
Environment variable REQUIRED_VAR is not set

$ dstack apply -e REQUIRED_VAR=value
...
Submit a new run? [y/n]

$ export REQUIRED_VAR=value
$ dstack apply 
...
Submit a new run? [y/n]

This is not possible with the mapping format:

env:
  REQUIRED_VAR:
  VAR_WITH_EMPTY_VALUE: ''
$ dstack apply
2 validation errors for ApplyConfigurationRequest
__root__ -> TaskConfigurationRequest -> env
  value is not a valid list (type=type_error.list)
__root__ -> TaskConfigurationRequest -> env -> REQUIRED_VAR
  none is not an allowed value (type=type_error.none.not_allowed)

Solution

Treat null (an implicit value in YAML mapping if no value provided) as a marker of a required variable.

Workaround

No response

Would you like to help us implement this feature by sending a PR?

No

peterschmidt85 commented 2 weeks ago

I'd drop mapping support instead