Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Allow to force deploy if deploy parameters change (#644)
Browse files Browse the repository at this point in the history
Adds `--force` flag to deploy cli command. If deployment parameters
changed and this flag set, mlem will remove old deployment and create
new one.
Also, now there will be no error if parameters changed, but old app does
not have state

Limitations:
* for now only available from cli since adding this to API required a
bit of refactoring
* deployment will always be re-created even if platform allows to just
update old deployment

related #463
closes #549
  • Loading branch information
mike0sv authored Mar 20, 2023
1 parent 50f6d57 commit 6bf8f12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 16 additions & 4 deletions mlem/cli/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
MlemModel,
)
from mlem.telemetry import pass_telemetry_params
from mlem.ui import echo, no_echo, set_echo
from mlem.ui import EMOJI_STOP, echo, no_echo, set_echo

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -116,6 +116,9 @@ def deploy_run_command(
model_rev: Optional[str] = option_model_rev,
project: Optional[str] = option_project,
file_conf: List[str] = option_file_conf("deployment"),
force: bool = Option(
False, is_flag=True, help="Force re-create if parameters changed"
),
**__kwargs__,
):
from mlem.api.commands import deploy
Expand All @@ -139,9 +142,18 @@ def deploy_run_command(
try:
meta = load_meta(path, project=project, force_type=MlemDeployment)
if meta != _meta:
raise DeploymentError(
f"Different deployment meta already exists at {meta.loc}. Please use `mlem deployment run --load <path> ...`"
)
if not meta.is_state_empty:
if not force:
raise DeploymentError(
f"Different deployment meta already exists at {meta.loc}. Please use `mlem deployment run --load <path> ...`"
)
echo(
EMOJI_STOP
+ "Removing old deployment since parameters changed"
)
meta.remove()
with wrap_build_error(type_name, MlemDeployment):
meta = _meta.dump(path, project=project)
except MlemObjectNotFound:
with wrap_build_error(type_name, MlemDeployment):
meta = _meta.dump(path, project=project)
Expand Down
4 changes: 4 additions & 0 deletions mlem/core/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,10 @@ def get_state(self) -> ST:
self, self.state_type
) or self.state_type(declaration=self)

@property
def is_state_empty(self):
return self._state_manager.get_state(self, self.state_type) is None

def lock_state(self):
return self._state_manager.lock_state(self)

Expand Down

0 comments on commit 6bf8f12

Please sign in to comment.