Skip to content

Commit

Permalink
ore/gcloud: Add --write-url argument
Browse files Browse the repository at this point in the history
coreos-assembler was trying to re-create the URL that ore computed
for the storage, and a recent refactoring broke that.

Add an option to write out the URL we used so we only need
to have its computation in one place.

Specifically, cosa started replacing `.` with `-` but ore wasn't.

xref coreos/coreos-assembler#1078
  • Loading branch information
cgwalters committed Jan 28, 2020
1 parent e7b3cc6 commit afeaa21
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/ore/gcloud/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package gcloud

import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -43,6 +44,7 @@ var (
uploadFile string
uploadFedora bool
uploadForce bool
uploadWriteUrl string
)

func init() {
Expand All @@ -55,6 +57,7 @@ func init() {
"path_to_coreos_image (build with: ./image_to_vm.sh --format=gce ...)")
cmdUpload.Flags().BoolVar(&uploadFedora, "fcos", false, "Flag this is Fedora CoreOS (or a derivative); currently enables SECURE_BOOT and UEFI_COMPATIBLE")
cmdUpload.Flags().BoolVar(&uploadForce, "force", false, "overwrite existing GS and GCE images without prompt")
cmdUpload.Flags().StringVar(&uploadWriteUrl, "write-url", "", "output the uploaded URL to the named file")
GCloud.AddCommand(cmdUpload)
}

Expand Down Expand Up @@ -176,6 +179,10 @@ func runUpload(cmd *cobra.Command, args []string) {
}
}

if uploadWriteUrl != "" {
err = ioutil.WriteFile(uploadWriteUrl, []byte(storageSrc), 0644)
}

if err != nil {
fmt.Fprintf(os.Stderr, "Creating GCE image failed: %v\n", err)
os.Exit(1)
Expand Down Expand Up @@ -211,7 +218,7 @@ func gceSanitize(name string) string {

// Write file to Google Storage
func writeFile(api *storage.Service, bucket, filename, destname string) error {
fmt.Printf("Writing %v to gs://%v ...\n", filename, bucket)
fmt.Printf("Writing %v to gs://%v/%v ...\n", filename, bucket, destname)
fmt.Printf("(Sometimes this takes a few minutes)\n")

file, err := os.Open(filename)
Expand Down

0 comments on commit afeaa21

Please sign in to comment.