Compare commits

..

No commits in common. "5a2c16ff28d9378c3da07e6ecfb75b153b7f37fc" and "bb6b8523a31fa6988f112c3a9f993e7ee1f2e56b" have entirely different histories.

4 changed files with 15 additions and 33 deletions

View file

@ -57,6 +57,8 @@ RUN rm -rf /etc/yum.repos.d/*.repo /get_arch
RUN pip install awscli RUN pip install awscli
ARG BRANCH=r9
RUN git clone https://git.resf.org/sig_core/kickstarts.git --branch $BRANCH /kickstarts
RUN pip install 'git+https://git.resf.org/sig_core/toolkit.git@devel#egg=empanadas&subdirectory=iso/empanadas' RUN pip install 'git+https://git.resf.org/sig_core/toolkit.git@devel#egg=empanadas&subdirectory=iso/empanadas'

View file

@ -65,8 +65,7 @@ config = {
"x86_64": "amd64", "x86_64": "amd64",
"aarch64": "arm64", "aarch64": "arm64",
"ppc64le": "ppc64le", "ppc64le": "ppc64le",
"s390x": "s390x", "s390x": "s390x"
"i686": "386"
}, },
"aws_region": "us-east-2", "aws_region": "us-east-2",
"bucket": "resf-empanadas", "bucket": "resf-empanadas",

View file

@ -55,9 +55,6 @@ STORAGE_DIR = pathlib.Path("/var/lib/imagefactory/storage")
KICKSTART_PATH = pathlib.Path(os.environ.get("KICKSTART_PATH", "/kickstarts")) KICKSTART_PATH = pathlib.Path(os.environ.get("KICKSTART_PATH", "/kickstarts"))
BUILDTIME = datetime.datetime.utcnow() BUILDTIME = datetime.datetime.utcnow()
CMD_PARAM_T = List[Union[str, Callable[..., str]]]
@define(kw_only=True) @define(kw_only=True)
class ImageBuild: class ImageBuild:
architecture: Architecture = field() architecture: Architecture = field()
@ -92,12 +89,10 @@ class ImageBuild:
self.command_args = self._command_args() self.command_args = self._command_args()
self.package_args = self._package_args() self.package_args = self._package_args()
self.common_args = self._common_args() self.common_args = self._common_args()
self.kickstart_arg = self.kickstart_imagefactory_args()
self.metadata = pathlib.Path(self.outdir, "metadata.json") self.metadata = pathlib.Path(self.outdir, "metadata.json")
self.checkout_kickstarts()
self.kickstart_arg = self.kickstart_imagefactory_args()
# Yes, this is gross. I'll fix it later. # Yes, this is gross. I'll fix it later.
if self.image_type in ["Container"]: if self.image_type in ["Container"]:
self.stage_commands = [ self.stage_commands = [
@ -117,6 +112,8 @@ class ImageBuild:
["/prep-azure.sh", lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", f"{STORAGE_DIR}"], ["/prep-azure.sh", lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", f"{STORAGE_DIR}"],
["cp", lambda: f"{STORAGE_DIR}/{self.target_uuid}.vhd", f"{self.outdir}/{self.outname}.vhd"] ["cp", lambda: f"{STORAGE_DIR}/{self.target_uuid}.vhd", f"{self.outdir}/{self.outname}.vhd"]
] ]
# ["qemu-img", "resize", "-f", "raw", lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", lambda: f"{self.rounded_size()}"],
# ["qemu-img", "convert", "-f", "raw", "-o", "subformat=fixed,force_size" ,"-O", "vpc", lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", f"{self.outdir}/{self.outname}.vhd"]
if self.image_type in ["Vagrant"]: if self.image_type in ["Vagrant"]:
_map = { _map = {
"Vbox": "vmdk", "Vbox": "vmdk",
@ -150,27 +147,12 @@ class ImageBuild:
finally: finally:
f.flush() f.flush()
def checkout_kickstarts(self) -> int: # def rounded_size(self) -> int:
cmd = ["git", "clone", "--branch", f"r{self.architecture.major}", rlvars['livemap']['git_repo'], f"{KICKSTART_PATH}"] # # Azure images need to be rounded to the nearest 1MB boundary.
ret, out, err, _ = self.runCmd(cmd, search=False) # MB=1024*1024
log.debug(out) #
log.debug(err) # raw_size = pathlib.Path(STORAGE_DIR},f"{self.target_uuid}.body").stat().st_size
if ret > 0: # rounded_size = raw
ret = self.pull_kickstarts()
return ret
def pull_kickstarts(self) -> int:
cmd: CMD_PARAM_T = ["git", "-C", f"{KICKSTART_PATH}", "reset", "--hard", "HEAD"]
ret, out, err, _ = self.runCmd(cmd, search=False)
log.debug(out)
log.debug(err)
if ret == 0:
cmd = ["git", "-C", f"{KICKSTART_PATH}", "pull"]
ret, out, err, _ = self.runCmd(cmd, search=False)
log.debug(out)
log.debug(err)
return ret
def output_name(self) -> Tuple[pathlib.Path, str]: 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}" directory = f"Rocky-{self.architecture.major}-{self.type_variant}-{self.architecture.version}-{BUILDTIME.strftime('%Y%m%d')}.{self.release}"
@ -319,7 +301,7 @@ class ImageBuild:
log.info(f"Build complete! Output available in {self.outdir}/") log.info(f"Build complete! Output available in {self.outdir}/")
return 0 return 0
def runCmd(self, command: CMD_PARAM_T, search: bool = True) -> Tuple[int, Union[bytes,None], Union[bytes,None], Union[str,None]]: def runCmd(self, command: List[Union[str, Callable]], search: bool = True) -> Tuple[int, Union[bytes,None], Union[bytes,None], Union[str,None]]:
prepared, _ = self.prepare_command(command) prepared, _ = self.prepare_command(command)
log.info(f"Running command: {' '.join(prepared)}") log.info(f"Running command: {' '.join(prepared)}")
@ -350,7 +332,7 @@ class ImageBuild:
return res return res
def prepare_command(self, command_list: CMD_PARAM_T) -> Tuple[List[str],List[None]]: def prepare_command(self, command_list: List[Union[str, Callable]]) -> Tuple[List[str],List[None]]:
""" """
Commands may be a callable, which should be a lambda to be evaluated at Commands may be a callable, which should be a lambda to be evaluated at
preparation time with available locals. This can be used to, among preparation time with available locals. This can be used to, among

View file

@ -21,8 +21,7 @@ SOURCE_AMI_NAME=$(aws --profile resf-ami ec2 describe-images \
# Enforce a name structure # Enforce a name structure
# Rocky-8-ec2-8.6-20220515.0.x86_64 # Rocky-8-ec2-8.6-20220515.0.x86_64
pat="Rocky-[89]-[Ee][Cc]2-[89]\.[0-9]-[0-9]+\.[0-9]+\.((aarch|x86_)64|ppc64le|s390x)" if [[ ! "${SOURCE_AMI_NAME}" =~ Rocky-[89]-ec2-[89]\.[0-9]-[0-9]+\.[0-9]+\.((aarch|x86_)64|ppc64le|s390x) ]]; then
if [[ ! "${SOURCE_AMI_NAME}" =~ $pat ]]; then
echo "Bad source ami (${SOURCE_AMI_NAME}). Exiting." echo "Bad source ami (${SOURCE_AMI_NAME}). Exiting."
exit 1 exit 1
fi fi