56 lines
1.7 KiB
Bash
Executable file
56 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -eox pipefail
|
|
|
|
VM_NAME="${VM_NAME:-k8s-kvm}"
|
|
VM_MEMORY="${VM_MEMORY:-4G}"
|
|
# hostfwd=[tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport
|
|
HOSTFWD="${HOSTFWD:-hostfwd=tcp::2222-:22}"
|
|
DISK_IMG="${DISK_IMG:-./coreos_production_qemu_image.img}"
|
|
CD_ARG=""
|
|
MONITOR_OUTPUT="${MONITOR_OUTPUT:-unix:/tmp/kvm-mon}"
|
|
|
|
if [ -n "${CLOUD_CONFIG_FILE}" ]; then
|
|
echo "Setting cloud config file: ${CLOUD_CONFIG_FILE}"
|
|
mkdir -p "${PWD}/openstack/latest"
|
|
cp "${CLOUD_CONFIG_FILE}" "${PWD}/openstack/latest/user_data"
|
|
cat "${PWD}/openstack/latest/user_data"
|
|
set -- \
|
|
-fsdev local,id=conf,security_model=none,readonly,path="${PWD}" \
|
|
-device virtio-9p-pci,fsdev=conf,mount_tag=config-2 "$@"
|
|
fi
|
|
|
|
if [ -n "${IGNITION_CONFIG_FILE}" ]; then
|
|
echo "Setting ignition config file: ${IGNITION_CONFIG_FILE}"
|
|
cat "${IGNITION_CONFIG_FILE}"
|
|
set -- -fw_cfg name=opt/com.coreos/config,file="${IGNITION_CONFIG_FILE}" "$@"
|
|
fi
|
|
|
|
if [ -n "$CONFIG_FILE" ]; then
|
|
echo "Transpiling config file: ${CONFIG_FILE}"
|
|
cat "${CONFIG_FILE}"
|
|
./ct -in-file $CONFIG_FILE -out-file ${PWD}/ignition.json
|
|
echo "Setting ignition config file ${PWD}/ignition.json"
|
|
cat "${PWD}/ignition.json"
|
|
set -- -fw_cfg name=opt/com.coreos/config,file="${PWD}/ignition.json" "$@"
|
|
fi
|
|
|
|
if [ -n "$CD_IMG" ]; then
|
|
CD_ARG="-drive file=${CD_IMG},media=cdrom"
|
|
fi
|
|
|
|
# https://alpha.release.core-os.net/amd64-usr/current/coreos_production_qemu.sh
|
|
qemu-system-x86_64 \
|
|
-name "${VM_NAME}" \
|
|
-enable-kvm \
|
|
-cpu host \
|
|
-m "${VM_MEMORY}" \
|
|
-device virtio-net,netdev=vmnic \
|
|
-netdev user,id=vmnic,"${HOSTFWD}",hostname="${VM_NAME}" \
|
|
-drive if=virtio,file="${DISK_IMG}" \
|
|
${CD_ARG} \
|
|
-nographic \
|
|
-machine accel=kvm \
|
|
-vga std \
|
|
-smp 2 \
|
|
-monitor "${MONITOR_OUTPUT}" \
|
|
$@
|