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