From ccfbcceebdc342edbef040eccb36042e8d3243f4 Mon Sep 17 00:00:00 2001
From: Dave Tucker
Date: Tue, 2 May 2017 12:36:09 +0100
Subject: [PATCH 1/2] linuxkit: Make gcp push honour the img-name flag
This fixes a regression where `linuxkit push gcp` no longer allows for a
custom destination to be provided via the `-img-name` flag or the
`CLOUDSDK_IMAGE_NAME` environment variable
Signed-off-by: Dave Tucker
---
src/cmd/linuxkit/push_gcp.go | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/src/cmd/linuxkit/push_gcp.go b/src/cmd/linuxkit/push_gcp.go
index 79860fe4d..6724004bb 100644
--- a/src/cmd/linuxkit/push_gcp.go
+++ b/src/cmd/linuxkit/push_gcp.go
@@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
- "strings"
log "github.com/Sirupsen/logrus"
)
@@ -25,7 +24,7 @@ func pushGcp(args []string) {
bucketFlag := gcpCmd.String("bucket", "", "GS Bucket to upload to. *Required*")
publicFlag := gcpCmd.Bool("public", false, "Select if file on GS should be public. *Optional*")
familyFlag := gcpCmd.String("family", "", "GCP Image Family. A group of images where the family name points to the most recent image. *Optional*")
- nameFlag := gcpCmd.String("img-name", "", "Overrides the Name used to identify the file in Google Storage and Image. Defaults to [name]")
+ nameFlag := gcpCmd.String("img-name", "", "Overrides the Name used to identify the file in Google Storage and Image. Defaults to [name] with the '.img.tar.gz' suffix removed")
if err := gcpCmd.Parse(args); err != nil {
log.Fatal("Unable to parse args")
@@ -37,7 +36,8 @@ func pushGcp(args []string) {
gcpCmd.Usage()
os.Exit(1)
}
- prefix := remArgs[0]
+ src := remArgs[0]
+ suffix := ".img.tar.gz"
keys := getStringValue(keysVar, *keysFlag, "")
project := getStringValue(projectVar, *projectFlag, "")
@@ -51,24 +51,19 @@ func pushGcp(args []string) {
log.Fatalf("Unable to connect to GCP")
}
- suffix := ".img.tar.gz"
- src := prefix
- if strings.HasSuffix(prefix, suffix) {
- prefix = prefix[:len(prefix)-len(suffix)]
- } else {
- src = prefix + suffix
- }
- if name != "" {
- prefix = name
+ if name == "" {
+ name = src[:len(src)-len(suffix)]
}
+
if bucket == "" {
log.Fatalf("No bucket specified. Please provide one using the -bucket flag")
}
- err = client.UploadFile(src, prefix+suffix, bucket, public)
+
+ err = client.UploadFile(src, name+suffix, bucket, public)
if err != nil {
log.Fatalf("Error copying to Google Storage: %v", err)
}
- err = client.CreateImage(prefix, "https://storage.googleapis.com/"+bucket+"/"+prefix+".img.tar.gz", family, true)
+ err = client.CreateImage(name, "https://storage.googleapis.com/"+bucket+"/"+name+suffix, family, true)
if err != nil {
log.Fatalf("Error creating Google Compute Image: %v", err)
}
From cda03f7e0d7f1de3f1194f186e4d75377c4f8c02 Mon Sep 17 00:00:00 2001
From: Dave Tucker
Date: Tue, 2 May 2017 12:38:27 +0100
Subject: [PATCH 2/2] Makefile: Use the name provided to upload in run
This fixes an issue introduced in the split of push and run.
Before this commit, an image could be pushed to a custom location from
the presence of the `CLOUDSDK_IMAGE_NAME` variable. The subsquent run
would fail as the name `test-ltp` or `test` had been hard coded in the
Make target. We now use a target-specific variable which is only set if
there is not an existing variable in the environment
Signed-off-by: Dave Tucker
---
Makefile | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index fa3730449..6a32055de 100644
--- a/Makefile
+++ b/Makefile
@@ -58,9 +58,10 @@ test-hyperkit: $(LINUXKIT) test-initrd.img test-bzImage test-cmdline
$(call check_test_log, test.log)
.PHONY: test-gcp
+test-gcp: export CLOUDSDK_IMAGE_NAME?=test
test-gcp: $(LINUXKIT) test.img.tar.gz
$(LINUXKIT) push gcp test.img.tar.gz
- $(LINUXKIT) run gcp test | tee test-gcp.log
+ $(LINUXKIT) run gcp $(CLOUDSDK_IMAGE_NAME) | tee test-gcp.log
$(call check_test_log, test-gcp.log)
.PHONY: test
@@ -72,9 +73,10 @@ test-ltp.img.tar.gz: $(MOBY) test/ltp/test-ltp.yml
$(MOBY) build --pull test/ltp/test-ltp.yml
.PHONY: test-ltp
+test-ltp: export CLOUDSDK_IMAGE_NAME?=test-ltp
test-ltp: $(LINUXKIT) test-ltp.img.tar.gz
$(LINUXKIT) push gcp test-ltp.img.tar.gz
- $(LINUXKIT) run gcp -skip-cleanup -machine n1-highcpu-4 test-ltp | tee test-ltp.log
+ $(LINUXKIT) run gcp -skip-cleanup -machine n1-highcpu-4 $(CLOUDSDK_IMAGE_NAME) | tee test-ltp.log
$(call check_test_log, test-ltp.log)
.PHONY: ci ci-tag ci-pr