Hi Team! I am wondering what are the different rec...
# questions
g
Hi Team! I am wondering what are the different recommended ways to set up a dev/staging/prod model deployment in Kedro. I can see one based on separate dev/staging/prod kedro envs, but is there other way (with tags or modular pipelines?)? Thanks 🙂
h
Someone will reply to you shortly. In the meantime, this might help:
d
It’s very much supposed to be driven with the Kedro envs like you’ve pointed out. The two other ancillary pieces are the: • you can set the env with environment variables • Hooks can do conditional logic using the env key Below is an example of a hook I have in place to stop anyone doing a production run by accident
Copy code
class PipelineGuardHooks:
    def __init__(self) -> None:
        self._logger = logging.getLogger(__name__)

    @hook_impl
    def before_pipeline_run(self, run_params: dict[str, str]) -> None:
        """Kill execution if someone is trying to run `prod` or `stg` outside of GitOps workflow"""
        is_ci = os.environ.get("CI") == "true"
        is_github_repo = os.environ.get("GITHUB_REPOSITORY") is not None
        is_github_actions = is_ci and is_github_repo
        kedro_env = run_params.get("env", os.environ.get("KEDRO_ENV"))
        is_protected_environment = kedro_env in ["prod", "stg"]
        if is_github_actions is False and is_protected_environment is False:
            <http://self._logger.info|self._logger.info>(f'Running pipeline "{kedro_env}" on CI/CD')
        else:
            self._logger.error(
                f'Cannot run pipeline for "{kedro_env}" outside of CI/CD. Killing process.'
            )
            sys.exit(1)
👍 1
🙌 1
g
Thanks @datajoely. It is also quite nice to always know which deployment is targeted with run_params inside any kedro run. For some context, I was wondering how I should make sure kedro-dagster enables deployment patterns used in kedro.
❤️ 1