Clean up project and zone handling
BUG: 129569857
Change-Id: I74419ff0e37c46d1cdb128f5b890ffbcd64e7e99
Test: Ran AOSP image build
(cherry picked from commit 2cc6a59f44da0f682186e18a17b58eef63e78f05)
diff --git a/tools/create_base_image_hostlib.sh b/tools/create_base_image_hostlib.sh
index abc2fd8..d8e583c 100755
--- a/tools/create_base_image_hostlib.sh
+++ b/tools/create_base_image_hostlib.sh
@@ -12,9 +12,14 @@
DEFINE_string build_instance \
"${USER}-build" "Instance name to create for the build" "i"
+DEFINE_string build_project "$(gcloud config get-value project)" \
+ "Project to use for scratch"
+DEFINE_string build_zone "$(gcloud config get-value compute/zone)" \
+ "Zone to use for scratch resources"
DEFINE_string dest_image "vsoc-host-scratch-${USER}" "Image to create" "o"
DEFINE_string dest_family "" "Image family to add the image to" "f"
-DEFINE_string dest_project "" "Project to use for the new image" "p"
+DEFINE_string dest_project "$(gcloud config get-value project)" \
+ "Project to use for the new image" "p"
DEFINE_string launch_instance "" \
"Name of the instance to launch with the new image" "l"
DEFINE_string source_image_family debian-9 "Image familty to use as the base" \
@@ -29,6 +34,7 @@
DEFINE_string variant master \
"Variant to build: generally master or stable"
+
SSH_FLAGS=(${INTERNAL_IP})
wait_for_instance() {
@@ -55,11 +61,7 @@
main() {
set -o errexit
set -x
- if [[ -n "${FLAGS_dest_project}" ]]; then
- dest_project_flag=("--project=${FLAGS_dest_project}")
- else
- dest_project_flag=()
- fi
+ PZ=(--project=${FLAGS_build_project} --zone=${FLAGS_build_zone})
if [[ -n "${FLAGS_dest_family}" ]]; then
dest_family_flag=("--family=${FLAGS_dest_family}")
else
@@ -83,51 +85,64 @@
delete_instances+=("${FLAGS_launch_instance}")
fi
gcloud compute instances delete -q \
- "${dest_project_flag[@]}" "${delete_instances[@]}" || \
+ "${PZ[@]}" "${delete_instances[@]}" || \
echo Not running
gcloud compute disks delete -q \
- "${dest_project_flag[@]}" "${FLAGS_dest_image}" || echo No scratch disk
+ "${PZ[@]}" "${FLAGS_dest_image}" || echo No scratch disk
gcloud compute images delete -q \
- "${dest_project_flag[@]}" "${FLAGS_dest_image}" || echo Not respinning
+ --project="${FLAGS_build_project}" "${FLAGS_dest_image}" || echo Not respinning
gcloud compute disks create \
- "${dest_project_flag[@]}" \
+ "${PZ[@]}" \
--image-family="${FLAGS_source_image_family}" \
--image-project="${FLAGS_source_image_project}" \
"${FLAGS_dest_image}"
gcloud compute instances create \
- "${dest_project_flag[@]}" \
+ "${PZ[@]}" \
--machine-type=n1-standard-16 \
--image-family="${FLAGS_source_image_family}" \
--image-project="${FLAGS_source_image_project}" \
--boot-disk-size=200GiB \
"${FLAGS_build_instance}"
- wait_for_instance "${dest_project_flag[@]}" "${FLAGS_build_instance}"
+ wait_for_instance "${PZ[@]}" "${FLAGS_build_instance}"
# Ubuntu tends to mount the wrong disk as root, so help it by waiting until
# it has booted before giving it access to the clean image disk
gcloud compute instances attach-disk \
- "${dest_project_flag[@]}" \
+ "${PZ[@]}" \
"${FLAGS_build_instance}" --disk="${FLAGS_dest_image}"
# beta for the --internal-ip flag that may be passed via SSH_FLAGS
- gcloud beta compute scp "${SSH_FLAGS[@]}" "${dest_project_flag[@]}" \
+ gcloud beta compute scp "${SSH_FLAGS[@]}" "${PZ[@]}" \
"${source_files[@]}" \
"${FLAGS_build_instance}:"
gcloud compute ssh "${SSH_FLAGS[@]}" \
- "${dest_project_flag[@]}" "${FLAGS_build_instance}" -- \
+ "${PZ[@]}" "${FLAGS_build_instance}" -- \
./create_base_image_gce.sh
gcloud compute instances delete -q \
- "${dest_project_flag[@]}" "${FLAGS_build_instance}"
- gcloud compute images create "${dest_project_flag[@]}" \
+ "${PZ[@]}" "${FLAGS_build_instance}"
+ gcloud compute images create \
+ --project="${FLAGS_build_project}" \
--source-disk="${FLAGS_dest_image}" \
+ --source-disk-zone="${FLAGS_build_zone}" \
--licenses=https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx \
"${dest_family_flag[@]}" \
"${FLAGS_dest_image}"
- gcloud compute disks delete -q "${dest_project_flag[@]}" \
+ gcloud compute disks delete -q "${PZ[@]}" \
"${FLAGS_dest_image}"
if [[ -n "${FLAGS_launch_instance}" ]]; then
- gcloud compute instances create "${dest_project_flag[@]}" \
+ gcloud compute instances create "${PZ[@]}" \
+ --image-project="${FLAGS_build_project}" \
--image="${FLAGS_dest_image}" \
--machine-type=n1-standard-4 \
--scopes storage-ro \
"${FLAGS_launch_instance}"
fi
+ cat <<EOF
+ echo Test and if this looks good, consider releasing it via:
+
+ gcloud compute images create \
+ --project="${FLAGS_dest_project}" \
+ --source-image="${FLAGS_dest_image}" \
+ --source-image-project="${FLAGS_build_project}" \
+ "${dest_family_flag[@]}" \
+ "${FLAGS_dest_image}"
+EOF
}