Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure we detect changes during initial deploy #1175

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Loading