public void cleanUp(ServiceSpec serviceSpec, BuildContext context) throws HyscaleException {
        String imageCleanUpPolicy = imageBuilderConfig.getImageCleanUpPolicy();

        ImageCleanUpPolicy cleanUpPolicy = ImageCleanUpPolicy.fromString(imageCleanUpPolicy);

        logger.debug("Image cleanup Policy {}", cleanUpPolicy);

        if (cleanUpPolicy == null) {
            cleanUpPolicy = ImageCleanUpPolicy.PRESERVE_N_RECENTLY_USED;
        }

        if (cleanUpPolicy == ImageCleanUpPolicy.PRESERVE_ALL) {
            logger.debug("Preserve all policy for image cleanup, no images to clean up.");
            return;
        }

        List<String> imageIds = null;
        Map<String, String> labels = imageMetadataProvider.getImageOwnerLabel();
        String imageName = getImageName(serviceSpec, cleanUpPolicy);

        imageIds = hyscaleDockerClient.getImageIds(imageName, labels);

        if (imageIds == null || imageIds.isEmpty()) {
            logger.debug("No images to clean");
            return;
        }

        if (ImageCleanUpPolicy.PRESERVE_N_RECENTLY_USED == cleanUpPolicy) {
            if (imageIds.size() > imageBuilderConfig.getNoOfPreservedImages()) {
                imageIds = imageIds.stream().skip(imageBuilderConfig.getNoOfPreservedImages())
                        .collect(Collectors.toList());
            } else {
                logger.debug("Not enough images avaialbe for cleaning");
                return;
            }
        }

        logger.debug("Images to be removed: {}", imageIds);
        hyscaleDockerClient.deleteImages(imageIds, USE_FORCE);
    }
This class is responsible for cleaning up local images
It uses User defined cleanup policy to clean up respective images
The images are fetched and cleaned up based on available docker client
image-builder/builder-services/src/main/java/io/hyscale/builder/services/cleanup/ImageCleanUpProcessor.java