Skip to content

Commit

Permalink
Merge pull request #263 from covexo/deploy-hash
Browse files Browse the repository at this point in the history
Implement #257
  • Loading branch information
FabianKramm committed Sep 28, 2018
2 parents 66789d1 + 849ebba commit e4f6d9a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
17 changes: 15 additions & 2 deletions cmd/up.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/devspace/config/v1/devspace.go
Expand Up @@ -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"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/devspace/sync/downstream.go
Expand Up @@ -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 + `");
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions pkg/devspace/sync/evaluater.go
Expand Up @@ -149,15 +149,18 @@ 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
}
}

// 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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/devspace/sync/upstream.go
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions 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
}

0 comments on commit e4f6d9a

Please sign in to comment.