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: clean up upload.go, stop mutating image name #1322

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
39 changes: 11 additions & 28 deletions mantle/cmd/ore/gcloud/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ import (
"io/ioutil"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"google.golang.org/api/googleapi"
"google.golang.org/api/storage/v1"

"github.com/coreos/mantle/platform/api/gcloud"
"github.com/coreos/mantle/sdk"
)

var (
Expand All @@ -40,21 +38,19 @@ var (

uploadBucket string
uploadImageName string
uploadBoard string
uploadFile string
uploadFedora bool
uploadForce bool
uploadWriteUrl string
)

func init() {
build := sdk.BuildRoot()
cmdUpload.Flags().StringVar(&uploadBucket, "bucket", "gs://users.developer.core-os.net", "gs://bucket/prefix/ prefix defaults to $USER")
cmdUpload.Flags().StringVar(&uploadImageName, "name", "", "name for uploaded image, defaults to COREOS_VERSION")
cmdUpload.Flags().StringVar(&uploadBoard, "board", "amd64-usr", "board used for naming with default prefix only")
cmdUpload.Flags().StringVar(&uploadFile, "file",
build+"/images/amd64-usr/latest/coreos_production_gce.tar.gz",
"path_to_coreos_image (build with: ./image_to_vm.sh --format=gce ...)")
cmdUpload.Flags().StringVar(&uploadBucket, "bucket", "", "gs://bucket/prefix/")
cmdUpload.MarkFlagRequired("bucket")
cmdUpload.Flags().StringVar(&uploadImageName, "name", "", "name for uploaded image")
cmdUpload.MarkFlagRequired("name")
cmdUpload.Flags().StringVar(&uploadFile, "file", "", "path to image .tar.gz file to upload")
cmdUpload.MarkFlagRequired("file")
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")
Expand All @@ -67,16 +63,6 @@ func runUpload(cmd *cobra.Command, args []string) {
os.Exit(2)
}

// if an image name is unspecified try to use version.txt
if uploadImageName == "" {
ver, err := sdk.VersionsFromDir(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)
}
uploadImageName = ver.Version
}

gsURL, err := url.Parse(uploadBucket)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand All @@ -90,19 +76,16 @@ func runUpload(cmd *cobra.Command, args []string) {
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
}
fmt.Fprint(os.Stderr, "prefix not specified. Refusing to upload in root directory of bucket\n")
os.Exit(1)
}

uploadBucket = gsURL.Host
uploadImageName = strings.TrimPrefix(gsURL.Path+"/"+uploadImageName, "/")
// create equivalent image names for GS and GCE
imageNameGS := strings.TrimPrefix(gsURL.Path+"/"+uploadImageName, "/") + ".tar.gz"

// Sanitize the image name for GCE
imageNameGCE := gceSanitize(uploadImageName)
imageNameGS := uploadImageName + ".tar.gz"

storageAPI, err := storage.New(api.Client())
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion src/cosalib/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def gcp_run_ore(build, args):
'--basename', build.build_name,
'upload',
'--force', # We want to support restarting the pipeline
'--board=""',
'--bucket', f'gs://{args.bucket}/{build.build_name}',
'--json-key', args.json_key,
'--name', gcp_name,
Expand Down