Skip to content

Commit

Permalink
isoBuilder.py: Add support for rpm-ostree based iso and custom artifact
Browse files Browse the repository at this point in the history
path.

In order to generate custom rpm-ostree iso use the following command:
```
photon-iso-builder -v 4.0 -f build-rpm-ostree-iso -o <path-to-ostree-tar>
```

Command to use user specified artifact path:
```
photon-iso-builder -v 4.0 -a <path-to-artifact-parent-dir> -p packages_custom.json
```

Changes:
- Move jsonread() to commandutils from isoBuilder.

- generate_initrd.sh:
  - Add flag OSTREE_ISO to check if rpm-ostree iso is being generated.
  - Create array BIND_MOUNT_DIR containing list of directories to mount
    in docker container if tdnf command fails.
  - Create local repo if ostree iso is not getting generated.
  - Move generation of build_install_options_custom.json to isoBuilder.

- isoBuilder.py:
  - Use key worded arguments while generating isoBuilder object.
  - Use artifact_path provided by user to generate iso in instead of curDir.
  - Add createInstallOptionJson() to generate custom build install
    option json. Set install option key to "custom" by default and
    change it to "ostree_host" to select ostree installation.
  - Skip downloading packages if rpm ostree iso is generated.
  - Skip check for custom_packages_json before adding packages to
    download package list.
  - Install syslinux and photon-iso-config without adding them to
    download pkg list.
  - Download sample_ks.cfg and sample_ui.cfg from specified branch of
    photon repo.
  - Add default custom_packages_json for ostree iso as
    packages_ostree_host.json.
  - Add copyAdditionalFiles() to copy any extra files to iso.
    Ex - ostree-repo.tar.gz
  - Replace shell commands with shutil lib functions.
  - Remove extraction of OSL to reduce size of iso.
  - Add help for missing parameters.

Change-Id: I5175d0f387816803258433b18ec8a791acb5d7d3
  • Loading branch information
gpiyush-dev committed Mar 15, 2023
1 parent c1fa64f commit dc0dac9
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 98 deletions.
7 changes: 7 additions & 0 deletions photon_installer/commandutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ssl
import requests
import copy
import json
from urllib.parse import urlparse
from OpenSSL.crypto import load_certificate, FILETYPE_PEM

Expand Down Expand Up @@ -132,6 +133,12 @@ def checkIfHostRpmNotUsable(self):

return self.hostRpmIsNotUsable

@staticmethod
def jsonread(filename):
with open(filename) as f:
data = json.load(f)
return data

def convertToBytes(self, size):
if not isinstance(size, str):
return int(size)
Expand Down
68 changes: 31 additions & 37 deletions photon_installer/generate_initrd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ PACKAGES=$2
RPMS_PATH=$3
PHOTON_RELEASE_VER=$4
CUSTOM_PKG_LIST_FILE=$5
PACKAGE_LIST_FILE_BASE_NAME="build_install_options_custom.json"
CUSTOM_PKG_LIST_FILE_BASE_NAME=$(basename "${CUSTOM_PKG_LIST_FILE}")
PACKAGE_LIST_FILE_BASE_NAME=$6
OSTREE_ISO=$7
INITRD=$WORKINGDIR/photon-chroot
LICENSE_TEXT="VMWARE $PHOTON_RELEASE_VER"

Expand All @@ -21,15 +21,6 @@ fi

LICENSE_TEXT+=" LICENSE AGREEMENT"

cat > ${WORKINGDIR}/photon-local.repo <<EOF
[photon-local]
name=VMware Photon Linux
baseurl=file://${RPMS_PATH}
gpgcheck=0
enabled=1
skip_if_unavailable=True
EOF

cat > ${WORKINGDIR}/tdnf.conf <<EOF
[main]
gpgcheck=0
Expand All @@ -38,19 +29,36 @@ clean_requirements_on_remove=true
repodir=${WORKINGDIR}
EOF

TDNF_CMD="tdnf install -qy \
TDNF_CMD="tdnf install -y \
--releasever $PHOTON_RELEASE_VER \
--installroot $INITRD \
--rpmverbosity 10 \
-c ${WORKINGDIR}/tdnf.conf \
${PACKAGES}"
--rpmverbosity 10"

BIND_MOUNT_DIR=("$WORKINGDIR:$WORKINGDIR")

if [ $OSTREE_ISO != "True" ]; then
cat > ${WORKINGDIR}/photon-local.repo <<EOF
[photon-local]
name=VMware Photon Linux
baseurl=file://${RPMS_PATH}
gpgcheck=0
enabled=1
skip_if_unavailable=True
EOF
# Generate list of volumes to mount in container.
# Don't mount RPMS_PATH if ostree iso as we don't need RPMS dir to install.
BIND_MOUNT_DIR+=("$RPMS_PATH:$RPMS_PATH")
TDNF_CMD+=" -c ${WORKINGDIR}/tdnf.conf"
fi

echo $TDNF_CMD
# Prepend "-v" to each element in array BIND_MOUNT_DIR.
BIND_MOUNT_DIR=( "${BIND_MOUNT_DIR[@]/#/-v }" )

$TDNF_CMD || docker run --privileged --ulimit nofile=1024:1024 --rm -v $RPMS_PATH:$RPMS_PATH -v $WORKINGDIR:$WORKINGDIR photon:$PHOTON_RELEASE_VER /bin/bash -c "$TDNF_CMD"
TDNF_CMD+=" ${PACKAGES}"

#mkdir -p $WORKINGDIR/isolinux
#cp -r ${INITRD}/usr/share/photon-isolinux/* $WORKINGDIR/isolinux/
echo $TDNF_CMD

$TDNF_CMD || docker run --privileged --ulimit nofile=1024:1024 --rm ${BIND_MOUNT_DIR[*]} photon:$PHOTON_RELEASE_VER /bin/bash -c "$TDNF_CMD"

chroot ${INITRD} /usr/sbin/pwconv
chroot ${INITRD} /usr/sbin/grpconv
Expand All @@ -62,29 +70,15 @@ echo "photon-installer" > $INITRD/etc/hostname

rm -rf ${INITRD}/var/cache/tdnf


# Move entire /boot from initrd to ISO
mv ${INITRD}/boot ${WORKINGDIR}/

mkdir -p $INITRD/installer
cp $SCRIPT_PATH/../sample_ks/sample_ui.cfg ${INITRD}/installer
mv ${WORKINGDIR}/sample_ui.cfg ${INITRD}/installer
mv ${WORKINGDIR}/EULA.txt ${INITRD}/installer

# TODO: change minimal to custom.json
cat > ${INITRD}/installer/build_install_options_custom.json << EOF
{
"custom" : {
"title" : "Photon Custom",
"packagelist_file" : "${CUSTOM_PKG_LIST_FILE_BASE_NAME}",
"visible" : false
}
}
EOF


if [ -f "$CUSTOM_PKG_LIST_FILE" ]; then
cp ${CUSTOM_PKG_LIST_FILE} ${INITRD}/installer/packages_minimal.json
cp ${CUSTOM_PKG_LIST_FILE} ${INITRD}/installer
fi
mv ${WORKINGDIR}/$PACKAGE_LIST_FILE_BASE_NAME ${INITRD}/installer
cp ${CUSTOM_PKG_LIST_FILE} ${INITRD}/installer

mkfifo ${INITRD}/dev/initctl
mknod ${INITRD}/dev/ram0 b 1 0
Expand Down
Loading

0 comments on commit dc0dac9

Please sign in to comment.