@@ -176,6 +176,36 @@ def verify(
176176 if isinstance (bento_info , Bento )
177177 else bento_info
178178 )
179+
180+ # NOTE:
181+ # envs defined on the service via @bentoml.service(envs=[...])
182+ # are stored on the Bento manifest (manifest.envs). Historically
183+ # they were only used for validation here (empty value => required),
184+ # and for image build (spec v2).
185+ #
186+ # When users run `bentoml deploy .` they expect those envs with
187+ # default values to also show up as deployment envs on BentoCloud.
188+ # To honour that expectation, we treat manifest envs with a value
189+ # as default deployment envs, unless they are explicitly set via
190+ # CLI flags or a config file.
191+ if self .cli and self .config_dict is None and self .config_file is None :
192+ # Only envs coming from CLI flags are in self.envs here.
193+ existing_env_names = {
194+ env ["name" ] for env in (self .envs or []) if "name" in env
195+ }
196+ default_envs = [
197+ {"name" : env .name , "value" : env .value }
198+ for env in manifest .envs
199+ if env .value and env .name not in existing_env_names
200+ ]
201+ if default_envs :
202+ if self .envs is None :
203+ self .envs = []
204+ self .envs .extend (default_envs )
205+ # Keep cfg_dict in sync so that get_config_dict() sends
206+ # these defaults to BentoCloud.
207+ self .cfg_dict ["envs" ] = self .envs
208+
179209 required_envs = [env .name for env in manifest .envs if not env .value ]
180210 provided_envs : list [str ] = [env ["name" ] for env in (self .envs or [])]
181211 if self .secrets :
0 commit comments