Skip to content

Commit 7ff905b

Browse files
committed
tests: start container after initial sync
1 parent f006945 commit 7ff905b

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

cmd/sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ func (cmd *SyncCmd) applyFlagsToSyncConfig(syncConfig *latest.SyncConfig, option
307307
syncConfig.ExcludePaths = cmd.Exclude
308308
}
309309
if cmd.UploadOnly {
310-
syncConfig.DisableDownload = &cmd.UploadOnly
310+
syncConfig.DisableDownload = cmd.UploadOnly
311311
}
312312
if cmd.DownloadOnly {
313-
syncConfig.DisableUpload = &cmd.DownloadOnly
313+
syncConfig.DisableUpload = cmd.DownloadOnly
314314
}
315315

316316
// if selection is specified through flags, we don't want to use the loaded

e2e/tests/replacepods/replacepods.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ var _ = DevSpaceDescribe("replacepods", func() {
6666
done <- err
6767
}()
6868

69+
// check if file is there
70+
framework.ExpectRemoteFileContents("ubuntu", ns, "/app/test2.txt", "Hello World 123")
71+
6972
// check if file is there
7073
framework.ExpectRemoteFileContents("ubuntu", ns, "/test.txt", "Hello World\n")
7174

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World 123

pkg/devspace/build/builder/restart/restart.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ var LegacyScriptPath = "/" + ScriptName
1313
// ScriptPath is the absolute path of the restart script in the container
1414
var ScriptPath = "/.devspace/" + ScriptName
1515

16+
// TouchPath is the absolute path of the touch file that signals initial syncing is done
17+
// and the container can start
18+
var TouchPath = "/.devspace/start"
19+
1620
// ScriptContextPath is the absolute path of the restart script in the build context
1721
var ScriptContextPath = "/.devspace/.devspace/" + ScriptName
1822

@@ -39,6 +43,7 @@ tmpDir="/.devspace"
3943
screenLogFile="$tmpDir/screenlog.0"
4044
pidFile="$tmpDir/devspace-pid"
4145
sidFile="$tmpDir/devspace-sid"
46+
touchFile="$tmpDir/start"
4247
4348
mkdir -p $tmpDir
4449
@@ -61,6 +66,10 @@ quit() {
6166
fi
6267
}
6368
69+
until [ -f $touchFile ]; do
70+
sleep 1
71+
done
72+
6473
while $restart; do
6574
set +e
6675
if command -v screen >/dev/null; then

pkg/devspace/config/versions/v1beta11/upgrade.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,15 @@ func (c *Config) mergeDevConfig(log log.Logger) (map[string]*next.DevPod, error)
641641
UploadExcludeFile: syncConfig.UploadExcludeFile,
642642
InitialSync: next.InitialSyncStrategy(syncConfig.InitialSync),
643643
InitialSyncCompareBy: next.InitialSyncCompareBy(syncConfig.InitialSyncCompareBy),
644-
DisableDownload: syncConfig.DisableDownload,
645-
DisableUpload: syncConfig.DisableUpload,
646644
Polling: syncConfig.Polling,
647645
WaitInitialSync: syncConfig.WaitInitialSync,
648646
}
647+
if syncConfig.DisableDownload != nil {
648+
nextSyncConfig.DisableDownload = *syncConfig.DisableDownload
649+
}
650+
if syncConfig.DisableUpload != nil {
651+
nextSyncConfig.DisableUpload = *syncConfig.DisableUpload
652+
}
649653
syncPath := "."
650654
if syncConfig.LocalSubPath != "" {
651655
syncPath = syncConfig.LocalSubPath

pkg/devspace/services/sync/controller.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,8 @@ func (c *controller) initClient(ctx *devspacecontext.Context, pod *v1.Pod, arch,
331331
return nil, err
332332
}
333333

334-
upstreamDisabled := false
335-
if syncConfig.DisableUpload != nil {
336-
upstreamDisabled = *syncConfig.DisableUpload
337-
}
338-
339-
downstreamDisabled := false
340-
if syncConfig.DisableDownload != nil {
341-
downstreamDisabled = *syncConfig.DisableDownload
342-
}
343-
334+
upstreamDisabled := syncConfig.DisableUpload
335+
downstreamDisabled := syncConfig.DisableDownload
344336
compareBy := latest.InitialSyncCompareByMTime
345337
if syncConfig.InitialSyncCompareBy != "" {
346338
compareBy = syncConfig.InitialSyncCompareBy

pkg/devspace/sync/upstream.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"compress/gzip"
77
"context"
88
"fmt"
9+
"github.com/loft-sh/devspace/pkg/devspace/build/builder/restart"
910
"github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
1011
"github.com/loft-sh/devspace/pkg/util/fsutil"
1112
"io"
@@ -29,6 +30,10 @@ import (
2930
"github.com/pkg/errors"
3031
)
3132

33+
var (
34+
TouchFile = ""
35+
)
36+
3237
type upstream struct {
3338
events chan notify.EventInfo
3439
symlinks map[string]*Symlink
@@ -49,6 +54,7 @@ type upstream struct {
4954
initialSyncCompletedMutex sync.Mutex
5055
initialSyncChanges []string
5156
initialSyncCompleted bool
57+
initialSyncTouchOnce sync.Once
5258
}
5359

5460
const (
@@ -249,10 +255,22 @@ func (u *upstream) mainLoop() error {
249255
}
250256
}
251257

252-
func (u *upstream) execCommandsAfterInitialSync() error {
258+
func (u *upstream) execCommandsAfterInitialSync() (err error) {
253259
u.initialSyncCompletedMutex.Lock()
254260
defer u.initialSyncCompletedMutex.Unlock()
255261

262+
// make sure the touch file is there
263+
defer func() {
264+
if err == nil && u.sync.Options.RestartContainer && u.initialSyncCompleted {
265+
u.initialSyncTouchOnce.Do(func() {
266+
_, err = u.client.Execute(u.sync.ctx, &remote.Command{
267+
Cmd: "touch",
268+
Args: []string{restart.TouchPath},
269+
})
270+
})
271+
}
272+
}()
273+
256274
if !u.initialSyncCompleted || len(u.initialSyncChanges) == 0 {
257275
return nil
258276
}

0 commit comments

Comments
 (0)