diff --git a/build-vm b/build-vm index 72ec73093..ea4dd8153 100644 --- a/build-vm +++ b/build-vm @@ -73,7 +73,7 @@ EMULATOR_SCRIPT= # openstack specific VM_OPENSTACK_FLAVOR= -for i in ec2 emulator kvm lxc openstack qemu uml xen zvm docker pvm nspawn; do +for i in gcloud ec2 emulator kvm lxc openstack qemu uml xen zvm docker pvm nspawn; do . "$BUILD_DIR/build-vm-$i" done @@ -151,7 +151,7 @@ vm_parse_options() { VM_TYPE=${VM_TYPE%:*} ;; lxc|docker|nspawn) ;; - ec2|xen|kvm|uml|qemu|emulator|openstack|zvm|pvm) + gcloud|ec2|xen|kvm|uml|qemu|emulator|openstack|zvm|pvm) test -z "$VM_ROOT" && VM_ROOT=1 ;; none|chroot) VM_TYPE= ;; diff --git a/build-vm-gcloud b/build-vm-gcloud new file mode 100644 index 000000000..3a8394ab5 --- /dev/null +++ b/build-vm-gcloud @@ -0,0 +1,204 @@ +# +# Google Cloud specific functions +# +################################################################ +# +# Copyright (c) 2022 SUSE Linux Products GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or 3 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program (see the file COPYING); if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +# +################################################################ + +# +# prepare with +# gcloud config set account ACCOUNT +# gcloud auth login + +# issues to fix before merge +# - detect disk device on attach and adapt CLI for it +# - fix hardcoded names (vm-2 and friends) +# - cleanup +# +# issues to fix for becoming productive +# - look into a way how to use disk encryption +# - look into a way to setup bootloader without possible conflicts in build environment +# - fix random build failures +# - improve serial log behaviour +# - looking for speedups .... we need currently 3 minutes on new hardware of gcloud versus 20 seconds on old hardware with kvm +# - add support to inject sysrq events ... how? +# - find a way to avoid the need of a 10GB storage device even for the smallest build + +GCLOUD_MACHINE_TYPE="n2d-standard-4" +GCLOUD_PROJECT=it-support-51de +GCLOUD_ZONE=europe-west1-b +GCLOUD_ATTACHED= + +GCLOUD_LOCAL_SSD=/dev/nvme0n1 + +[ -e /etc/google_instance_id ] && GCLOUD_MY_HOST_INSTANCE=$( "$GRUB_CONFIG_DIR/grub.cfg" + echo "insmod ext2" >> "$GRUB_CONFIG_DIR/grub.cfg" + echo "set timeout=0" >> "$GRUB_CONFIG_DIR/grub.cfg" + echo "serial" >> "$GRUB_CONFIG_DIR/grub.cfg" + echo "terminal_input serial" >> "$GRUB_CONFIG_DIR/grub.cfg" + echo "terminal_output serial" >> "$GRUB_CONFIG_DIR/grub.cfg" + echo "linux (hd0,gpt4)/boot/vmlinuz root=/dev/sda4 console=ttyS0,38400n8 init=/.build/build splash=silent $vm_linux_kernel_parameter" >> "$GRUB_CONFIG_DIR/grub.cfg" + echo "initrd (hd0,gpt4)/boot/initrd" >> "$GRUB_CONFIG_DIR/grub.cfg" + echo "boot" >> "$GRUB_CONFIG_DIR/grub.cfg" + + umount ${VM_DEVICE}2 || cleanup_and_exit 3 "ERROR: grub install failed" +} + +vm_cleanup_gcloud() { +echo "XXX vm_cleanup_gcloud" + gcloud compute instances detach-disk instance-1 --disk disk-1 --zone $GCLOUD_ZONE +# gcloud compute instances delete vm-2 --zone=$GCLOUD_ZONE || cleanup_and_exit 3 "Unable to delete VM" + gcloud compute disks delete disk-1 --zone $GCLOUD_ZONE --quiet || : +# gcloud compute networks delete vm-2-build-subnet || : +# gcloud compute networks delete vm-2-build-network || : +} + +vm_sysrq_gcloud() { +echo "XXX not yet implemented" + : +} + +vm_kill_gcloud() { +echo "XXX vm_kill_gcloud" + gcloud compute instances delete vm-2 --zone=$GCLOUD_ZONE +} + +vm_startup_gcloud() { +set +x + # Create a custom network with no access + gcloud compute networks create vm-2-build-network --subnet-mode=custom + gcloud compute networks subnets create vm-2-build-subnet --network=vm-2-build-network --range=10.0.0.0/29 --region=${GCLOUD_ZONE%-*} + gcloud compute instances create vm-2 \ + --zone=$GCLOUD_ZONE --machine-type=$GCLOUD_MACHINE_TYPE \ + --network-interface=subnet=vm-2-build-subnet,no-address \ + --no-service-account --no-scopes \ + --metadata=startup-script="/.build/build" \ + --disk=auto-delete=no,boot=yes,device-name=disk-1,name=disk-1 || cleanup_and_exit 3 "Unable to start build VM" +# --no-shielded-secure-boot --no-shielded-vtpm --no-shielded-integrity-monitoring + echo "Reading stdout..." + gcloud compute instances get-serial-port-output vm-2 --zone=$GCLOUD_ZONE + temp_file=`mktemp` + start= + while gcloud compute instances get-serial-port-output vm-2 --zone=$GCLOUD_ZONE $start > $temp_file; do + cp $temp_file /tmp/test + start=`tail -n 3 "$temp_file" | sed -n -e 's,.*Specify \(--start=\d\) in the next.*,\1,p'` + sed '/^Specify --start=.*/d' $temp_file + done + rm -f "$temp_file" + gcloud compute instances delete vm-2 --zone=$GCLOUD_ZONE --quiet +}