Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tools/baseimage/pkg/gce/scripts/install_kernel_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ arch=$(uname -m)
[ "${arch}" = "aarch64" ] && arch=arm64

sudo apt-get update
sudo chroot /mnt/image /usr/bin/apt-get update

if ! sudo chroot /mnt/image /usr/bin/apt-get install --dry-run \
"${linux_image_deb}" > /dev/null; then
echo "CREATE IMAGE FAILED!!!"
echo "Package not found: ${linux_image_deb}"
exit 1
fi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rather use the /search endpoint:

curl -s "https://packages.debian.org/search?keywords=linux-image-6.12.101&suite=trixie&section=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.


sudo apt-get upgrade -y

version=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-${arch} | grep ^Depends: | \
cut -d: -f2 | cut -d" " -f2 )
echo "START VERSION: ${version}"

sudo chroot /mnt/image /usr/bin/apt-get update
sudo chroot /mnt/image /usr/bin/apt-get dist-upgrade -y

version=$(sudo chroot /mnt/image/ /usr/bin/dpkg -s linux-image-cloud-${arch} | grep ^Depends: | \
Expand Down
Loading