From cb31f4f3fd1a24b8268cca34f9bfefaf3b747a5d Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 30 Jun 2022 01:44:12 +0700 Subject: all: add awwan scripts to deploy and test image The gcloud-image-publish.aww is the script to publish the recently build image to gcloud and create new image. The gcloud-image-test.aww is the script to test the new image by creating new compute engine. The gcloud-test-image-official.aww is the script to test the official public image from Google. The gcloud-test-tail.aww is the script to get the serial log from test image in compute engine. --- awwan.env | 9 +++++++++ gcloud-image-publish.aww | 27 +++++++++++++++++++++++++++ gcloud-image-test.aww | 30 ++++++++++++++++++++++++++++++ gcloud-test-image-official.aww | 17 +++++++++++++++++ gcloud-test-tail.aww | 4 ++++ 5 files changed, 87 insertions(+) create mode 100644 awwan.env create mode 100644 gcloud-image-publish.aww create mode 100644 gcloud-image-test.aww create mode 100644 gcloud-test-image-official.aww create mode 100644 gcloud-test-tail.aww diff --git a/awwan.env b/awwan.env new file mode 100644 index 0000000..5de47e5 --- /dev/null +++ b/awwan.env @@ -0,0 +1,9 @@ +[gcloud] +config = arch-builder +project = arch-build +region = asia-southeast1 +zone = asia-southeast1-b + +[host] +image = arch-v20220701 +name = arch-test diff --git a/gcloud-image-publish.aww b/gcloud-image-publish.aww new file mode 100644 index 0000000..d16e0f8 --- /dev/null +++ b/gcloud-image-publish.aww @@ -0,0 +1,27 @@ +## Script to publish builded image to public. + +#require: gcloud config configurations activate {{.Val "gcloud::config"}} + +gsutil cp {{.Val "host::image"}}.tar.gz gs://arch-builder-a/image/ + +gcloud compute images delete {{.Val "host::image"}} --quiet || exit 0 + +gcloud compute images create {{.Val "host::image"}} \ + --source-uri=gs://arch-builder-a/image/{{.Val "host::image"}}.tar.gz \ + --family=arch \ + --guest-os-features=GVNIC,UEFI_COMPATIBLE,VIRTIO_SCSI_MULTIQUEUE \ + --description="Arch linux image with ops-agent. See https://github.com/shuLhan/compute-archlinux-image-builder" + +gcloud compute images list --no-standard-images +gcloud compute images describe {{.Val "host::image"}} + +## Share the image publicly with authenticated users. + +gcloud compute images add-iam-policy-binding {{.Val "host::image"}} \ + --member='allAuthenticatedUsers' \ + --role='roles/compute.imageUser' + +## Delete the image on storage. + +gsutil rm -a gs://arch-builder-a/image/** +gsutil ls gs://arch-builder-a/ diff --git a/gcloud-image-test.aww b/gcloud-image-test.aww new file mode 100644 index 0000000..218dae7 --- /dev/null +++ b/gcloud-image-test.aww @@ -0,0 +1,30 @@ +## Script to test the published image manually by creating new compute +## instance. + +#require: gcloud config configurations activate {{.Val "gcloud::config"}} + +gcloud compute instances create arch-test \ + --zone={{.Val "gcloud::zone"}} \ + --image={{.Val "host::image"}} \ + --metadata=block-project-ssh-keys=TRUE \ + --machine-type=f1-micro + +gcloud compute instances describe arch-test \ + --zone={{.Val "gcloud::zone"}} + +gcloud compute instances tail-serial-port-output {{.Val "host::name"}} \ + --zone={{.Val "gcloud::zone"}} \ + +gcloud compute ssh \ + --zone={{.Val "gcloud::zone"}} \ + --command="lsblk -o NAME,UUID,MOUNTPOINTS; cat /etc/fstab; timedatectl show-timesync; localectl" \ + arch-test + +##---- Cleaning up. + +gcloud compute instances stop arch-test \ + --zone={{.Val "gcloud::zone"}} + +gcloud compute instances delete arch-test \ + --zone={{.Val "gcloud::zone"}} \ + --quiet diff --git a/gcloud-test-image-official.aww b/gcloud-test-image-official.aww new file mode 100644 index 0000000..3e464af --- /dev/null +++ b/gcloud-test-image-official.aww @@ -0,0 +1,17 @@ +## Script to test the official public image. + +#require: gcloud config configurations activate {{.Val "gcloud::config"}} + +gcloud compute instances create arch-test \ + --zone={{.Val "gcloud::zone"}} \ + --image-project=arch-linux-gce \ + --image-family=arch \ + --machine-type=f1-micro + +gcloud compute instances describe arch-test \ + --zone={{.Val "gcloud::zone"}} + +gcloud compute ssh \ + --zone={{.Val "gcloud::zone"}} \ + --command="lsblk -o NAME,UUID,MOUNTPOINTS; cat /etc/fstab; timedatectl show-timesync; localectl" \ + arch-test diff --git a/gcloud-test-tail.aww b/gcloud-test-tail.aww new file mode 100644 index 0000000..c7dd93f --- /dev/null +++ b/gcloud-test-tail.aww @@ -0,0 +1,4 @@ +#require: gcloud config configurations activate {{.Val "gcloud::config"}} + +gcloud compute instances get-serial-port-output {{.Val "host::name"}} \ + --zone={{.Val "gcloud::zone"}} -- cgit v1.3