forked from sig_core/toolkit
Checkout kickstarts on every run, instead of when building the image
This commit is contained in:
parent
7c16cc2cdc
commit
5a2c16ff28
@ -57,8 +57,6 @@ 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'
|
||||||
|
|
||||||
|
@ -55,6 +55,9 @@ 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()
|
||||||
@ -89,10 +92,12 @@ 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 = [
|
||||||
@ -112,8 +117,6 @@ 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",
|
||||||
@ -147,12 +150,27 @@ class ImageBuild:
|
|||||||
finally:
|
finally:
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
# def rounded_size(self) -> int:
|
def checkout_kickstarts(self) -> int:
|
||||||
# # Azure images need to be rounded to the nearest 1MB boundary.
|
cmd = ["git", "clone", "--branch", f"r{self.architecture.major}", rlvars['livemap']['git_repo'], f"{KICKSTART_PATH}"]
|
||||||
# MB=1024*1024
|
ret, out, err, _ = self.runCmd(cmd, search=False)
|
||||||
#
|
log.debug(out)
|
||||||
# raw_size = pathlib.Path(STORAGE_DIR},f"{self.target_uuid}.body").stat().st_size
|
log.debug(err)
|
||||||
# rounded_size = raw
|
if ret > 0:
|
||||||
|
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}"
|
||||||
@ -301,7 +319,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: List[Union[str, Callable]], search: bool = True) -> Tuple[int, Union[bytes,None], Union[bytes,None], Union[str,None]]:
|
def runCmd(self, command: CMD_PARAM_T, 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)}")
|
||||||
|
|
||||||
@ -332,7 +350,7 @@ class ImageBuild:
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def prepare_command(self, command_list: List[Union[str, Callable]]) -> Tuple[List[str],List[None]]:
|
def prepare_command(self, command_list: CMD_PARAM_T) -> 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
|
||||||
|
Loading…
Reference in New Issue
Block a user