Skip to content
6 changes: 4 additions & 2 deletions vm-install/image-setup/bootstrap-lite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ ORG=$2

INSTALL_DIR="/opt/opsmx"
INSTALL_SCRIPT="$INSTALL_DIR/opsmxssd/install.sh"
TARGET_FILE="$INSTALL_SCRIPT/opsmxssd/ssd-minimal-values.yaml"
FALLBACK_FILE="$INSTALL_SCRIPT/opsmxssd/default-ssd-minimal-values.yaml"
TARGET_FILE="$HOME/opsmxssd/ssd-minimal-values.yaml"
FALLBACK_FILE="$INSTALL_DIR/opsmxssd/default-ssd-minimal-values.yaml"
mkdir -p "$HOME/opsmxssd"

if [ "$#" -gt 2 ]; then
REMOTE_URL=$3
echo "Attempting to download values file from $REMOTE_URL"
Expand Down
2 changes: 1 addition & 1 deletion vm-install/image-setup/bundle-lite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ls $IMAGES_DIR
for tarfile in "$IMAGES_DIR"/*.tar; do
echo "Loading image from $tarfile"
sudo docker load -i "$tarfile"
echo "deleting $tarfile"
echo "Deleting $tarfile"
sudo rm $tarfile
done
echo "all images loaded from $IMAGES_DIR"
Expand Down
2 changes: 1 addition & 1 deletion vm-install/image-setup/extract-images-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ with open("$OUTPUT_FILE", "w") as out:
for image in sorted(images):
out.write(f"{image}\n")

print(f"Extracted {len(images)} images into: $OUTPUT_FILE")
print(f"Extracted {len(images)} images into: $OUTPUT_FILE")
EOF
9 changes: 5 additions & 4 deletions vm-install/image-setup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ done
echo "K3s node is in Ready state."

# Set coordonates for Kubernetes access
sudo cp /etc/rancher/k3s/k3s.yaml k3s.yaml
sudo chown $(whoami) k3s.yaml
export KUBECONFIG=$(pwd)/k3s.yaml
mkdir -p "$HOME/.kube"
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/k3s.yaml
sudo chown $(whoami): $HOME/.kube/k3s.yaml
export KUBECONFIG=$HOME/.kube/k3s.yaml
kubectl get ns ssd || err_code=$?
if [ $err_code!=0 ]; then
kubectl create ns ssd
Expand All @@ -61,7 +62,7 @@ helm repo update
# Use yq to modify the values.yaml file dynamically based on the command-line arguments
echo "Modifying values.yaml with host ($HOST) and organisationname ($ORG_NAME) parameters..."
yq e '.' "$VALUES_FILE" >/dev/null || {
echo "yq cannot read $VALUES_FILE"
echo "yq cannot read $VALUES_FILE"
exit 1
}

Expand Down
29 changes: 20 additions & 9 deletions vm-install/packer/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ unzip packer.zip
sudo mv packer /usr/local/bin/
packer --version # confirm install
packer plugins install github.com/hashicorp/qemu

# Install QEMU
sudo apt install -y qemu-system-x86 qemu-utils
sudo apt install xorriso -y

# Install AWS
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

curl -fSL -o bundle-lite-prefetch.sh https://raw.githubusercontent.com/OpsMx/enterprise-ssd/$RELEASETAG/vm-install/image-setup/bundle-lite-prefetch.sh

curl -fSL -o extract-images-list.sh https://raw.githubusercontent.com/OpsMx/enterprise-ssd/$RELEASETAG/vm-install/image-setup/extract-images-list.sh
Expand All @@ -35,25 +42,29 @@ curl -fSL -o ssd-ubuntu.pkr.hcl https://raw.githubusercontent.com/OpsMx/enterpri

curl -fSL -o ssd-ubuntu.pkrvars.hcl https://raw.githubusercontent.com/OpsMx/enterprise-ssd/$RELEASETAG/vm-install/packer/ssd-ubuntu.pkrvars.hcl

curl -fSL -o ova-creator.sh https://raw.githubusercontent.com/OpsMx/enterprise-ssd/$RELEASETAG/vm-install/packer/ova-creator.sh

chmod +x ova-creator.sh

# 🔧 Render cloud-init config from template
envsubst '${RELEASETAG}' <user-data.tpl >user-data
echo "Rendered user-data with RELEASETAG=$RELEASETAG"
echo "Rendered user-data with RELEASETAG=$RELEASETAG"

# (when not dealing with version tags) Update release tag in version.env with what value is in enviornment variable
sed -i "s/^RELEASETAG=.*/RELEASETAG=${RELEASETAG}/" version.env

