Build azure images, too
This commit is contained in:
parent
767362aceb
commit
3cccd03d55
1
iso/empanadas/.gitignore
vendored
1
iso/empanadas/.gitignore
vendored
@ -2,3 +2,4 @@ __pycache__/
|
|||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
*.so
|
*.so
|
||||||
|
Containerfile*.devel
|
||||||
|
@ -60,13 +60,11 @@ RUN pip install awscli
|
|||||||
ENV BRANCH r9
|
ENV BRANCH r9
|
||||||
RUN git clone https://git.resf.org/sig_core/kickstarts.git --branch $BRANCH /kickstarts
|
RUN git clone https://git.resf.org/sig_core/kickstarts.git --branch $BRANCH /kickstarts
|
||||||
|
|
||||||
# devel only
|
|
||||||
# COPY . /empanadas
|
|
||||||
# RUN pip install -e /empanadas
|
|
||||||
|
|
||||||
# prod
|
|
||||||
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'
|
||||||
|
|
||||||
ENV LIBGUESTFS_BACKEND direct
|
ENV LIBGUESTFS_BACKEND direct
|
||||||
|
|
||||||
|
COPY prep-azure.sh /prep-azure.sh
|
||||||
|
RUN chmod +x /prep-azure.sh
|
||||||
|
|
||||||
ENTRYPOINT ["/tini", "--"]
|
ENTRYPOINT ["/tini", "--"]
|
||||||
|
@ -106,6 +106,13 @@ class ImageBuild:
|
|||||||
self.stage_commands = [
|
self.stage_commands = [
|
||||||
["qemu-img", "convert", "-f", "raw", "-O", "qcow2", lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", f"{self.outdir}/{self.outname}.qcow2"]
|
["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 ["Azure"]:
|
||||||
|
self.stage_commands = [
|
||||||
|
["/empanadas/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"]
|
||||||
|
]
|
||||||
|
# ["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",
|
||||||
@ -136,6 +143,13 @@ class ImageBuild:
|
|||||||
finally:
|
finally:
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
|
# def rounded_size(self) -> int:
|
||||||
|
# # Azure images need to be rounded to the nearest 1MB boundary.
|
||||||
|
# MB=1024*1024
|
||||||
|
#
|
||||||
|
# raw_size = pathlib.Path(STORAGE_DIR},f"{self.target_uuid}.body").stat().st_size
|
||||||
|
# rounded_size = raw
|
||||||
|
|
||||||
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}"
|
||||||
name = f"{directory}.{self.architecture.name}"
|
name = f"{directory}.{self.architecture.name}"
|
||||||
@ -245,7 +259,7 @@ class ImageBuild:
|
|||||||
def package(self) -> int:
|
def package(self) -> int:
|
||||||
# Some build types don't need to be packaged by imagefactory
|
# Some build types don't need to be packaged by imagefactory
|
||||||
# @TODO remove business logic if possible
|
# @TODO remove business logic if possible
|
||||||
if self.image_type in ["GenericCloud", "EC2"]:
|
if self.image_type in ["GenericCloud", "EC2", "Azure"]:
|
||||||
self.target_uuid = self.base_uuid if hasattr(self, 'base_uuid') else ""
|
self.target_uuid = self.base_uuid if hasattr(self, 'base_uuid') else ""
|
||||||
|
|
||||||
if self.target_uuid:
|
if self.target_uuid:
|
||||||
|
55
iso/empanadas/prep-azure.sh
Executable file
55
iso/empanadas/prep-azure.sh
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat << EOF
|
||||||
|
$0: prep raw image for azure
|
||||||
|
|
||||||
|
usage: $0 raw_image
|
||||||
|
|
||||||
|
Description: Takes a raw image and calculates the closest whole-MegaByte,
|
||||||
|
resizing a copy of the raw image, and returning the path to the resize 'vpc'
|
||||||
|
image (a .vhd file to upload)
|
||||||
|
|
||||||
|
Dumps VHD in \$PWD by default. Override with ``OUTDIR=/path/to/outdir``
|
||||||
|
|
||||||
|
Don't try to compress it.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
local level="$1"; shift
|
||||||
|
local msg="$@"
|
||||||
|
local out=$([ "$level" == "error" ] && echo 2 || echo 1)
|
||||||
|
printf "[%s] %s: %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "${level}" "${msg}" >&${out}
|
||||||
|
if [[ "${level}" == "error" ]]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
MB=$((1024*1024)) # for calculations - 1048576 bytes
|
||||||
|
|
||||||
|
if ! command -v qemu-img 2>&1 >/dev/null; then
|
||||||
|
log error "Need qemu-img.";
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
rawdisk="$1"
|
||||||
|
|
||||||
|
if [[ -z "$rawdisk" ]]; then
|
||||||
|
usage
|
||||||
|
log error "need path to a raw image to prep"
|
||||||
|
fi
|
||||||
|
|
||||||
|
outdir="${2:-${PWD}}"
|
||||||
|
|
||||||
|
size=$(qemu-img info -f raw --output json "${rawdisk}" | gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}')
|
||||||
|
|
||||||
|
rounded_size=$(((($size+$MB-1)/$MB)*$MB)) # size (in bytes) + 1MB, less one, and rounded.
|
||||||
|
|
||||||
|
outfilename=$(basename ${rawdisk//body/vhd})
|
||||||
|
outfile="${outdir}/${outfilename}"
|
||||||
|
qemu-img resize -f raw "${rawdisk}" "${rounded_size}" || log error "failed to resize"
|
||||||
|
qemu-img convert -f raw -o subformat=fixed,force_size -O vpc "${rawdisk}" "${outfile}" || log error "failed to convert to VHD format"
|
||||||
|
|
||||||
|
echo "${outfile}"
|
Loading…
Reference in New Issue
Block a user