diff --git a/dagster_uc/manage_user_code_deployments.py b/dagster_uc/manage_user_code_deployments.py index 20fc042..7702a4e 100644 --- a/dagster_uc/manage_user_code_deployments.py +++ b/dagster_uc/manage_user_code_deployments.py @@ -89,6 +89,7 @@ def default( def build_push_container( deployment_name: str, + branch_name: str, image_prefix: str | None, config: UserCodeDeploymentsConfig, use_sudo: bool, @@ -105,7 +106,7 @@ def build_push_container( dockerfile=config.dockerfile, use_sudo=use_sudo, tag=tag, - branch_name=deployment_name, + branch_name=branch_name, use_az_login=config.use_az_login, ) @@ -274,7 +275,7 @@ def deployment_delete( name = handler.get_deployment_name( deployment_name_suffix="", use_project_name=config.use_project_name, - ) + ).full_name else: # In case the UI name separator of the deployment is passed name = name.replace(":", "--") @@ -308,7 +309,7 @@ def check_deployment( ) -> None: """This function executes before any other nested cli command is called and loads the configuration object.""" if not name: - name = handler.get_deployment_name(use_project_name=config.use_project_name) + name = handler.get_deployment_name(use_project_name=config.use_project_name).full_name else: # In case the UI name separator of the deployment is passed name = name.replace(":", "--") @@ -324,6 +325,8 @@ def check_deployment( with contextlib.suppress(Exception): for line in pod.logs(pretty=True, follow=True, timeout=timeout): # type: ignore typer.echo(line) + if "started dagster code server" in line.lower(): + break @deployment_app.command( @@ -400,10 +403,18 @@ def is_command_available(command: str) -> bool: raise Exception("Podman installation is required to run dagster-uc.") logger.debug("Using 'podman' to build image.") - deployment_name = deployment_name or handler.get_deployment_name( - deployment_name_suffix, - use_project_name=config.use_project_name, - ) + if deployment_name: + (deployment_name, branch_name) = (deployment_name, deployment_name) + else: + dagster_deployment = handler.get_deployment_name( + deployment_name_suffix, + use_project_name=config.use_project_name, + ) + (deployment_name, branch_name) = ( + dagster_deployment.full_name, + dagster_deployment.branch_name, + ) + logger.debug("Determining tag...") new_tag = gen_tag( deployment_name @@ -420,9 +431,10 @@ def is_command_available(command: str) -> bool: if not skip_build: build_push_container( deployment_name, - handler.config.image_prefix, - config, - use_sudo, + branch_name=branch_name, + image_prefix=handler.config.image_prefix, + config=config, + use_sudo=use_sudo, tag=new_tag, ) diff --git a/dagster_uc/uc_handler.py b/dagster_uc/uc_handler.py index 1269146..991cde9 100644 --- a/dagster_uc/uc_handler.py +++ b/dagster_uc/uc_handler.py @@ -3,7 +3,7 @@ import re import subprocess from collections.abc import Callable -from typing import cast +from typing import NamedTuple, cast import kr8s import yaml @@ -24,6 +24,13 @@ from dagster_uc.log import logger +class DagsterDeployment(NamedTuple): + """Dagster deployment names""" + + full_name: str + branch_name: str + + class DagsterUserCodeHandler: """This the dagster-user code handler for common activities such as updating config maps, listing them and modifying them.""" @@ -423,7 +430,7 @@ def get_deployment_name( # noqa: D102 self, deployment_name_suffix: str | None = None, use_project_name: bool = True, - ) -> str: + ) -> DagsterDeployment: """Creates a deployment name based on the name of the pyproject.toml and name of git branch""" logger.debug("Determining deployment name...") @@ -437,12 +444,12 @@ def get_deployment_name( # noqa: D102 name = f"{project_name}--{branch}" if project_name is not None else branch else: - name = ( - f"{project_name}--{self.config.environment}" - if project_name is not None - else self.config.environment - ) - return name + branch = self.config.environment + name = f"{project_name}--{branch}" if project_name is not None else branch + return DagsterDeployment( + full_name=name, + branch_name=branch, + ) def _ensure_dagster_version_match(self) -> None: """Raises an exception if the cluster version of dagster is different than the local version""" diff --git a/pyproject.toml b/pyproject.toml index 8f2e07d..7a6652e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dagster-uc" -version = "0.3.0" +version = "0.3.1" authors = [ {name = "Stefan Verbruggen"}, {name = "Ion Koutsouris"},