From 1c9ff3e562f05c1a54eb7e0d2bafbbb69f7b7742 Mon Sep 17 00:00:00 2001 From: Pritesh Arora <60378152+pritt20@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:17:54 +0530 Subject: [PATCH] Implement gzip for dag bundle compression for cloud deploys (#1778) Co-authored-by: Pritesh Arora --- cloud/deploy/bundle.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/cloud/deploy/bundle.go b/cloud/deploy/bundle.go index a3066b742..900f4c488 100644 --- a/cloud/deploy/bundle.go +++ b/cloud/deploy/bundle.go @@ -142,11 +142,18 @@ func DeleteBundle(input *DeleteBundleInput) error { func uploadBundle(tarDirPath, bundlePath, uploadURL string, prependBaseDir bool) (string, error) { tarFilePath := filepath.Join(tarDirPath, "bundle.tar") + tarGzFilePath := tarFilePath + ".gz" defer func() { - err := os.Remove(tarFilePath) - if err != nil { - fmt.Println("\nFailed to delete tar file: ", err.Error()) - fmt.Println("\nPlease delete the tar file manually from path: " + tarFilePath) + tarFiles := []string{tarFilePath, tarGzFilePath} + for _, file := range tarFiles { + err := os.Remove(file) + if err != nil { + if os.IsNotExist(err) { + continue + } + fmt.Println("\nFailed to delete archived file: ", err.Error()) + fmt.Println("\nPlease delete the archived file manually from path: " + file) + } } }() @@ -156,13 +163,19 @@ func uploadBundle(tarDirPath, bundlePath, uploadURL string, prependBaseDir bool) return "", err } - tarFile, err := os.Open(tarFilePath) + // Gzip the tar + err = fileutil.GzipFile(tarFilePath, tarGzFilePath) + if err != nil { + return "", err + } + + tarGzFile, err := os.Open(tarGzFilePath) if err != nil { return "", err } - defer tarFile.Close() + defer tarGzFile.Close() - versionID, err := azureUploader(uploadURL, tarFile) + versionID, err := azureUploader(uploadURL, tarGzFile) if err != nil { return "", err }