chmod +x bundle-lite-prefetch.sh
./bundle-lite-prefetch.sh

#IMG="jammy-server-cloudimg-amd64.img"
#IMG_URL="https://cloud-images.ubuntu.com/jammy/current/$IMG"
#CHECKSUM=$(curl -s https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS | grep "$IMG" | awk '{print $1}')
IMG="noble-server-cloudimg-amd64.img"
IMG_URL="https://cloud-images.ubuntu.com/noble/current/$IMG"
CHECKSUM=$(curl -s https://cloud-images.ubuntu.com/noble/current/SHA256SUMS | grep "$IMG" | awk '{print $1}')

## Inject checksum into a Packer HCL file template
#envsubst <<EOF > ssd-ubuntu.pkrvars.hcl
#iso_url = "$IMG_URL"
#iso_checksum = "sha256:$CHECKSUM"
#EOF
# Inject checksum into a Packer HCL file template
envsubst <<EOF >ssd-ubuntu.pkrvars.hcl
iso_url = "$IMG_URL"
iso_checksum = "sha256:$CHECKSUM"
EOF

packer init .
PACKER_LOG=1 packer build -var-file=ssd-ubuntu.pkrvars.hcl .
106 changes: 106 additions & 0 deletions vm-install/packer/ova-creator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash
set -e

# Usage: ./create-ova.sh <image_name_without_extension> [buffer_size_in_GB]
# Example: ./create-ova.sh ubuntu-ssd 2

IMAGE_NAME="$1"
BUFFER_GB="$2"

if [ -z "$IMAGE_NAME" ]; then
echo "Usage: $0 <image_name_without_extension> [buffer_size_in_GB]"
exit 1
fi

if [ ! -f "${IMAGE_NAME}.vmdk" ]; then
echo "Error: ${IMAGE_NAME}.vmdk not found!"
exit 1
fi

# Default buffer if not provided
if [ -z "$BUFFER_GB" ]; then
BUFFER_GB=2
fi

# Get real VMDK size
VMDK_SIZE=$(stat -c%s "${IMAGE_NAME}.vmdk")
BUFFER_BYTES=$((BUFFER_GB * 1024 * 1024 * 1024))

# Calculate final OVF disk capacity
DISK_CAPACITY=$((VMDK_SIZE + BUFFER_BYTES))

# Setup default vCPU and RAM recommendations
VCPUS=8
MEMORY_MB=32768 # 32 GB RAM in MB

echo "Detected VMDK size: $VMDK_SIZE bytes (~$((VMDK_SIZE / 1024 / 1024 / 1024)) GiB)"
echo "Adding buffer: ${BUFFER_GB} GB"
echo "Final disk capacity for OVF: $DISK_CAPACITY bytes (~$((DISK_CAPACITY / 1024 / 1024 / 1024)) GiB)"
echo "Setting virtual CPU: ${VCPUS}, Memory: ${MEMORY_MB} MB"

# Create OVF descriptor
cat >"${IMAGE_NAME}.ovf" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<ovf:Envelope
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 ovf.xsd">

<ovf:References>
<ovf:File ovf:id="file1" ovf:href="${IMAGE_NAME}.vmdk" ovf:size="${VMDK_SIZE}"/>
</ovf:References>

<ovf:DiskSection>
<ovf:Info>List of the virtual disks</ovf:Info>
<ovf:Disk ovf:diskId="disk1" ovf:fileRef="file1" ovf:capacity="${DISK_CAPACITY}"/>
</ovf:DiskSection>

<ovf:VirtualSystem ovf:id="${IMAGE_NAME}">
<ovf:Info>A virtual machine</ovf:Info>
<ovf:Name>${IMAGE_NAME}</ovf:Name>

<ovf:OperatingSystemSection ovf:id="94">
<ovf:Info>The kind of installed guest operating system</ovf:Info>
<ovf:Description>Ubuntu Linux (64-bit)</ovf:Description>
</ovf:OperatingSystemSection>

<ovf:VirtualHardwareSection>
<ovf:Info>Virtual hardware requirements</ovf:Info>

<ovf:Item>
<rasd:ElementName>${VCPUS} virtual CPU</rasd:ElementName>
<rasd:InstanceID>1</rasd:InstanceID>
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>${VCPUS}</rasd:VirtualQuantity>
</ovf:Item>

<ovf:Item>
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
<rasd:ElementName>${MEMORY_MB} MB of memory</rasd:ElementName>
<rasd:InstanceID>2</rasd:InstanceID>
<rasd:ResourceType>4</rasd:ResourceType>
<rasd:VirtualQuantity>${MEMORY_MB}</rasd:VirtualQuantity>
</ovf:Item>

<ovf:Item>
<rasd:ElementName>Hard disk</rasd:ElementName>
<rasd:HostResource>ovf:/disk/disk1</rasd:HostResource>
<rasd:InstanceID>3</rasd:InstanceID>
<rasd:ResourceType>17</rasd:ResourceType>
</ovf:Item>

</ovf:VirtualHardwareSection>

</ovf:VirtualSystem>

</ovf:Envelope>
EOF

echo "OVF descriptor created: ${IMAGE_NAME}.ovf"

# Create OVA archive
echo "Packing OVA..."
tar -cvf "${IMAGE_NAME}.ova" "${IMAGE_NAME}.ovf" "${IMAGE_NAME}.vmdk"

echo "OVA generation complete: ${IMAGE_NAME}.ova"
24 changes: 3 additions & 21 deletions vm-install/packer/ssd-ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,9 @@ build {
post-processor "shell-local" {
inline = [
"echo 'Converting QCOW2 to VMDK...'",
"qemu-img convert -O vmdk output-qcow2/${local.image_name} ${local.image_name}.vmdk",

"echo 'Creating OVF descriptor...'",
"cat > ${local.image_name}.ovf <<EOF",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<ovf:Envelope xmlns:ovf=\"http://schemas.dmtf.org/ovf/envelope/1\">",
" <ovf:References>",
" <ovf:File ovf:id=\"file1\" ovf:href=\"${local.image_name}.vmdk\" ovf:size=\"$(stat -c%s ${local.image_name}.vmdk)\"/>",
" </ovf:References>",
" <ovf:DiskSection>",
" <ovf:Disk ovf:diskId=\"disk1\" ovf:fileRef=\"file1\" ovf:capacity=\"4294967296\"/>",
" </ovf:DiskSection>",
" <ovf:VirtualSystem ovf:id=\"${local.image_name}\">",
" <ovf:Name>${local.image_name}</ovf:Name>",
" </ovf:VirtualSystem>",
"</ovf:Envelope>",
"EOF",

"echo 'Creating OVA...'",
"tar -cvf ${local.image_name}.ova ${local.image_name}.ovf ${local.image_name}.vmdk",
"echo '✅ OVA generation complete: ${local.image_name}.ova'"
"qemu-img convert -p -f qcow2 output-qcow2/${local.image_name} -O vmdk -o subformat=streamOptimized,compat6 ${local.image_name}.vmdk",
"echo 'VMDK generated successfully: ${local.image_name}.vmdk'",
"bash ova-creator.sh ${local.image_name} 60"
]
}
}
Expand Down