Esempio n. 1
0
def delete_project_environment_images(project_uuid):
    """Delete environment images of a project.

    All environment images related to the project are removed
    from the environment, running environment builds are stopped
    and removed from the db. Dangling docker images are also removed.

    Args:
        project_uuid:
    """

    # cleanup references to the builds and dangling images
    # of all environments of this project
    delete_project_builds(project_uuid)
    delete_project_dangling_images(project_uuid)

    filters = {
        "label": [
            f"_orchest_env_build_is_intermediate=0",
            f"_orchest_project_uuid={project_uuid}",
        ]
    }
    images_to_remove = docker_images_list_safe(docker_client, filters=filters)

    image_remove_exceptions = []
    # try with repeat because there might be a race condition
    # where the aborted runs are still using the image
    for img in images_to_remove:
        docker_images_rm_safe(docker_client, img.id)
    def _collateral(self, project_uuid: str, environment_uuid: str):
        image_name = _config.ENVIRONMENT_IMAGE_NAME.format(
            project_uuid=project_uuid, environment_uuid=environment_uuid)

        delete_project_environment_dangling_images(project_uuid,
                                                   environment_uuid)

        # Try with repeat because there might be a race condition where
        # the aborted runs are still using the image.
        docker_images_rm_safe(docker_client, image_name)
    def _collateral(self, project_uuid: str):
        filters = {
            "label": [
                "_orchest_env_build_is_intermediate=0",
                f"_orchest_project_uuid={project_uuid}",
            ]
        }
        images_to_remove = docker_images_list_safe(docker_client,
                                                   filters=filters)

        # Try with repeat because there might be a race condition
        # where the aborted runs are still using the image.
        for img in images_to_remove:
            docker_images_rm_safe(docker_client, img.id)
Esempio n. 4
0
    def delete(self, project_uuid, environment_uuid):
        """Removes an environment image given project_uuid and image_uuid

        Will stop any run or experiment making use of this environment.
        """
        image_name = _config.ENVIRONMENT_IMAGE_NAME.format(
            project_uuid=project_uuid, environment_uuid=environment_uuid)

        # stop all interactive runs making use of the environment
        int_runs = interactive_runs_using_environment(project_uuid,
                                                      environment_uuid)
        for run in int_runs:
            stop_pipeline_run(run.run_uuid)

        # stop all experiments making use of the environment
        exps = experiments_using_environment(project_uuid, environment_uuid)
        for exp in exps:
            stop_experiment(exp.experiment_uuid)

        # cleanup references to the builds and dangling images
        # of this environment
        delete_project_environment_builds(project_uuid, environment_uuid)
        delete_project_environment_dangling_images(project_uuid,
                                                   environment_uuid)

        # try with repeat because there might be a race condition
        # where the aborted runs are still using the image
        docker_images_rm_safe(docker_client, image_name)

        return (
            {
                "message":
                f"Environment image {image_name} was successfully deleted"
            },
            200,
        )