diff --git a/iso/empanadas/empanadas/backends/imagefactory.py b/iso/empanadas/empanadas/backends/imagefactory.py index 44a1ebc..70ece6e 100644 --- a/iso/empanadas/empanadas/backends/imagefactory.py +++ b/iso/empanadas/empanadas/backends/imagefactory.py @@ -149,8 +149,7 @@ class ImageFactoryBackend(BackendInterface): if (res := all(ret > 0 for ret in returns) > 0): raise Exception(res) - ret = self.copy() - return ret + return 0 def checkout_kickstarts(self) -> int: cmd = ["git", "clone", "--branch", f"r{self.ctx.architecture.major}", @@ -291,3 +290,29 @@ class ImageFactoryBackend(BackendInterface): if self.stage_commands: self.stage_commands.append(["cp", "-v", lambda: f"{STORAGE_DIR}/{self.target_uuid}.meta", f"{self.ctx.outdir}/build.meta"]) + + def prepare_vagrant(self, options): + """Setup the output directory for the Vagrant type variant, dropping templates as required""" + + templates = {} + templates['Vagrantfile'] = self.ctx.tmplenv.get_template(f"vagrant/Vagrantfile.{self.ctx.variant}") + templates['metadata.json'] = self.ctx.tmplenv.get_template('vagrant/metadata.tmpl.json') + templates['info.json'] = self.ctx.tmplenv.get_template('vagrant/info.tmpl.json') + + if self.ctx.variant == "VMware": + templates[f"{self.ctx.outname}.vmx"] = self.ctx.tmplenv.get_template('vagrant/vmx.tmpl') + + if self.ctx.variant == "Vbox": + templates['box.ovf'] = self.ctx.tmplenv.get_template('vagrant/box.tmpl.ovf') + + if self.ctx.variant == "Libvirt": + # Libvirt vagrant driver expects the qcow2 file to be called box.img. + qemu_command_index = [i for i, d in enumerate(self.stage_commands) if d[0] == "qemu-img"][0] + self.stage_commands.insert(qemu_command_index+1, ["mv", f"{self.ctx.outdir}/{self.ctx.outname}.qcow2", f"{self.ctx.outdir}/box.img"]) + + for name, template in templates.items(): + utils.render_template(f"{self.ctx.outdir}/{name}", template, + name=self.ctx.outname, + arch=self.ctx.architecture.name, + options=options + ) diff --git a/iso/empanadas/empanadas/backends/kiwi.py b/iso/empanadas/empanadas/backends/kiwi.py index c9a5a2e..7a3d7dc 100644 --- a/iso/empanadas/empanadas/backends/kiwi.py +++ b/iso/empanadas/empanadas/backends/kiwi.py @@ -20,11 +20,35 @@ import sys # TODO(neil): this should be part of the config, somewhere temp = AttributeDict( { + "Azure": { + "kiwiType": "oem", + "kiwiProfile": "Cloud-Azure", + "fileType": "qcow2", + "outputKey": "disk_format_image", + }, + "OCP": { + "kiwiType": "oem", + "kiwiProfile": "Cloud-OCP", + "fileType": "qcow2", + "outputKey": "disk_format_image", + }, "GenericCloud": { "kiwiType": "oem", "kiwiProfile": "Cloud-GenericCloud", "fileType": "qcow2", - "outputKey": "disk_format_image" + "outputKey": "disk_format_image", + }, + "EC2": { + "kiwiType": "oem", + "kiwiProfile": "Cloud-EC2", + "fileType": "qcow2", + "outputKey": "disk_format_image", + }, + "Vagrant": { + "kiwiType": "oem", + "kiwiProfile": "Vagrant", + "fileType": "box", + "outputKey": "disk_format_image", }, "Container": { "kiwiType": "oci", @@ -117,7 +141,7 @@ class KiwiBackend(BackendInterface): def run_mock_command(self, mock_command: List[str]): mock_args = ["--configdir", "/workdir/mock-rocky-configs/etc/mock", "-r", f"rl-9-{self.ctx.architecture.name}-core-infra"] - if self.ctx.image_type == 'GenericCloud': + if self.ctx.image_type != 'Container': mock_args.append("--isolation=simple") command = [ "mock", diff --git a/iso/empanadas/empanadas/builders/imagebuild.py b/iso/empanadas/empanadas/builders/imagebuild.py index d2d31ee..3e128f2 100644 --- a/iso/empanadas/empanadas/builders/imagebuild.py +++ b/iso/empanadas/empanadas/builders/imagebuild.py @@ -105,7 +105,7 @@ class ImageBuild: # pylint: disable=too-few-public-methods ) return template - def copy(self, skip=False) -> int: + def upload(self, skip=False) -> int: if not skip: self.log.info("Copying files to output directory") copy_command = ["aws", "s3", "cp", "--recursive", f"{self.outdir}/", diff --git a/iso/empanadas/empanadas/builders/utils.py b/iso/empanadas/empanadas/builders/utils.py index 631894f..3da9bf5 100644 --- a/iso/empanadas/empanadas/builders/utils.py +++ b/iso/empanadas/empanadas/builders/utils.py @@ -11,33 +11,6 @@ BYTES_NONE_T = Union[bytes, None] CMD_RESULT_T = Tuple[int, BYTES_NONE_T, BYTES_NONE_T, STR_NONE_T] -# def prepare_vagrant(options): -# """Setup the output directory for the Vagrant type variant, dropping templates as required""" -# file_loader = FileSystemLoader(f"{_rootdir}/templates") -# tmplenv = Environment(loader=file_loader) -# -# templates = {} -# templates['Vagrantfile'] = tmplenv.get_template(f"vagrant/Vagrantfile.{self.variant}") -# templates['metadata.json'] = tmplenv.get_template('vagrant/metadata.tmpl.json') -# templates['info.json'] = tmplenv.get_template('vagrant/info.tmpl.json') -# -# if self.variant == "VMware": -# templates[f"{self.outname}.vmx"] = tmplenv.get_template('vagrant/vmx.tmpl') -# -# if self.variant == "Vbox": -# templates['box.ovf'] = tmplenv.get_template('vagrant/box.tmpl.ovf') -# -# if self.variant == "Libvirt": -# # Libvirt vagrant driver expects the qcow2 file to be called box.img. -# qemu_command_index = [i for i, d in enumerate(self.stage_commands) if d[0] == "qemu-img"][0] -# self.stage_commands.insert(qemu_command_index+1, ["mv", f"{self.outdir}/{self.outname}.qcow2", f"{self.outdir}/box.img"]) -# -# for name, template in templates.items(): -# self.render_template(f"{self.outdir}/{name}", template, -# name=self.outname, -# arch=self.architecture.name, -# options=options -# ) def render_template(path, template, **kwargs) -> pathlib.Path: diff --git a/iso/empanadas/empanadas/scripts/build_image.py b/iso/empanadas/empanadas/scripts/build_image.py index a2110ed..3da3518 100644 --- a/iso/empanadas/empanadas/scripts/build_image.py +++ b/iso/empanadas/empanadas/scripts/build_image.py @@ -35,6 +35,9 @@ parser.add_argument('--kube', action='store_true', parser.add_argument('--timeout', type=str, help="change timeout for imagefactory build process", required=False, default='3600') +parser.add_argument('--backend', type=str, + help="which backend to use (kiwi|imagefactory)", + required=False, default='kiwi') results = parser.parse_args() @@ -65,9 +68,8 @@ def run(): arches = rlvars['allowed_arches'] if results.kube else [platform.uname().machine] for architecture in arches: - if results.type in ["Container", "GenericCloud"]: - backend = KiwiBackend( - ) + if results.backend == "kiwi": + backend = KiwiBackend() else: backend = ImageFactoryBackend( kickstart_dir="kickstart" if results.kickstartdir else "os", @@ -104,3 +106,10 @@ def run(): method() else: log.fatal(f"Unable to execute {stage}") + + if 'upload' in skip_stages: + return + + log.info("Final stage - Upload") + + IB.upload(skip='upload' in skip_stages)