mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
8eb1fac9ad
* Refactor and update dependencies in the project - Updated go.sum to replace `github.com/absmach/magistrala` with `github.com/absmach/supermq` across various modules. - Removed VSock configuration from environment variables and QEMU arguments. - Updated QEMU configuration and related tests to remove references to guest CID and VSock. - Added new HTTP transport layer for API endpoints in the manager. - Introduced Prometheus monitoring configuration with alert rules and Alertmanager setup. - Updated service and VM interfaces to remove unused methods and references. - Refactored tests to align with the new structure and dependencies. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Add MaxVMs configuration and enforce limit on VM creation Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Add comprehensive tests for HTTP transport handlers and endpoints Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Add test case for exceeding maximum number of VMs in TestRun Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Improve error handling in TestHandlerWithCustomRouter to ensure response writing is checked Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Update dependencies to latest versions - Upgrade cel.dev/expr from v0.23.0 to v0.24.0 - Upgrade github.com/absmach/supermq from v0.16.0 to v0.17.0 - Upgrade github.com/cenkalti/backoff from v4.3.0 to v5.0.2 - Upgrade github.com/cncf/xds/go to v0.0.0-20250501225837-2ac532fd4443 - Upgrade github.com/go-chi/chi/v5 from v5.2.1 to v5.2.2 - Upgrade github.com/go-jose/go-jose/v3 from v3.0.3 to v3.0.4 - Upgrade github.com/gofrs/uuid/v5 from v5.3.0 to v5.3.2 - Upgrade github.com/prometheus/client_golang from v1.22.0 to v1.23.0 - Upgrade github.com/prometheus/client_model from v0.6.1 to v0.6.2 - Upgrade github.com/prometheus/common from v0.62.0 to v0.65.0 - Upgrade github.com/prometheus/procfs from v0.15.1 to v0.16.1 - Upgrade go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp from v0.60.0 to v0.62.0 - Upgrade go.opentelemetry.io/otel/exporters/otlp/otlptrace from v1.36.0 to v1.37.0 - Upgrade golang.org/x/crypto from v0.39.0 to v0.40.0 - Upgrade golang.org/x/sys from v0.33.0 to v0.34.0 - Upgrade golang.org/x/text from v0.26.0 to v0.27.0 - Upgrade golang.org/x/time from v0.11.0 to v0.12.0 - Upgrade google.golang.org/grpc from v1.73.0 to v1.74.2 Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
120 lines
3.6 KiB
Bash
Executable File
120 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Source environment variables
|
|
source ./.env
|
|
|
|
# Required commands
|
|
REQUIRED_CMDS=("wget" "cloud-localds" "$QEMU_BINARY" "qemu-img")
|
|
|
|
# Check for required commands
|
|
for cmd in "${REQUIRED_CMDS[@]}"; do
|
|
if ! command -v "$cmd" &> /dev/null; then
|
|
echo "Error: $cmd is not installed. Please install it and try again."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Ensure script is run as root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "Error: This script must be run as root."
|
|
exit 1
|
|
fi
|
|
|
|
# Create the root filesystem image if it doesn't exist
|
|
if [ ! -f "$BASE_IMAGE" ]; then
|
|
echo "Downloading base Ubuntu image..."
|
|
wget -q "$BASE_IMAGE_URL" -O "$BASE_IMAGE" --show-progress
|
|
fi
|
|
|
|
# Create custom image
|
|
echo "Creating custom QEMU image..."
|
|
qemu-img create -f qcow2 -b "$BASE_IMAGE" -F qcow2 "$CUSTOM_IMAGE" "$DISK_SIZE"
|
|
|
|
# Cloud-init configuration files
|
|
CLOUD_CONFIG="config.yaml"
|
|
META_DATA="meta-data"
|
|
SEED_IMAGE="seed.img"
|
|
|
|
# Create seed image for cloud-init
|
|
echo "Creating seed image..."
|
|
cloud-localds "$SEED_IMAGE" "$CLOUD_CONFIG" "$META_DATA"
|
|
|
|
# Construct QEMU arguments from environment variables
|
|
construct_qemu_args() {
|
|
args=()
|
|
|
|
args+=("-name" "$VM_NAME")
|
|
|
|
# Virtualization (Enable KVM)
|
|
if [ "$ENABLE_KVM" == "true" ]; then
|
|
args+=("-enable-kvm")
|
|
fi
|
|
|
|
# Machine, CPU, RAM
|
|
if [ -n "$MACHINE" ]; then
|
|
args+=("-machine" "$MACHINE")
|
|
fi
|
|
|
|
if [ -n "$CPU" ]; then
|
|
args+=("-cpu" "$CPU")
|
|
fi
|
|
|
|
args+=("-boot" "d")
|
|
args+=("-smp" "$SMP_COUNT,maxcpus=$SMP_MAXCPUS")
|
|
args+=("-m" "$MEMORY_SIZE,slots=$MEMORY_SLOTS,maxmem=$MAX_MEMORY")
|
|
|
|
# OVMF (if applicable)
|
|
if [ "$ENABLE_SEV_SNP" != "true" ]; then
|
|
args+=("-drive" "if=$OVMF_CODE_IF,format=$OVMF_CODE_FORMAT,unit=$OVMF_CODE_UNIT,file=$OVMF_CODE,readonly=$OVMF_CODE_READONLY")
|
|
args+=("-drive" "if=$OVMF_VARS_IF,format=$OVMF_VARS_FORMAT,unit=$OVMF_VARS_UNIT,file=$OVMF_VARS")
|
|
fi
|
|
|
|
# Network configuration
|
|
args+=("-netdev" "user,id=$NET_DEV_ID,hostfwd=tcp::$NET_DEV_HOST_FWD_AGENT-:$NET_DEV_GUEST_FWD_AGENT")
|
|
args+=("-device" "virtio-net-pci,disable-legacy=$VIRTIO_NET_PCI_DISABLE_LEGACY,iommu_platform=$VIRTIO_NET_PCI_IOMMU_PLATFORM,netdev=$NET_DEV_ID,addr=$VIRTIO_NET_PCI_ADDR,romfile=$VIRTIO_NET_PCI_ROMFILE")
|
|
|
|
# SEV_SNP (if enabled)
|
|
if [ "$ENABLE_SEV_SNP" == "true" ]; then
|
|
kernel_hash=""
|
|
host_data=""
|
|
|
|
args+=("-machine" "confidential-guest-support=$SEV_SNP_ID,memory-backend=$MEM_ID")
|
|
|
|
args+=("-bios" "$OVMF_CODE_FILE")
|
|
sev_snp_type="sev-snp-guest"
|
|
|
|
if [ -n "$SEV_SNP_HOST_DATA" ]; then
|
|
host_data=",host-data=$SEV_SNP_HOST_DATA"
|
|
fi
|
|
|
|
if [ "$ENABLE_KERNEL_HASH" == "true" ]; then
|
|
kernel_hash=",kernel-hashes=on"
|
|
fi
|
|
|
|
args+=("-object" "memory-backend-memfd,id=$MEM_ID,size=$MEMORY_SIZE,share=true,prealloc=false")
|
|
args+=("-object" "$sev_snp_type,id=$SEV_SNP_ID,cbitpos=$SEV_SNP_CBIT_POS,reduced-phys-bits=$SEV_SNP_REDUCED_PHYS_BITS$kernel_hash$host_data")
|
|
fi
|
|
|
|
# Disk image configuration
|
|
args+=("-drive" "file=$SEED_IMAGE,media=cdrom")
|
|
args+=("-drive" "file=$CUSTOM_IMAGE,if=none,id=disk0,format=qcow2")
|
|
args+=("-device" "virtio-scsi-pci,id=scsi,disable-legacy=on,iommu_platform=true")
|
|
args+=("-device" "scsi-hd,drive=disk0")
|
|
|
|
# Display options
|
|
if [ "$NO_GRAPHIC" == "true" ]; then
|
|
args+=("-nographic")
|
|
fi
|
|
|
|
args+=("-monitor" "$MONITOR")
|
|
args+=("-vnc" ":9")
|
|
|
|
echo "${args[@]}"
|
|
}
|
|
|
|
qemu_args=$(construct_qemu_args)
|
|
|
|
echo "Running QEMU with the following arguments: $qemu_args"
|
|
echo "Starting QEMU VM..."
|
|
$QEMU_BINARY $qemu_args
|