Various image building changes

* Add UBI container specification
* Change ouput path to simplify copying operations
* Install patches for imagefactory and fixed version of oz for RHEL in
  container
    * Please ignore the RPM in this repo for now...
* Add conversion steps for Vagrant, EC2 images
* Fix KSes if they have a $basearch variable by subtitution
* Add usefbx variable to ensure we have an output for debugging
This commit is contained in:
Neil Hanlon 2022-07-08 13:26:07 -04:00
parent 9e9955a0de
commit 767362aceb
Signed by untrusted user: neil
GPG Key ID: 705BC21EC3C70F34
6 changed files with 60 additions and 13 deletions

View File

@ -43,6 +43,12 @@ RUN dnf install -y \
RUN sed -i -e 's/# memory = 1024/memory = 2048/' /etc/oz/oz.cfg
COPY imagefactory.patch /
COPY oz.rpm /
RUN dnf -y install /oz.rpm
RUN (cd /usr/lib/python3.10/site-packages/; patch -p1 </imagefactory.patch)
RUN ssh-keygen -t rsa -q -f "$HOME/.ssh/id_rsa" -N ""
RUN dnf clean all
RUN rm -rf /etc/yum.repos.d/*.repo /get_arch
@ -52,7 +58,7 @@ RUN rm -rf /etc/yum.repos.d/*.repo /get_arch
RUN pip install awscli
ENV BRANCH r9
RUN git clone https://git.rockylinux.org/rocky/kickstarts.git --branch $BRANCH /kickstarts
RUN git clone https://git.resf.org/sig_core/kickstarts.git --branch $BRANCH /kickstarts
# devel only
# COPY . /empanadas

View File

@ -103,7 +103,7 @@ for conf in glob.iglob(f"{_rootdir}/sig/*.yaml"):
ALLOWED_TYPE_VARIANTS = {
"Azure": None,
"Container": ["Base", "Minimal"],
"Container": ["Base", "Minimal", "UBI"],
"EC2": None,
"GenericCloud": None,
"Vagrant": ["Libvirt", "VBox"]

View File

@ -84,8 +84,7 @@ class ImageBuild:
if not self.tdl_path:
exit(2)
self.type_variant = self.type_variant_name()
self.outname = self.output_name()
self.outdir = pathlib.Path(f"/tmp/{self.outname}")
self.outdir, self.outname = self.output_name()
self.out_type = self.image_format()
self.command_args = self._command_args()
self.package_args = self._package_args()
@ -94,14 +93,29 @@ class ImageBuild:
self.metadata = pathlib.Path(self.outdir, "metadata.json")
if self.image_type == "Container":
# Yes, this is gross. I'll fix it later.
if self.image_type in ["Container"]:
self.stage_commands = [
["tar", "-C", f"{self.outdir}", "--strip-components=1", "-x", "-f", lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", "*/layer.tar"]
]
if self.image_type in ["GenericCloud", "EC2"]:
if self.image_type in ["GenericCloud"]:
self.stage_commands = [
["qemu-img", "convert", "-f", "raw", "-O", "qcow2", lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", f"{self.outdir}/{self.outname}.qcow2"]
]
if self.image_type in ["EC2"]:
self.stage_commands = [
["qemu-img", "convert", "-f", "raw", "-O", "qcow2", lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", f"{self.outdir}/{self.outname}.qcow2"]
]
if self.image_type in ["Vagrant"]:
_map = {
"VBox": "vmdk",
"Libvirt": "qcow2"
}
output = f"{_map[self.variant]}" #type: ignore
self.stage_commands = [
["qemu-img", "convert", "-f", "raw", "-O", output, lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", f"{self.outdir}/{self.outname}.{output}"]
]
try:
os.mkdir(self.outdir)
@ -122,11 +136,14 @@ class ImageBuild:
finally:
f.flush()
def output_name(self):
return f"Rocky-{self.architecture.major}-{self.type_variant}-{self.architecture.version}-{BUILDTIME.strftime('%Y%m%d')}.{self.release}.{self.architecture.name}"
def output_name(self) -> Tuple[pathlib.Path, str]:
directory = f"Rocky-{self.architecture.major}-{self.type_variant}-{self.architecture.version}-{BUILDTIME.strftime('%Y%m%d')}.{self.release}"
name = f"{directory}.{self.architecture.name}"
outdir = pathlib.Path(f"/tmp/", directory)
return outdir, name
def type_variant_name(self):
return self.image_type if not self.variant else f"{self.image_type}-{self.variant.capitalize()}"
return self.image_type if not self.variant else f"{self.image_type}-{self.variant}"
def _command_args(self):
args_mapping = {
@ -207,7 +224,9 @@ class ImageBuild:
def copy_command(self) -> List[str]:
copy_command = ["aws", "s3", "cp", "--recursive", f"{self.outdir}/", f"s3://resf-empanadas/buildimage-{ self.outname }/{ BUILDTIME.strftime('%s') }/"]
copy_command = ["aws", "s3", "cp", "--recursive", f"{self.outdir}/",
f"s3://resf-empanadas/buildimage-{self.architecture.version}-{self.architecture.name}/{ self.outname }/{ BUILDTIME.strftime('%s') }/"
]
return copy_command
@ -215,6 +234,8 @@ class ImageBuild:
if self.base_uuid:
return 0
self.fix_ks()
ret, out, err, uuid = self.runCmd(self.build_command())
if uuid:
self.base_uuid = uuid.rstrip()
@ -238,11 +259,11 @@ class ImageBuild:
def stage(self) -> int:
""" Stage the artifacst from wherever they are (unpacking and converting if needed)"""
if not self.stage_commands:
if not hasattr(self,'stage_commands'):
return 0
returns = []
for command in self.stage_commands:
for command in self.stage_commands: #type: ignore
ret, out, err, _ = self.runCmd(command, search=False)
returns.append(ret)
@ -318,6 +339,9 @@ class ImageBuild:
if stderr:
log_lines("Command STDERR", stderr)
def fix_ks(self):
self.runCmd(["sed", "-i", f"s,$basearch,{self.architecture.name},", self.kickstart_arg[-1]])
def render_kubernetes_job(self):
commands = [self.build_command(), self.package_command(), self.copy_command()]
if not self.job_template:

View File

@ -11,6 +11,7 @@
<extra_command>rpm -qa --qf '%{NAME},%{VERSION},%{RELEASE},%{ARCH},%{EPOCH},%{SIZE},%{SIGMD5},%{BUILDTIME}
'</extra_command>
</icicle>
<kernelparam>console=tty0 inst.usefbx</kernelparam>
</os>
<description>Rocky-{{major}}-{{type}}-{{version_variant}}.{{iso8601date}}.{{release}}.{{architecture}} Generated on {{utcnow}}</description>
<disk>

View File

@ -0,0 +1,16 @@
diff --git a/imagefactory_plugins/TinMan/TinMan.info b/imagefactory_plugins/TinMan/TinMan.info
index bd61a02..00a8112 100644
--- a/imagefactory_plugins/TinMan/TinMan.info
+++ b/imagefactory_plugins/TinMan/TinMan.info
@@ -3,7 +3,10 @@
"targets": [ ["Fedora", null, null], ["RHEL-6", null, null], ["RHEL-5", null, null],
["Ubuntu", null, null], ["CentOS-6", null, null], ["CentOS-5", null, null],
["ScientificLinux-6", null, null], ["ScientificLinux-5", null, null], ["OpenSUSE", null, null],
- [ "RHEL-7", null, null ], [ "CentOS-7", null, null ], [ "ScientificLinux-7", null, null ] ],
+ [ "RHEL-7", null, null ], [ "CentOS-7", null, null ], [ "ScientificLinux-7", null, null ],
+ [ "RHEL-8", null, null ], [ "CentOS-8", null, null ], [ "Rocky-8", null, null ],
+ [ "RHEL-9", null, null ], [ "CentOS-9", null, null ], [ "Rocky-9", null, null ]
+ ],
"description": "Plugin to support most Oz customize capable guest types",
"maintainer": {
"name": "Red Hat, Inc.",

BIN
iso/empanadas/oz.rpm Normal file

Binary file not shown.