From 48872e391743f716830cab3dc5b27ad738d600c7 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 7 Sep 2023 14:53:47 +0200 Subject: [PATCH] deb_autopkg: add building just all base images Adding a new command repo-build-baseimage that builds all (missing) base images for the targets used in given repo config. Signed-off-by: Enrico Weigelt, metux IT consult --- deb_autopkg/builder.py | 5 ++++- deb_autopkg/cmd.py | 14 ++++++++++++ deb_autopkg/tasks/all_baseimage.py | 21 ++++++++++++++++++ deb_autopkg/tasks/target_rootfs.py | 35 ++++++++++++++++++++++++++++++ repo-build-baseimage | 4 ++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 deb_autopkg/tasks/all_baseimage.py create mode 100644 deb_autopkg/tasks/target_rootfs.py create mode 100755 repo-build-baseimage diff --git a/deb_autopkg/builder.py b/deb_autopkg/builder.py index 373a2a8..105d485 100644 --- a/deb_autopkg/builder.py +++ b/deb_autopkg/builder.py @@ -2,7 +2,7 @@ # Copyright (C) Enrico Weigelt, metux IT consult from metux.util.task import TaskRunner -from .tasks import pkg_build, pkg_clone, all_clone, pool_build, pool_upload, pool_deploy +from .tasks import pkg_build, pkg_clone, all_clone, all_baseimage, pool_build, pool_upload, pool_deploy from metux.util.specobject import SpecError class Builder: @@ -22,6 +22,9 @@ def clone_package(self, name): def clone_all(self): return self._run(all_clone.alloc(self.conf)) + def baseimage_all(self): + return self._run(all_baseimage.alloc(self.conf)) + def build_pool(self, name): if name is None or name == '': name = self.conf['defaults::build-pool'] diff --git a/deb_autopkg/cmd.py b/deb_autopkg/cmd.py index 5a22999..0a6145a 100644 --- a/deb_autopkg/cmd.py +++ b/deb_autopkg/cmd.py @@ -46,6 +46,10 @@ def build_package(conffile, pkg): def clone_all(conffile): return Builder(load(conffile)).clone_all() +@cmdfunc +def baseimage_all(conffile): + return Builder(load(conffile)).baseimage_all() + @cmdfunc def get_builder(conffile): return Builder(load(conffile)) @@ -76,3 +80,13 @@ def tool_repo_build_pool(argv): return build_pool(argv[1], None) return build_pool(argv[1], argv[2]) + +@cmdfunc +def tool_repo_build_rootfs(argv): + if len(argv) < 2: + print("%s " % argv[0]) + print("") + print("Build root filesystems for targets in given config file") + return 1 + + return baseimage_all(argv[1]) diff --git a/deb_autopkg/tasks/all_baseimage.py b/deb_autopkg/tasks/all_baseimage.py new file mode 100644 index 0000000..a9eec69 --- /dev/null +++ b/deb_autopkg/tasks/all_baseimage.py @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# Copyright (C) Enrico Weigelt, metux IT consult + +from metux.util.task import Task +from .target_rootfs import alloc as target_rootfs_alloc +from .dckbp_clone import alloc as dckbp_clone_alloc + +""" Task: clone all package git repos""" +class BaseimageAllTask(Task): + + def get_subtasks(self): + conf = self.param['conf'] + tasks = [ dckbp_clone_alloc(conf) ] + + for t in conf.get_targets(): + tasks.append(target_rootfs_alloc(conf, t)) + + return tasks + +def alloc(conf): + return conf.cached_task_alloc('baseimage-all', BaseimageAllTask, { 'conf': conf }) diff --git a/deb_autopkg/tasks/target_rootfs.py b/deb_autopkg/tasks/target_rootfs.py new file mode 100644 index 0000000..329f458 --- /dev/null +++ b/deb_autopkg/tasks/target_rootfs.py @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# Copyright (C) Enrico Weigelt, metux IT consult + +from metux.util.task import Task +from os import environ +from copy import copy +from subprocess import call + +"""build for apt (docker-buildpackage)""" +class TargetBaseimageTask(Task): + + """[private]""" + def __init__(self, param): + Task.__init__(self, param) + self.target = param['target'] + self.conf = param['conf'] + + def do_run(self): + tgt = self.target + + env = copy(environ) + + self.log_info('building rootfs for target "%s"' % tgt['name']) + + if (call([self.conf.get_dckbp_cmd(), + '--create-baseimage', + '--target', + self.target['dck-buildpackage::target']], + env=env) != 0): + self.fail("rootfs build failed: "+tgt['name']) + + return True + +def alloc(conf, target): + return conf.cached_task_alloc('target-baseimage:'+target['name'], TargetBaseimageTask, { 'target': target }) diff --git a/repo-build-baseimage b/repo-build-baseimage new file mode 100755 index 0000000..45b2b72 --- /dev/null +++ b/repo-build-baseimage @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 +import sys, deb_autopkg +from deb_autopkg import cmd +sys.exit(cmd.tool_repo_build_rootfs(sys.argv))