golang.org/x/build@v0.0.0-20240506185731-218518f32b70/env/linux-x86-vmx/create.sh (about) 1 #!/bin/sh 2 # Copyright 2019 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 # This creates the debian-bullseye-vmx buildlet VM that's 7 # like the Container-Optimized OS but using Debian Bullseye 8 # instead of the Chromium OS, and with nested virtualization 9 # enabled. 10 11 set -e 12 set -x 13 14 ZONE=us-central1-f 15 TARGET_IMAGE=debian-bullseye-vmx 16 17 TMP_DISK=dev-debian-vmx-tmpdisk 18 TMP_IMG=dev-debian-vmx-image 19 TMP_VM=dev-debian-vmx 20 21 # Create disk, forking Debian 9 (Stretch). 22 gcloud compute disks delete $TMP_DISK --zone=$ZONE --quiet || true 23 gcloud compute disks create $TMP_DISK \ 24 --zone=$ZONE \ 25 --size=40GB \ 26 --image-project=debian-cloud \ 27 --image-family debian-11 28 29 # Create image based on that disk, with the nested virtualization 30 # opt-in flag ("license"). 31 gcloud compute images delete $TMP_IMG --quiet || true 32 gcloud compute images create \ 33 $TMP_IMG \ 34 --source-disk=$TMP_DISK \ 35 --source-disk-zone=$ZONE \ 36 --licenses "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx" 37 38 # No longer need that temp disk: 39 gcloud compute disks delete $TMP_DISK --zone=$ZONE --quiet 40 41 # Create the VM 42 gcloud compute instances delete --zone=$ZONE $TMP_VM --quiet || true 43 gcloud compute instances create \ 44 $TMP_VM \ 45 --zone=$ZONE \ 46 --image=$TMP_IMG \ 47 --min-cpu-platform "Intel Haswell" \ 48 --network default-vpc \ 49 --no-service-account --no-scopes 50 51 echo "Waiting for SSH port to be available..." 52 while ! gcloud compute ssh $TMP_VM --zone=$ZONE --tunnel-through-iap -- echo hi; do 53 sleep 1 54 done 55 56 echo "SSH is up. Copying prep-vm.sh script to VM..." 57 58 # gcloud compute scp lacks an --internal-ip flag, even though gcloud 59 # compute ssh has it. Annoying. Workaround: 60 gcloud compute scp --zone=$ZONE --tunnel-through-iap prep-vm.sh $TMP_VM: 61 62 # And prep the machine. 63 gcloud compute ssh $TMP_VM --zone=$ZONE --tunnel-through-iap -- sudo bash ./prep-vm.sh 64 65 echo "Done prepping machine; shutting down" 66 67 # Shut it down so it's a stable source to snapshot from. 68 gcloud compute instances stop $TMP_VM --zone=$ZONE 69 70 # Now make the new image from our instance's disk. 71 gcloud compute images delete $TARGET_IMAGE --quiet || true 72 gcloud compute images create $TARGET_IMAGE --source-disk=$TMP_VM --source-disk-zone=$ZONE 73 74 gcloud compute images delete $TMP_IMG --quiet 75 76 echo "Done."