Compare commits

...

17 commits

Author SHA1 Message Date
Luke Hoban ae2f5db7e7 Fix lint issues 2021-06-21 05:53:09 +10:00
Luke Hoban f90ece4462 Merge branch 'watch-cmd-paths' of git://github.com/doitadrian/pulumi into doitadrian-watch-cmd-paths 2021-06-21 05:43:47 +10:00
Adrian Smijulj 57ad7a9bae Update descriptions 2021-06-12 08:03:53 +02:00
Adrian Smijulj c4f4062b0f Add support for watching absolute paths 2021-06-12 07:59:47 +02:00
Adrian Smijulj 19865df412 Add "paths" argument 2021-06-11 16:10:16 +02:00
Adrian Smijulj 61cce63199 Add "paths" argument to Watch function 2021-06-11 16:10:00 +02:00
Adrian Smijulj c66233049b Add "paths" as the last function parameter 2021-06-11 16:09:30 +02:00
Adrian Smijulj 108f0bc467 Rename variable 2021-06-11 16:08:41 +02:00
Adrian Smijulj efc6d8801d Assign pathArray as the last argument 2021-06-11 16:08:19 +02:00
Adrian Smijulj d3f8a02f4c Add "paths" argument to Watch function 2021-06-11 15:10:23 +02:00
Adrian Smijulj 5da85b1b2c Remove WatchPaths from UpdateOptions 2021-06-11 15:08:37 +02:00
Adrian Smijulj 20f79f2232 Add default value 2021-06-11 10:38:09 +02:00
Adrian Smijulj a91aefc1c3 Refactor notify.Watch call 2021-06-11 10:37:49 +02:00
Adrian Smijulj 6ab9dc20bd Update changelog 2021-06-08 21:14:13 +02:00
Adrian Smijulj 04057c1558 Handle custom paths 2021-06-08 20:57:36 +02:00
Adrian Smijulj 0315c18756 Introduce path argument 2021-06-08 20:56:29 +02:00
Adrian Smijulj 811beae23c Add WatchPaths to UpdateOptions 2021-06-08 20:52:03 +02:00
10 changed files with 49 additions and 25 deletions

View file

