-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add daisy wf and replacement mechanism to invoke preloading scripts (#…
…2309) * Update projects and permissions * Change project to gcp-guest and add comments * Update install_package_cos.wf.json- update to deb 11 worker (10 is EOL soon)
- Loading branch information
1 parent
75616c8
commit 21446ad
Showing
3 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
daisy_workflows/image_build/install_package/cos/install_package_cos.wf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"Name": "image-replace-package", | ||
"Zone": "us-central1-a", | ||
"DefaultTimeout": "30m", | ||
"Vars": { | ||
"source_image": { | ||
"Required": true, | ||
"Description": "source image" | ||
}, | ||
"dest_image": { | ||
"Required": true, | ||
"Description": "dest image" | ||
}, | ||
"package_version": { | ||
"Required": true, | ||
"Description": "package version" | ||
}, | ||
"cos_branch": { | ||
"Required": true, | ||
"Description": "cos_branch" | ||
}, | ||
"worker_image": { | ||
"Value": "projects/compute-image-tools/global/images/family/debian-11-worker", | ||
"Description": "worker image" | ||
}, | ||
"machine_type": { | ||
"Value": "e2-medium", | ||
"Description": "machine type" | ||
} | ||
}, | ||
"Sources": { | ||
"work/utils": "../../../linux_common/utils", | ||
"work/package_replacement": "package_replacement", | ||
"work/replacepackage.sh": "replacepackage.sh", | ||
"startup_script": "../../../linux_common/bootstrap.sh" | ||
}, | ||
"Steps": { | ||
"create-disks": { | ||
"CreateDisks": [ | ||
{ | ||
"Name": "disk-worker", | ||
"SourceImage": "${worker_image}", | ||
"Type": "pd-ssd" | ||
} | ||
] | ||
}, | ||
"create-inst": { | ||
"CreateInstances": [ | ||
{ | ||
"Name": "inst-worker", | ||
"Disks": [{"Source": "disk-worker"}], | ||
"MachineType": "${machine_type}", | ||
"Metadata": { | ||
"files_gcs_dir": "${SOURCESPATH}/work", | ||
"prefix": "ReplacePackage", | ||
"script": "replacepackage.sh", | ||
"source_image": "${source_image}", | ||
"dest_image": "${dest_image}", | ||
"cos_branch": "${cos_branch}", | ||
"package_version": "${package_version}" | ||
}, | ||
"StartupScript": "startup_script", | ||
"Scopes": [ | ||
"https://www.googleapis.com/auth/cloud-platform", | ||
"https://www.googleapis.com/auth/devstorage.read_write", | ||
"https://www.googleapis.com/auth/compute", | ||
"https://www.googleapis.com/auth/servicecontrol" | ||
] | ||
} | ||
] | ||
}, | ||
"wait": { | ||
"WaitForInstancesSignal": [ | ||
{ | ||
"Name": "inst-worker", | ||
"Timeout": "15m", | ||
"SerialOutput": { | ||
"Port": 1, | ||
"FailureMatch": "ReplacePackageFailed:", | ||
"SuccessMatch": "ReplacePackageSuccess:", | ||
"StatusMatch": "ReplacePackageStatus:" | ||
} | ||
} | ||
] | ||
}, | ||
"delete-inst": { | ||
"DeleteResources": { | ||
"Instances": ["inst-worker"], | ||
"Disks":["disk-worker"] | ||
} | ||
} | ||
|
||
}, | ||
"Dependencies": { | ||
"create-inst": ["create-disks"], | ||
"wait": ["create-inst"], | ||
"delete-inst": ["wait"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
daisy_workflows/image_build/install_package/cos/replacepackage.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# | ||
# This script is responsible for invoking the preloading mechanism that creates | ||
# a COS image with the new package version that is used for testing. | ||
# 1) The script sets all the preloading scripts as executable (located in | ||
# /cos/package_replacement). | ||
# 2) Then, collects all passed in data through metadata API (name of source | ||
# image, dest image, package version, cos branch). | ||
# - cos_branch: the name of the branch associated with a COS milestone (ie | ||
# for cos-113, cos_branch=release-R113). | ||
# 3) Runs a gcloud submit command to invoke the cloudbuild responsible for | ||
# preloading. | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -x | ||
|
||
set_files_executable(){ | ||
cd /files/package_replacement | ||
|
||
search_dir=. | ||
for file in "$search_dir"/* | ||
do | ||
chmod +x $file | ||
done | ||
} | ||
|
||
get_vars(){ | ||
export SOURCE_IMAGE=$(curl -H "Metadata-Flavor:Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/source_image) | ||
export DEST_IMAGE=$(curl -H "Metadata-Flavor:Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/dest_image) | ||
export PACKAGE_VERSION=$(curl -H "Metadata-Flavor:Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/package_version) | ||
export COS_BRANCH=$(curl -H "Metadata-Flavor:Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/cos_branch) | ||
} | ||
|
||
# The following additional parameters are passed into the cloudbuild script: | ||
# _BASE_IMAGE_PROJECT: The project that contains the base/source image. | ||
# _BASE_IMAGE: The name of the base/source image. | ||
# _DEST_PROJECT: The project that contains the resulting preloaded image. | ||
# _NEW_IMAGE: The name of the resulting preloaded image. | ||
# _NEW_IMAGE_FAMILY: The new image family for the preloaded image. | ||
create_preloaded_image(){ | ||
gcloud builds submit --config=dev_cloudbuild.yaml --disk-size=200 . --substitutions=_NEW_IMAGE_FAMILY="cos-preloaded-images",_BASE_IMAGE_PROJECT="cos-cloud",_BASE_IMAGE="${SOURCE_IMAGE}",_OVERLAYS_BRANCH="${COS_BRANCH}",_GUEST_AGENT_VERSION="${PACKAGE_VERSION}",_NEW_IMAGE="${DEST_IMAGE}",_DEST_PROJECT="gcp-guest" | ||
} | ||
|
||
main (){ | ||
echo "Creating COS image with the new guest agent version..." | ||
set_files_executable | ||
get_vars | ||
create_preloaded_image | ||
} | ||
|
||
main |