Upload benchmarks to GCS. (#523)
This commit is contained in:
		
							parent
							
								
									6e7c91a1cb
								
							
						
					
					
						commit
						b0e7c0e8cd
					
				|  | @ -22,7 +22,6 @@ import ( | |||
| 	"log" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
| 	"path/filepath" | ||||
| 	"time" | ||||
| ) | ||||
| 
 | ||||
|  | @ -49,16 +48,16 @@ func CreateIntegrationTarball() (string, error) { | |||
| 
 | ||||
| // UploadFileToBucket will upload the at filePath to gcsBucket. It will return the path
 | ||||
| // of the file in gcsBucket.
 | ||||
| func UploadFileToBucket(gcsBucket string, filePath string) (string, error) { | ||||
| 	log.Printf("Uploading file at %s to GCS bucket at %s\n", filePath, gcsBucket) | ||||
| func UploadFileToBucket(gcsBucket string, filePath string, gcsPath string) (string, error) { | ||||
| 	dst := fmt.Sprintf("%s/%s", gcsBucket, gcsPath) | ||||
| 	log.Printf("Uploading file at %s to GCS bucket at %s\n", filePath, dst) | ||||
| 
 | ||||
| 	cmd := exec.Command("gsutil", "cp", filePath, gcsBucket) | ||||
| 	_, err := RunCommandWithoutTest(cmd) | ||||
| 	if err != nil { | ||||
| 	cmd := exec.Command("gsutil", "cp", filePath, dst) | ||||
| 	if _, err := RunCommandWithoutTest(cmd); err != nil { | ||||
| 		return "", fmt.Errorf("Failed to copy tarball to GCS bucket %s: %s", gcsBucket, err) | ||||
| 	} | ||||
| 
 | ||||
| 	return filepath.Join(gcsBucket, filePath), err | ||||
| 	return dst, nil | ||||
| } | ||||
| 
 | ||||
| // DeleteFromBucket will remove the content at path. path should be the full path
 | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ import ( | |||
| 	"runtime" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/timing" | ||||
| ) | ||||
|  | @ -195,6 +196,9 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do | |||
| 	} | ||||
| 	if b, err := strconv.ParseBool(os.Getenv("BENCHMARK")); err == nil && b { | ||||
| 		benchmarkEnv = "BENCHMARK_FILE=/kaniko/benchmarks/" + dockerfile | ||||
| 		benchmarkFile := path.Join("benchmarks", dockerfile) | ||||
| 		dst := path.Join("benchmarks/run_"+time.Now().Format("2006-01-02 15:04:05"), dockerfile) | ||||
| 		defer UploadFileToBucket(gcsBucket, benchmarkFile, dst) | ||||
| 	} | ||||
| 
 | ||||
| 	// build kaniko image
 | ||||
|  |  | |||
|  | @ -127,7 +127,7 @@ func TestMain(m *testing.M) { | |||
| 		os.Exit(1) | ||||
| 	} | ||||
| 
 | ||||
| 	fileInBucket, err := UploadFileToBucket(config.gcsBucket, contextFile) | ||||
| 	fileInBucket, err := UploadFileToBucket(config.gcsBucket, contextFile, contextFile) | ||||
| 	if err != nil { | ||||
| 		fmt.Println("Failed to upload build context", err) | ||||
| 		os.Exit(1) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue