From 849ebba0186ba653e018f1834b54cefa537d9071 Mon Sep 17 00:00:00 2001 From: fabiankramm Date: Fri, 28 Sep 2018 14:53:04 +0200 Subject: [PATCH] Implement #257 --- cmd/up.go | 17 +++++++++++++-- pkg/devspace/config/v1/devspace.go | 1 + pkg/devspace/sync/downstream.go | 8 ++++---- pkg/devspace/sync/evaluater.go | 7 +++++-- pkg/devspace/sync/upstream.go | 2 +- pkg/util/hash/hash.go | 33 ++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 pkg/util/hash/hash.go diff --git a/cmd/up.go b/cmd/up.go index 215d12272d..1af07d0431 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/covexo/devspace/pkg/util/hash" "github.com/covexo/devspace/pkg/util/stdinutil" "github.com/covexo/devspace/pkg/util/yamlutil" @@ -159,10 +160,22 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) { mustRedeploy := cmd.buildImages() // Check if we find a running release pod - pod, err := getRunningDevSpacePod(cmd.helm, cmd.kubectl) + config := configutil.GetConfig(false) + hash, err := hash.Directory("chart") + if err != nil { + log.Fatalf("Error hashing chart directory: %v", err) + } - if err != nil || mustRedeploy || cmd.flags.deploy { + pod, err := getRunningDevSpacePod(cmd.helm, cmd.kubectl) + if err != nil || mustRedeploy || cmd.flags.deploy || config.DevSpace.ChartHash == nil || *config.DevSpace.ChartHash != hash { cmd.deployChart() + + config.DevSpace.ChartHash = &hash + + err = configutil.SaveConfig() + if err != nil { + log.Fatalf("Error saving config: %v", err) + } } else { cmd.pod = pod } diff --git a/pkg/devspace/config/v1/devspace.go b/pkg/devspace/config/v1/devspace.go index f1fefad033..af96f57dd0 100644 --- a/pkg/devspace/config/v1/devspace.go +++ b/pkg/devspace/config/v1/devspace.go @@ -4,6 +4,7 @@ package v1 type DevSpaceConfig struct { Terminal *Terminal `yaml:"terminal"` Release *Release `yaml:"release"` + ChartHash *string `yaml:"chartHash"` PortForwarding *[]*PortForwardingConfig `yaml:"portForwarding"` Sync *[]*SyncConfig `yaml:"sync"` } diff --git a/pkg/devspace/sync/downstream.go b/pkg/devspace/sync/downstream.go index 21b28640ad..5ab703cfa1 100644 --- a/pkg/devspace/sync/downstream.go +++ b/pkg/devspace/sync/downstream.go @@ -248,7 +248,7 @@ func (d *downstream) downloadFiles(files []*fileInformation) (string, error) { sleep 0.1; done; - tar -czf "$tmpFileOutput" -T "$tmpFileInput" 2>/dev/null; + tar -czf "$tmpFileOutput" -T "$tmpFileInput" 2>/tmp/devspace-downstream-error; (>&2 echo "` + StartAck + `"); (>&2 echo $(stat -c "%s" "$tmpFileOutput")); (>&2 echo "` + EndAck + `"); @@ -344,11 +344,11 @@ func (d *downstream) removeFilesAndFolders(removeFiles map[string]*fileInformati } else { err := os.Remove(absFilepath) if err != nil { - d.config.Logf("[Downstream] Skip file delete %s: %v", key, err) + if os.IsNotExist(err) == false { + d.config.Logf("[Downstream] Skip file delete %s: %v", key, err) + } } } - } else { - d.config.Logf("[Downstream] Skip delete %s", key) } delete(fileMap, key) diff --git a/pkg/devspace/sync/evaluater.go b/pkg/devspace/sync/evaluater.go index 96d6fad824..f36cd2f9f1 100644 --- a/pkg/devspace/sync/evaluater.go +++ b/pkg/devspace/sync/evaluater.go @@ -149,7 +149,7 @@ func shouldRemoveLocal(absFilepath string, fileInformation *fileInformation, s * // Exclude files on the exclude list if s.downloadIgnoreMatcher != nil { if s.downloadIgnoreMatcher.MatchesPath(fileInformation.Name) { - s.Logf("Skip %s because downloadIgnoreMatcher matched", absFilepath) + // s.Logf("Skip %s because downloadIgnoreMatcher matched", absFilepath) return false } } @@ -157,7 +157,10 @@ func shouldRemoveLocal(absFilepath string, fileInformation *fileInformation, s * // Only delete if mtime and size did not change stat, err := os.Stat(absFilepath) if err != nil { - s.Logf("Skip %s because stat returned %v", absFilepath, stat) + if os.IsNotExist(err) == false { + s.Logf("Skip %s because stat returned %v", absFilepath, err) + } + return false } diff --git a/pkg/devspace/sync/upstream.go b/pkg/devspace/sync/upstream.go index 2951ec7ad4..a775aab10e 100644 --- a/pkg/devspace/sync/upstream.go +++ b/pkg/devspace/sync/upstream.go @@ -313,7 +313,7 @@ func (u *upstream) uploadArchive(file *os.File, fileSize string, writtenFiles ma sleep 0.1; done; - tar xzpf "$tmpFile" -C '` + u.config.DestPath + `/.' 2>/dev/null; + tar xzpf "$tmpFile" -C '` + u.config.DestPath + `/.' 2>/tmp/devspace-upstream-error; echo "` + EndAck + `"; ` // We need that extra new line or otherwise the command is not sent diff --git a/pkg/util/hash/hash.go b/pkg/util/hash/hash.go new file mode 100644 index 0000000000..12ac0be1ac --- /dev/null +++ b/pkg/util/hash/hash.go @@ -0,0 +1,33 @@ +package hash + +import ( + "crypto/sha256" + "fmt" + "io" + "os" + "path/filepath" + "strconv" +) + +// Directory creates the hash value of a directory +func Directory(path string) (string, error) { + hash := sha256.New() + err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error { + if err != nil { + // We ignore errors + return nil + } + + size := strconv.FormatInt(info.Size(), 10) + mTime := strconv.FormatInt(info.ModTime().UnixNano(), 10) + io.WriteString(hash, path+";"+size+";"+mTime) + + return nil + }) + + if err != nil { + return "", err + } + + return fmt.Sprintf("%x", hash.Sum(nil)), nil +}