diff --git a/lib/cli/src/crewai_cli/deploy/main.py b/lib/cli/src/crewai_cli/deploy/main.py index 3dedb7d98..6ed0a7ab8 100644 --- a/lib/cli/src/crewai_cli/deploy/main.py +++ b/lib/cli/src/crewai_cli/deploy/main.py @@ -155,11 +155,17 @@ class DeployCommand(BaseCommand, PlusAPIMixin): response = self.plus_api_client.deploy_by_name(self.project_name) elif uuid: _display_git_remote_help() - response = self._update_crew_from_zip(uuid, repository) + env_vars = fetch_and_json_env_file() + response = self._update_crew_from_zip(uuid, repository, env_vars) elif self.project_name: _display_git_remote_help() deployment_uuid = self._deployment_uuid_by_name() - response = self._update_crew_from_zip(deployment_uuid, repository) + env_vars = fetch_and_json_env_file() + response = self._update_crew_from_zip( + deployment_uuid, + repository, + env_vars, + ) else: self._standard_no_param_error_message() return @@ -304,6 +310,7 @@ class DeployCommand(BaseCommand, PlusAPIMixin): self, uuid: str, repository: git.Repository | None, + env_vars: dict[str, str], ) -> Any: """Update an existing deployment by uploading a project ZIP archive.""" if not self.project_name: @@ -313,7 +320,11 @@ class DeployCommand(BaseCommand, PlusAPIMixin): zip_file_path = create_project_zip(self.project_name, repository=repository) try: console.print("Uploading project ZIP...", style="bold blue") - return self.plus_api_client.update_crew_from_zip(uuid, zip_file_path) + return self.plus_api_client.update_crew_from_zip( + uuid, + zip_file_path, + env=env_vars, + ) finally: zip_file_path.unlink(missing_ok=True) diff --git a/lib/cli/tests/deploy/test_deploy_main.py b/lib/cli/tests/deploy/test_deploy_main.py index 9d6d73b1b..7a71ecef8 100644 --- a/lib/cli/tests/deploy/test_deploy_main.py +++ b/lib/cli/tests/deploy/test_deploy_main.py @@ -293,11 +293,13 @@ class TestDeployCommand(unittest.TestCase): mock_display.assert_called_once_with({"uuid": "test-uuid"}) @patch("crewai_cli.deploy.main.create_project_zip") + @patch("crewai_cli.deploy.main.fetch_and_json_env_file") @patch("crewai_cli.deploy.main.git.Repository") @patch("crewai_cli.deploy.main.DeployCommand._display_deployment_info") def test_deploy_with_uuid_without_remote_updates_from_zip( - self, mock_display, mock_repository, mock_create_project_zip + self, mock_display, mock_repository, mock_fetch_env, mock_create_project_zip ): + mock_fetch_env.return_value = {"ENV_VAR": "value"} mock_repository.return_value.origin_url.return_value = None mock_repository.return_value.create_initial_commit_if_needed.return_value = ( False @@ -311,17 +313,21 @@ class TestDeployCommand(unittest.TestCase): self.deploy_command.deploy(uuid="test-uuid", skip_validate=True) self.mock_client.update_crew_from_zip.assert_called_once_with( - "test-uuid", Path("/tmp/test_project.zip") + "test-uuid", + Path("/tmp/test_project.zip"), + env={"ENV_VAR": "value"}, ) self.mock_client.deploy_by_uuid.assert_not_called() mock_display.assert_called_once_with({"uuid": "test-uuid"}) @patch("crewai_cli.deploy.main.create_project_zip") + @patch("crewai_cli.deploy.main.fetch_and_json_env_file") @patch("crewai_cli.deploy.main.git.Repository") @patch("crewai_cli.deploy.main.DeployCommand._display_deployment_info") def test_deploy_with_project_name_without_remote_updates_from_zip( - self, mock_display, mock_repository, mock_create_project_zip + self, mock_display, mock_repository, mock_fetch_env, mock_create_project_zip ): + mock_fetch_env.return_value = {"ENV_VAR": "value"} mock_repository.return_value.origin_url.return_value = None mock_repository.return_value.create_initial_commit_if_needed.return_value = ( False @@ -341,7 +347,9 @@ class TestDeployCommand(unittest.TestCase): self.mock_client.crew_status_by_name.assert_called_once_with("test_project") self.mock_client.update_crew_from_zip.assert_called_once_with( - "test-uuid", Path("/tmp/test_project.zip") + "test-uuid", + Path("/tmp/test_project.zip"), + env={"ENV_VAR": "value"}, ) self.mock_client.deploy_by_name.assert_not_called() mock_display.assert_called_once_with({"uuid": "test-uuid"})