Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mantle/ore: gcloud: add ability to attach license to image #1446

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
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
19 changes: 9 additions & 10 deletions mantle/cmd/ore/gcloud/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
uploadImageFamily string
uploadImageDescription string
uploadCreateImage bool
uploadImageLicense string
)

func init() {
Expand All @@ -58,6 +59,7 @@ func init() {
cmdUpload.Flags().StringVar(&uploadImageFamily, "family", "", "GCP image family to attach image to")
cmdUpload.Flags().StringVar(&uploadImageDescription, "description", "", "The description that should be attached to the image")
cmdUpload.Flags().BoolVar(&uploadCreateImage, "create-image", true, "Create an image in GCP after uploading")
cmdUpload.Flags().StringVar(&uploadImageLicense, "license", "", "The license to attach to the image")
GCloud.AddCommand(cmdUpload)
}

Expand Down Expand Up @@ -130,14 +132,16 @@ func runUpload(cmd *cobra.Command, args []string) {

if uploadCreateImage {
fmt.Printf("Creating image in GCE: %v...\n", imageNameGCE)

// create image on gce
_, pending, err := api.CreateImage(&gcloud.ImageSpec{
spec := &gcloud.ImageSpec{
Name: imageNameGCE,
Family: uploadImageFamily,
SourceImage: imageStorageURL,
Description: uploadImageDescription,
}, uploadForce)
}
if uploadImageLicense != "" {
spec.Licenses = []string{uploadImageLicense}
}
_, pending, err := api.CreateImage(spec, uploadForce)
if err == nil {
err = pending.Wait()
}
Expand All @@ -153,12 +157,7 @@ func runUpload(cmd *cobra.Command, args []string) {
switch ans {
case "y", "Y", "yes":
fmt.Println("Overriding existing image...")
_, pending, err = api.CreateImage(&gcloud.ImageSpec{
Name: imageNameGCE,
Family: uploadImageFamily,
SourceImage: imageStorageURL,
Description: uploadImageDescription,
}, true)
_, pending, err := api.CreateImage(spec, true)
bgilbert marked this conversation as resolved.
Show resolved Hide resolved
if err == nil {
err = pending.Wait()
}
Expand Down
5 changes: 5 additions & 0 deletions src/cosalib/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def gcp_run_ore(build, args):
ore_args.extend(['--description', args.description])
if not args.create_image:
ore_args.extend(['--create-image=false'])
if args.license:
ore_args.extend(['--license', args.license])

run_verbose(ore_args)
build.meta['gcp'] = {
Expand Down Expand Up @@ -119,4 +121,7 @@ def gcp_cli(parser):
type=boolean_string,
help="Whether or not to create an image in GCP after upload.",
default=True)
parser.add_argument("--license",
help="The license that should be attached to the image",
default=None)
return parser