func GenerateFullUpdate(version string, prod bool) error { var variant string if prod { variant = "production" } else { variant = "developer" } var ( dir = sdk.BuildImageDir(version) update_prefix = filepath.Join(dir, "coreos_"+variant+"_update") update_bin = update_prefix + ".bin" update_gz = update_prefix + ".gz" update_xml = update_prefix + ".xml" ) if err := checkUpdate(dir, update_xml); err == nil { plog.Infof("Using update manifest: %s", update_xml) return nil } plog.Noticef("Generating update payload: %s", update_gz) if err := run("delta_generator", "-new_image", update_bin, "-out_file", update_gz, "-private_key", privateKey); err != nil { return err } plog.Infof("Writing update manifest: %s", update_xml) update := omaha.Update{Id: sdk.GetDefaultAppId()} pkg, err := update.AddPackageFromPath(update_gz) // update engine needs the payload hash here in the action element postinstall := update.AddAction("postinstall") postinstall.Sha256 = pkg.Sha256 update.Version, err = sdk.GetVersionFromDir(dir) if err != nil { return err } return xmlMarshalFile(update_xml, &update) }
func runUpload(cmd *cobra.Command, args []string) { if len(args) != 0 { fmt.Fprintf(os.Stderr, "Unrecognized args in plume upload cmd: %v\n", args) os.Exit(2) } // if an image name is unspecified try to use version.txt if uploadImageName == "" { var err error uploadImageName, err = sdk.GetVersionFromDir(filepath.Dir(uploadFile)) if err != nil { fmt.Fprintf(os.Stderr, "Unable to get version from image directory, provide a -name flag or include a version.txt in the image directory: %v\n", err) os.Exit(1) } } gsURL, err := url.Parse(uploadBucket) if err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } if gsURL.Scheme != "gs" { fmt.Fprintf(os.Stderr, "URL missing gs:// scheme prefix: %v\n", uploadBucket) os.Exit(1) } if gsURL.Host == "" { fmt.Fprintf(os.Stderr, "URL missing bucket name %v\n", uploadBucket) os.Exit(1) } // if prefix not specified default name to gs://bucket/$USER/$BOARD/$VERSION if gsURL.Path == "" { if user := os.Getenv("USER"); user != "" { gsURL.Path = "/" + os.Getenv("USER") gsURL.Path += "/" + uploadBoard } } uploadBucket = gsURL.Host uploadImageName = strings.TrimPrefix(gsURL.Path+"/"+uploadImageName, "/") // create equivalent image names for GS and GCE imageNameGCE := gceSanitize(uploadImageName) imageNameGS := uploadImageName + ".tar.gz" var client *http.Client if uploadServiceAuth { client = auth.GoogleServiceClient() err = nil } else { client, err = auth.GoogleClient() } if err != nil { fmt.Fprintf(os.Stderr, "Authentication failed: %v\n", err) os.Exit(1) } api, err := compute.New(client) if err != nil { fmt.Fprintf(os.Stderr, "Api Client creation failed: %v\n", err) os.Exit(1) } // check if this file is already uploaded and give option to skip alreadyExists, err := fileQuery(client, uploadBucket, imageNameGS) if err != nil { fmt.Fprintf(os.Stderr, "Uploading image failed: %v\n", err) os.Exit(1) } if alreadyExists && !uploadForce { var ans string fmt.Printf("File %v already exists on Google Storage. Overwrite? (y/n):", imageNameGS) if _, err = fmt.Scan(&ans); err != nil { fmt.Fprintf(os.Stderr, "Scanning overwrite input: %v", err) os.Exit(1) } switch ans { case "y", "Y", "yes": fmt.Println("Overriding existing file...") err = writeFile(client, uploadBucket, uploadFile, imageNameGS) default: fmt.Println("Skipped file upload") } } else { err = writeFile(client, uploadBucket, uploadFile, imageNameGS) } if err != nil { fmt.Fprintf(os.Stderr, "Uploading image failed: %v\n", err) os.Exit(1) } fmt.Printf("Creating image in GCE: %v...\n", imageNameGCE) // create image on gce storageSrc := fmt.Sprintf("https://storage.googleapis.com/%v/%v", uploadBucket, imageNameGS) if uploadForce { err = platform.GCEForceCreateImage(api, opts.Project, imageNameGCE, storageSrc) } else { err = platform.GCECreateImage(api, opts.Project, imageNameGCE, storageSrc) } // if image already exists ask to delete and try again if err != nil && strings.HasSuffix(err.Error(), "alreadyExists") { var ans string fmt.Printf("Image %v already exists on GCE. Overwrite? (y/n):", imageNameGCE) if _, err = fmt.Scan(&ans); err != nil { fmt.Fprintf(os.Stderr, "Scanning overwrite input: %v", err) os.Exit(1) } switch ans { case "y", "Y", "yes": fmt.Println("Overriding existing image...") err = platform.GCEForceCreateImage(api, opts.Project, imageNameGCE, storageSrc) if err != nil { fmt.Fprintf(os.Stderr, "Creating GCE image failed: %v\n", err) os.Exit(1) } fmt.Printf("Image %v sucessfully created in GCE\n", imageNameGCE) default: fmt.Println("Skipped GCE image creation") } } if err != nil { fmt.Fprintf(os.Stderr, "Creating GCE image failed: %v\n", err) os.Exit(1) } }