Skip to content

Commit 2836094

Browse files
committed
feat: add nowatch to sync
1 parent 85e3231 commit 2836094

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

cmd/sync.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ type SyncCmd struct {
4545

4646
InitialSync string
4747

48-
Verbose bool
49-
5048
NoWatch bool
5149
DownloadOnInitialSync bool
5250
DownloadOnly bool
@@ -97,7 +95,6 @@ devspace sync --container-path=/my-path
9795
syncCmd.Flags().StringVar(&cmd.InitialSync, "initial-sync", "", "The initial sync strategy to use (mirrorLocal, mirrorRemote, preferLocal, preferRemote, preferNewest, keepAll)")
9896

9997
syncCmd.Flags().BoolVar(&cmd.NoWatch, "no-watch", false, "Synchronizes local and remote and then stops")
100-
syncCmd.Flags().BoolVar(&cmd.Verbose, "verbose", false, "Shows every file that is synced")
10198

10299
syncCmd.Flags().BoolVar(&cmd.UploadOnly, "upload-only", false, "If set DevSpace will only upload files")
103100
syncCmd.Flags().BoolVar(&cmd.DownloadOnly, "download-only", false, "If set DevSpace will only download files")
@@ -275,7 +272,7 @@ func (cmd *SyncCmd) Run(f factory.Factory) error {
275272

276273
// Start sync
277274
options = options.WithSkipInitContainers(true)
278-
return sync.StartSyncFromCmd(ctx, targetselector.NewTargetSelector(options), syncConfig.devPod.Name, syncConfig.syncConfig, cmd.NoWatch, cmd.Verbose)
275+
return sync.StartSyncFromCmd(ctx, targetselector.NewTargetSelector(options), syncConfig.devPod.Name, syncConfig.syncConfig, cmd.NoWatch)
279276
}
280277

281278
func fromSyncConfig(devPod *latest.DevPod, containerName string, sc *latest.SyncConfig) (nameConfig, error) {

pkg/devspace/config/versions/latest/schema.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,9 @@ type SyncConfig struct {
810810
InitialSync InitialSyncStrategy `yaml:"initialSync,omitempty" json:"initialSync,omitempty"`
811811
InitialSyncCompareBy InitialSyncCompareBy `yaml:"initialSyncCompareBy,omitempty" json:"initialSyncCompareBy,omitempty"`
812812

813-
DisableDownload *bool `yaml:"disableDownload,omitempty" json:"disableDownload,omitempty"`
814-
DisableUpload *bool `yaml:"disableUpload,omitempty" json:"disableUpload,omitempty"`
813+
DisableDownload bool `yaml:"disableDownload,omitempty" json:"disableDownload,omitempty"`
814+
DisableUpload bool `yaml:"disableUpload,omitempty" json:"disableUpload,omitempty"`
815+
NoWatch bool `yaml:"noWatch,omitempty" json:"noWatch,omitempty"`
815816

816817
Polling bool `yaml:"polling,omitempty" json:"polling,omitempty"`
817818

pkg/devspace/services/sync/sync.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sync
22

33
import (
4+
"context"
45
"fmt"
56
"github.com/loft-sh/devspace/pkg/devspace/config/loader"
67
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
@@ -12,7 +13,7 @@ import (
1213
)
1314

1415
// StartSyncFromCmd starts a new sync from command
15-
func StartSyncFromCmd(ctx *devspacecontext.Context, selector targetselector.TargetSelector, name string, syncConfig *latest.SyncConfig, noWatch, verbose bool) error {
16+
func StartSyncFromCmd(ctx *devspacecontext.Context, selector targetselector.TargetSelector, name string, syncConfig *latest.SyncConfig, noWatch bool) error {
1617
ctx, parent := ctx.WithNewTomb()
1718
options := &Options{
1819
Name: name,
@@ -21,7 +22,7 @@ func StartSyncFromCmd(ctx *devspacecontext.Context, selector targetselector.Targ
2122
RestartOnError: true,
2223
SyncLog: ctx.Log,
2324

24-
Verbose: verbose,
25+
Verbose: ctx.Log.GetLevel() == logrus.DebugLevel,
2526
}
2627

2728
// Start the tomb
@@ -69,9 +70,22 @@ func StartSync(ctx *devspacecontext.Context, devPod *latest.DevPod, selector tar
6970
loader.EachDevContainer(devPod, func(devContainer *latest.DevContainer) bool {
7071
for i, syncConfig := range devContainer.Sync {
7172
// start a new go routine in the tomb
72-
initDoneArray = append(initDoneArray, parent.NotifyGo(func() error {
73-
return startSync(ctx, devPod.Name, string(devContainer.Arch), syncConfig, selector.WithContainer(devContainer.Container), parent)
74-
}))
73+
s := syncConfig
74+
var cancel context.CancelFunc
75+
if s.NoWatch {
76+
var cancelCtx context.Context
77+
cancelCtx, cancel = context.WithCancel(ctx.Context)
78+
defer cancel()
79+
ctx = ctx.WithContext(cancelCtx)
80+
}
81+
initDone := parent.NotifyGo(func() error {
82+
if cancel != nil {
83+
defer cancel()
84+
}
85+
86+
return startSync(ctx, devPod.Name, string(devContainer.Arch), s, selector.WithContainer(devContainer.Container), parent)
87+
})
88+
initDoneArray = append(initDoneArray, initDone)
7589

7690
// every five we wait
7791
if i%5 == 0 {

0 commit comments

Comments
 (0)