@ -2,4 +2,9 @@
### Improvements
- [cli] - Added support for passing custom paths that need
to be watched by the `pulumi watch` command.
[#7115](https://github.com/pulumi/pulumi/pull/7247)
### Bug Fixes

View file

@ -164,7 +164,7 @@ type Backend interface {
// Destroy destroys all of this stack's resources.
Destroy(ctx context.Context, stack Stack, op UpdateOperation) (engine.ResourceChanges, result.Result)
// Watch watches the project's working directory for changes and automatically updates the active stack.
Watch(ctx context.Context, stack Stack, op UpdateOperation) result.Result
Watch(ctx context.Context, stack Stack, op UpdateOperation, paths []string) result.Result
// Query against the resource outputs in a stack's state checkpoint.
Query(ctx context.Context, op QueryOperation) result.Result

View file

@ -534,8 +534,8 @@ func (b *localBackend) Query(ctx context.Context, op backend.QueryOperation) res
}
func (b *localBackend) Watch(ctx context.Context, stack backend.Stack,
op backend.UpdateOperation) result.Result {
return backend.Watch(ctx, b, stack, op, b.apply)
op backend.UpdateOperation, paths []string) result.Result {
return backend.Watch(ctx, b, stack, op, b.apply, paths)
}
// apply actually performs the provided type of update on a locally hosted stack.

View file

@ -85,8 +85,8 @@ func (s *localStack) Destroy(ctx context.Context, op backend.UpdateOperation) (e
return backend.DestroyStack(ctx, s, op)
}
func (s *localStack) Watch(ctx context.Context, op backend.UpdateOperation) result.Result {
return backend.WatchStack(ctx, s, op)
func (s *localStack) Watch(ctx context.Context, op backend.UpdateOperation, paths []string) result.Result {
return backend.WatchStack(ctx, s, op, paths)
}
func (s *localStack) GetLogs(ctx context.Context, cfg backend.StackConfiguration,

View file

@ -853,8 +853,8 @@ func (b *cloudBackend) Destroy(ctx context.Context, stack backend.Stack,
}
func (b *cloudBackend) Watch(ctx context.Context, stack backend.Stack,
op backend.UpdateOperation) result.Result {
return backend.Watch(ctx, b, stack, op, b.apply)
op backend.UpdateOperation, paths []string) result.Result {
return backend.Watch(ctx, b, stack, op, b.apply, paths)
}
func (b *cloudBackend) Query(ctx context.Context, op backend.QueryOperation) result.Result {

View file

@ -161,8 +161,8 @@ func (s *cloudStack) Destroy(ctx context.Context, op backend.UpdateOperation) (e
return backend.DestroyStack(ctx, s, op)
}
func (s *cloudStack) Watch(ctx context.Context, op backend.UpdateOperation) result.Result {
return backend.WatchStack(ctx, s, op)
func (s *cloudStack) Watch(ctx context.Context, op backend.UpdateOperation, paths []string) result.Result {
return backend.WatchStack(ctx, s, op, paths)
}
func (s *cloudStack) GetLogs(ctx context.Context, cfg backend.StackConfiguration,

View file

@ -66,7 +66,7 @@ type MockBackend struct {
DestroyF func(context.Context, Stack,
UpdateOperation) (engine.ResourceChanges, result.Result)
WatchF func(context.Context, Stack,
UpdateOperation) result.Result
UpdateOperation, []string) result.Result
GetLogsF func(context.Context, Stack, StackConfiguration,
operations.LogQuery) ([]operations.LogEntry, error)
}
@ -221,10 +221,10 @@ func (be *MockBackend) Destroy(ctx context.Context, stack Stack,
}
func (be *MockBackend) Watch(ctx context.Context, stack Stack,
op UpdateOperation) result.Result {
op UpdateOperation, paths []string) result.Result {
if be.WatchF != nil {
return be.WatchF(ctx, stack, op)
return be.WatchF(ctx, stack, op, paths)
}
panic("not implemented")
}
@ -337,7 +337,7 @@ type MockStack struct {
imports []deploy.Import) (engine.ResourceChanges, result.Result)
RefreshF func(ctx context.Context, op UpdateOperation) (engine.ResourceChanges, result.Result)
DestroyF func(ctx context.Context, op UpdateOperation) (engine.ResourceChanges, result.Result)
WatchF func(ctx context.Context, op UpdateOperation) result.Result
WatchF func(ctx context.Context, op UpdateOperation, paths []string) result.Result
QueryF func(ctx context.Context, op UpdateOperation) result.Result
RemoveF func(ctx context.Context, force bool) (bool, error)
RenameF func(ctx context.Context, newName tokens.QName) (StackReference, error)
@ -413,9 +413,9 @@ func (ms *MockStack) Destroy(ctx context.Context, op UpdateOperation) (engine.Re
panic("not implemented")
}
func (ms *MockStack) Watch(ctx context.Context, op UpdateOperation) result.Result {
func (ms *MockStack) Watch(ctx context.Context, op UpdateOperation, paths []string) result.Result {
if ms.WatchF != nil {
return ms.WatchF(ctx, op)
return ms.WatchF(ctx, op, paths)
}
panic("not implemented")
}

View file

@ -50,7 +50,7 @@ type Stack interface {
// Destroy this stack's resources.
Destroy(ctx context.Context, op UpdateOperation) (engine.ResourceChanges, result.Result)
// Watch this stack.
Watch(ctx context.Context, op UpdateOperation) result.Result
Watch(ctx context.Context, op UpdateOperation, paths []string) result.Result
// remove this stack.
Remove(ctx context.Context, force bool) (bool, error)
@ -103,8 +103,8 @@ func DestroyStack(ctx context.Context, s Stack, op UpdateOperation) (engine.Reso
// WatchStack watches the projects working directory for changes and automatically updates the
// active stack.
func WatchStack(ctx context.Context, s Stack, op UpdateOperation) result.Result {
return s.Backend().Watch(ctx, s, op)
func WatchStack(ctx context.Context, s Stack, op UpdateOperation, paths []string) result.Result {
return s.Backend().Watch(ctx, s, op, paths)
}
// GetLatestConfiguration returns the configuration for the most recent deployment of the stack.

View file

@ -35,7 +35,8 @@ import (
// Watch watches the project's working directory for changes and automatically updates the active
// stack.
func Watch(ctx context.Context, b Backend, stack Stack, op UpdateOperation, apply Applier) result.Result {
func Watch(ctx context.Context, b Backend, stack Stack, op UpdateOperation,
apply Applier, paths []string) result.Result {
opts := ApplierOptions{
DryRun: false,
@ -69,9 +70,21 @@ func Watch(ctx context.Context, b Backend, stack Stack, op UpdateOperation, appl
}()
events := make(chan notify.EventInfo, 1)
if err := notify.Watch(path.Join(op.Root, "..."), events, notify.All); err != nil {
return result.FromError(err)
for _, p := range paths {
// Provided paths can be both relative and absolute.
watchPath := ""
if path.IsAbs(p) {
watchPath = path.Join(p, "...")
} else {
watchPath = path.Join(op.Root, p, "...")
}
if err := notify.Watch(watchPath, events, notify.All); err != nil {
return result.FromError(err)
}
}
defer notify.Stop(events)
fmt.Printf(op.Opts.Display.Color.Colorize(

View file

@ -35,6 +35,7 @@ func newWatchCmd() *cobra.Command {
var execKind string
var stack string
var configArray []string
var pathArray []string
var configPath bool
// Flags for engine.UpdateOptions.
@ -53,9 +54,9 @@ func newWatchCmd() *cobra.Command {
Short: "[PREVIEW] Continuously update the resources in a stack",
Long: "Continuously update the resources in a stack.\n" +
"\n" +
"This command watches the working directory for the current project and updates the active stack whenever\n" +
"the project changes. In parallel, logs are collected for all resources in the stack and displayed along\n" +
"with update progress.\n" +
"This command watches the working directory or specified paths for the current project and updates\n" +
"the active stack whenever the project changes. In parallel, logs are collected for all resources\n" +
"in the stack and displayed along with update progress.\n" +
"\n" +
"The program to watch is loaded from the project in the current directory by default. Use the `-C` or\n" +
"`--cwd` flag to use a different directory.",
@ -131,7 +132,8 @@ func newWatchCmd() *cobra.Command {
StackConfiguration: cfg,
SecretsManager: sm,
Scopes: cancellationScopes,
})
}, pathArray)
switch {
case res != nil && res.Error() == context.Canceled:
return result.FromError(errors.New("update cancelled"))
@ -143,6 +145,10 @@ func newWatchCmd() *cobra.Command {
}),
}
cmd.PersistentFlags().StringArrayVarP(
&pathArray, "path", "", []string{""},
"Specify one or more relative or absolute paths that need to be watched. "+
"A path can point to a folder or a file. Defaults to working directory")
cmd.PersistentFlags().BoolVarP(
&debug, "debug", "d", false,
"Print detailed debugging output during resource operations")