From 9d33f3a1cee41e81f5b206c4aba7882f77110299 Mon Sep 17 00:00:00 2001 From: Wes Date: Thu, 4 Apr 2024 11:23:56 -0700 Subject: [PATCH] fix: ensure we detect changes during initial deploy (#1175) Fixes #1161 --- buildengine/engine.go | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/buildengine/engine.go b/buildengine/engine.go index 1ba9a5e95f..f7cfcceb28 100644 --- a/buildengine/engine.go +++ b/buildengine/engine.go @@ -207,23 +207,28 @@ func (e *Engine) Deploy(ctx context.Context, replicas int32, waitForDeployOnline // Dev builds and deploys all local modules and watches for changes, redeploying as necessary. func (e *Engine) Dev(ctx context.Context, period time.Duration) error { + return e.watchForModuleChanges(ctx, period) +} + +func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration) error { logger := log.FromContext(ctx) + schemaChanges := make(chan schemaChange, 128) + e.schemaChanges.Subscribe(schemaChanges) + defer e.schemaChanges.Unsubscribe(schemaChanges) + + watchEvents := make(chan WatchEvent, 128) + watch := Watch(ctx, period, e.moduleDirs, e.externalDirs) + watch.Subscribe(watchEvents) + defer watch.Unsubscribe(watchEvents) + defer watch.Close() + // Build and deploy all modules first. err := e.buildAndDeploy(ctx, 1, true) if err != nil { logger.Errorf(err, "initial deploy failed") } - logger.Infof("All modules deployed, watching for changes...") - - // Then watch for changes and redeploy. - return e.watchForModuleChanges(ctx, period) -} - -func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration) error { - logger := log.FromContext(ctx) - moduleHashes := map[string][]byte{} e.controllerSchema.Range(func(name string, sch *schema.Module) bool { hash, err := computeModuleHash(sch) @@ -235,16 +240,6 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration return true }) - schemaChanges := make(chan schemaChange, 128) - e.schemaChanges.Subscribe(schemaChanges) - defer e.schemaChanges.Unsubscribe(schemaChanges) - - watchEvents := make(chan WatchEvent, 128) - watch := Watch(ctx, period, e.moduleDirs, e.externalDirs) - watch.Subscribe(watchEvents) - defer watch.Unsubscribe(watchEvents) - defer watch.Close() - // Watch for file and schema changes for { select {