Fail more quickly if the deb argument is wrong. - #2964
Conversation
If there's a mistake or issue with the linux_image_deb argument, then this only gets detected later in the process after several minutes. This hopefully should check the argument earlier, failing a little more quicker.
| echo "CREATE IMAGE FAILED!!!" | ||
| echo "Package not found: ${linux_image_deb}" | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
good idea, let's just make this logic part of the Golang binary. I think we can do a check just by pinging the debian endpoint:
url := "https://packages.debian.org/[trixie|bookworm]/{linux_image_deb}"
resp, err := http.Head(url)
if err == nil && resp.StatusCode == http.StatusOK {
fmt.Println("Exists (200 OK)")
} else {
fmt.Printf("Does not exist or error: %v (Status: %d)\n", err, resp.StatusCode)
}
This way we would fail way faster as we won't need to create VM/disks and all of that stuff.
There was a problem hiding this comment.
we could do something like that, but that becomes brittle if the path changes or the apt/package mechanism changes.
also, https://packages.debian.org/trixie/foo returns 200 OK.
There was a problem hiding this comment.
We can rather use the /search endpoint:
curl -s "https://packages.debian.org/search?keywords=linux-image-6.12.101&suite=trixie§ion=main" | grep -q "linux-image-6.12.100+deb13-cloud-amd64" && echo "Available" || echo "Not Available"
Given how ad-hoc this script is and how un-frequent is meant to be run I think is fine to rely on https://packages.debian.org/search in order to exit right away without engage on GCP resources. Verifying wether the package is valid via "chroot" and "apt" in this case would give us a better error message, however I think the delay for failing would almost be the same as we still need to create the vms, disks and so on which is the what takes the most when running this scripts.
If there's a mistake or issue with the linux_image_deb argument, then this only gets detected later in the process after several minutes. This hopefully should check the argument earlier, failing a little more quicker.