Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
1d4fe7b532 | |||
ddb984edf4 | |||
4d4b5f74cf |
60
build.py
60
build.py
@ -19,6 +19,8 @@ import yaml
|
||||
from jinja2 import Environment, BaseLoader
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
clean_images_counter = 0
|
||||
clean_images_limit_count = 0
|
||||
|
||||
ORG_DIR = Path("org")
|
||||
|
||||
@ -341,6 +343,7 @@ class DockerBuilder:
|
||||
def __init__(
|
||||
self,
|
||||
registry,
|
||||
overwrite_registry,
|
||||
branch,
|
||||
organization,
|
||||
overwrite_organization,
|
||||
@ -355,6 +358,7 @@ class DockerBuilder:
|
||||
self.org_dir = ORG_DIR
|
||||
self.images_dir = ORG_DIR / organization
|
||||
self.registry = registry
|
||||
self.overwrite_registry = overwrite_registry
|
||||
self.branch = branch
|
||||
self.organization = organization
|
||||
if overwrite_organization:
|
||||
@ -511,6 +515,15 @@ class DockerBuilder:
|
||||
tag = f":{tag}"
|
||||
return f"{registry}{self.overwrite_organization}/{image.base_name}{tag}"
|
||||
|
||||
def render_push_registry(self, image: Image, tag: str):
|
||||
if self.overwrite_registry:
|
||||
registry = self.overwrite_registry.rstrip("/") + "/"
|
||||
else:
|
||||
registry = ""
|
||||
if tag:
|
||||
tag = f":{tag}"
|
||||
return f"{registry}{self.overwrite_organization}/{image.base_name}{tag}"
|
||||
|
||||
def run(self, cmd, *args, **kwargs):
|
||||
if "check" not in kwargs:
|
||||
kwargs["check"] = True
|
||||
@ -778,16 +791,19 @@ class DockerBuilder:
|
||||
return
|
||||
|
||||
tags = self.tags.tags(self.branch, image, self.tasks)
|
||||
manifests = [self.render_full_tag(image, t) for t in tags]
|
||||
|
||||
for manifest in manifests:
|
||||
print(f"Push manifest {manifest}")
|
||||
for t in tags:
|
||||
manifest = self.render_full_tag(image, t)
|
||||
push_manifest = self.render_push_registry(image, t)
|
||||
|
||||
print(f"Source manifest {manifest}")
|
||||
print(f"Push manifest {push_manifest}")
|
||||
cmd = [
|
||||
"podman",
|
||||
"manifest",
|
||||
"push",
|
||||
manifest,
|
||||
f"docker://{manifest}",
|
||||
f"docker://{push_manifest}",
|
||||
]
|
||||
|
||||
if sign is not None:
|
||||
@ -795,6 +811,25 @@ class DockerBuilder:
|
||||
|
||||
self.run(cmd)
|
||||
|
||||
if clean_images_limit_count > 0:
|
||||
global clean_images_counter
|
||||
|
||||
if clean_images_limit_count <= clean_images_counter:
|
||||
cmd = [
|
||||
"podman",
|
||||
"rmi",
|
||||
"--all",
|
||||
"-f",
|
||||
]
|
||||
self.run(cmd,
|
||||
check=False,
|
||||
stderr=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL,
|
||||
)
|
||||
clean_images_counter = 0
|
||||
else:
|
||||
clean_images_counter += 1
|
||||
|
||||
|
||||
class ImagesInfo:
|
||||
def __init__(self):
|
||||
@ -865,9 +900,22 @@ def parse_args():
|
||||
"-r",
|
||||
"--registry",
|
||||
default="gitea.basealt.ru",
|
||||
help="source registry",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--clean-images-limit",
|
||||
default="5",
|
||||
type=int,
|
||||
help="limit count of local images, '0' - no clean mode",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--overwrite-registry",
|
||||
default="gitea.basealt.ru",
|
||||
help="destination registry",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--overwrite-organization",
|
||||
help="destination organization",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
@ -955,6 +1003,9 @@ def parse_args():
|
||||
args.branches = set(args.branches) - set(args.skip_branches)
|
||||
args.images = set(args.images) - set(args.skip_images)
|
||||
|
||||
global clean_images_limit_count
|
||||
clean_images_limit_count = args.clean_images_limit
|
||||
|
||||
return args
|
||||
|
||||
|
||||
@ -978,6 +1029,7 @@ def main():
|
||||
for branch in args.branches:
|
||||
db = DockerBuilder(
|
||||
args.registry,
|
||||
args.overwrite_registry,
|
||||
branch,
|
||||
organization,
|
||||
args.overwrite_organization,
|
||||
|
Reference in New Issue
Block a user