Skip to content

Commit 849ebba

Browse files
committed
Implement #257
1 parent 66789d1 commit 849ebba

6 files changed

Lines changed: 59 additions & 9 deletions

File tree

cmd/up.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/covexo/devspace/pkg/util/hash"
1213
"github.com/covexo/devspace/pkg/util/stdinutil"
1314

1415
"github.com/covexo/devspace/pkg/util/yamlutil"
@@ -159,10 +160,22 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
159160
mustRedeploy := cmd.buildImages()
160161

161162
// Check if we find a running release pod
162-
pod, err := getRunningDevSpacePod(cmd.helm, cmd.kubectl)
163+
config := configutil.GetConfig(false)
164+
hash, err := hash.Directory("chart")
165+
if err != nil {
166+
log.Fatalf("Error hashing chart directory: %v", err)
167+
}
163168

164-
if err != nil || mustRedeploy || cmd.flags.deploy {
169+
pod, err := getRunningDevSpacePod(cmd.helm, cmd.kubectl)
170+
if err != nil || mustRedeploy || cmd.flags.deploy || config.DevSpace.ChartHash == nil || *config.DevSpace.ChartHash != hash {
165171
cmd.deployChart()
172+
173+
config.DevSpace.ChartHash = &hash
174+
175+
err = configutil.SaveConfig()
176+
if err != nil {
177+
log.Fatalf("Error saving config: %v", err)
178+
}
166179
} else {
167180
cmd.pod = pod
168181
}

pkg/devspace/config/v1/devspace.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package v1
44
type DevSpaceConfig struct {
55
Terminal *Terminal `yaml:"terminal"`
66
Release *Release `yaml:"release"`
7+
ChartHash *string `yaml:"chartHash"`
78
PortForwarding *[]*PortForwardingConfig `yaml:"portForwarding"`
89
Sync *[]*SyncConfig `yaml:"sync"`
910
}

pkg/devspace/sync/downstream.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (d *downstream) downloadFiles(files []*fileInformation) (string, error) {
248248
249249
sleep 0.1;
250250
done;
251-
tar -czf "$tmpFileOutput" -T "$tmpFileInput" 2>/dev/null;
251+
tar -czf "$tmpFileOutput" -T "$tmpFileInput" 2>/tmp/devspace-downstream-error;
252252
(>&2 echo "` + StartAck + `");
253253
(>&2 echo $(stat -c "%s" "$tmpFileOutput"));
254254
(>&2 echo "` + EndAck + `");
@@ -344,11 +344,11 @@ func (d *downstream) removeFilesAndFolders(removeFiles map[string]*fileInformati
344344
} else {
345345
err := os.Remove(absFilepath)
346346
if err != nil {
347-
d.config.Logf("[Downstream] Skip file delete %s: %v", key, err)
347+
if os.IsNotExist(err) == false {
348+
d.config.Logf("[Downstream] Skip file delete %s: %v", key, err)
349+
}
348350
}
349351
}
350-
} else {
351-
d.config.Logf("[Downstream] Skip delete %s", key)
352352
}
353353

354354
delete(fileMap, key)

pkg/devspace/sync/evaluater.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,18 @@ func shouldRemoveLocal(absFilepath string, fileInformation *fileInformation, s *
149149
// Exclude files on the exclude list
150150
if s.downloadIgnoreMatcher != nil {
151151
if s.downloadIgnoreMatcher.MatchesPath(fileInformation.Name) {
152-
s.Logf("Skip %s because downloadIgnoreMatcher matched", absFilepath)
152+
// s.Logf("Skip %s because downloadIgnoreMatcher matched", absFilepath)
153153
return false
154154
}
155155
}
156156

157157
// Only delete if mtime and size did not change
158158
stat, err := os.Stat(absFilepath)
159159
if err != nil {
160-
s.Logf("Skip %s because stat returned %v", absFilepath, stat)
160+
if os.IsNotExist(err) == false {
161+
s.Logf("Skip %s because stat returned %v", absFilepath, err)
162+
}
163+
161164
return false
162165
}
163166

pkg/devspace/sync/upstream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (u *upstream) uploadArchive(file *os.File, fileSize string, writtenFiles ma
313313
sleep 0.1;
314314
done;
315315
316-
tar xzpf "$tmpFile" -C '` + u.config.DestPath + `/.' 2>/dev/null;
316+
tar xzpf "$tmpFile" -C '` + u.config.DestPath + `/.' 2>/tmp/devspace-upstream-error;
317317
echo "` + EndAck + `";
318318
` // We need that extra new line or otherwise the command is not sent
319319

pkg/util/hash/hash.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package hash
2+
3+
import (
4+
"crypto/sha256"
5+
"fmt"
6+
"io"
7+
"os"
8+
"path/filepath"
9+
"strconv"
10+
)
11+
12+
// Directory creates the hash value of a directory
13+
func Directory(path string) (string, error) {
14+
hash := sha256.New()
15+
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
16+
if err != nil {
17+
// We ignore errors
18+
return nil
19+
}
20+
21+
size := strconv.FormatInt(info.Size(), 10)
22+
mTime := strconv.FormatInt(info.ModTime().UnixNano(), 10)
23+
io.WriteString(hash, path+";"+size+";"+mTime)
24+
25+
return nil
26+
})
27+
28+
if err != nil {
29+
return "", err
30+
}
31+
32+
return fmt.Sprintf("%x", hash.Sum(nil)), nil
33+
}

0 commit comments

Comments
 (0)