builds, initial testing builds, packaging, ci workflow
Some checks failed
Comprehensive CI/CD Pipeline / Build and Test (push) Failing after 2m1s
Comprehensive CI/CD Pipeline / Security Audit (push) Successful in 46s
Comprehensive CI/CD Pipeline / Package Validation (push) Successful in 1m7s
Comprehensive CI/CD Pipeline / Status Report (push) Has been skipped
Some checks failed
Comprehensive CI/CD Pipeline / Build and Test (push) Failing after 2m1s
Comprehensive CI/CD Pipeline / Security Audit (push) Successful in 46s
Comprehensive CI/CD Pipeline / Package Validation (push) Successful in 1m7s
Comprehensive CI/CD Pipeline / Status Report (push) Has been skipped
This commit is contained in:
parent
0e80b08b0a
commit
45c124637b
25 changed files with 1994 additions and 6 deletions
57
plugins/cache_plugin.py
Normal file
57
plugins/cache_plugin.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Cache plugin for deb-mock
|
||||
Provides caching functionality for build artifacts and dependencies
|
||||
"""
|
||||
|
||||
from deb_mock.plugins.base import BasePlugin
|
||||
from deb_mock.plugins.registry import PluginInfo
|
||||
import os
|
||||
import hashlib
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
class CachePlugin(BasePlugin):
|
||||
"""Plugin for caching build artifacts and dependencies"""
|
||||
|
||||
def __init__(self, plugin_manager, config, deb_mock):
|
||||
super().__init__(plugin_manager, config, deb_mock)
|
||||
self.cache_dir = Path("/var/cache/deb-mock")
|
||||
self.artifact_cache = self.cache_dir / "artifacts"
|
||||
self.dependency_cache = self.cache_dir / "dependencies"
|
||||
|
||||
def pre_build_hook(self, environment, package_info):
|
||||
"""Check cache before building"""
|
||||
cache_key = self._generate_cache_key(package_info)
|
||||
cached_artifact = self.artifact_cache / f"{cache_key}.deb"
|
||||
|
||||
if cached_artifact.exists():
|
||||
self.logger.info(f"Found cached artifact: {cached_artifact}")
|
||||
return {"cached": True, "artifact": cached_artifact}
|
||||
|
||||
return {"cached": False}
|
||||
|
||||
def post_build_hook(self, environment, package_info, build_result):
|
||||
"""Cache build artifacts after successful build"""
|
||||
if build_result.get("success"):
|
||||
cache_key = self._generate_cache_key(package_info)
|
||||
artifact_path = build_result.get("artifact_path")
|
||||
|
||||
if artifact_path and os.path.exists(artifact_path):
|
||||
cached_artifact = self.artifact_cache / f"{cache_key}.deb"
|
||||
shutil.copy2(artifact_path, cached_artifact)
|
||||
self.logger.info(f"Cached artifact: {cached_artifact}")
|
||||
|
||||
def _generate_cache_key(self, package_info):
|
||||
"""Generate a cache key based on package information"""
|
||||
key_data = f"{package_info.get('name', '')}-{package_info.get('version', '')}-{package_info.get('architecture', '')}"
|
||||
return hashlib.md5(key_data.encode()).hexdigest()
|
||||
|
||||
# Plugin registration
|
||||
PLUGIN_INFO = PluginInfo(
|
||||
name="cache",
|
||||
version="1.0.0",
|
||||
description="Caching plugin for build artifacts and dependencies",
|
||||
author="Deb-Mock Team",
|
||||
plugin_class=CachePlugin
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue