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

chore: add settings for the "cdk watch" command #383

Merged
merged 3 commits into from
Oct 26, 2021

Conversation

skinny85
Copy link
Contributor

This PR updates the "CDK Watch" RFC with details of how to customize the watching process by introducing new options to the cdk.json file:

  • A "build" key that allows specifying what command(s) should be executed before the project is synthesized.
  • A "watch" key with two sub-keys, "include" and "exclude", that allows specifying what files should be observed for changes, and which ones should be ignored by the watcher.

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache-2.0 license

@skinny85 skinny85 requested a review from eladb October 14, 2021 23:48
@skinny85 skinny85 self-assigned this Oct 14, 2021
eladb
eladb previously requested changes Oct 18, 2021
text/0001-cdk-update.md Outdated Show resolved Hide resolved
text/0001-cdk-update.md Outdated Show resolved Hide resolved
text/0001-cdk-update.md Outdated Show resolved Hide resolved
text/0001-cdk-update.md Outdated Show resolved Hide resolved
text/0001-cdk-update.md Show resolved Hide resolved
@skinny85 skinny85 requested a review from eladb October 19, 2021 00:39
@skinny85
Copy link
Contributor Author

@eladb thanks for the review. I've incorporated your comments, would appreciate another pass!

@mergify mergify bot dismissed eladb’s stale review October 19, 2021 00:39

Pull request has been modified.

@eladb eladb requested a review from rix0rrr October 19, 2021 07:25
rix0rrr
rix0rrr previously approved these changes Oct 19, 2021
text/0001-cdk-update.md Show resolved Hide resolved
@mergify mergify bot dismissed rix0rrr’s stale review October 20, 2021 01:04

Pull request has been modified.

@skinny85
Copy link
Contributor Author

@eladb included your last comment about automatically excluding the CDK output directory, hopefully this is now ready 🙂.

@skinny85 skinny85 merged commit 91ffc5d into aws:master Oct 26, 2021
@skinny85 skinny85 deleted the cdk-watch-settings branch October 26, 2021 19:14
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Nov 4, 2021
Adds a `build` field to `cdk.json`. The command specified in the `build` will be executed before synthesis. This can be used to build any code that needs to be built before synthesis (for example, CDK App code or Lambda Function code).

This is part of the changes needed for the `cdk watch` command
(aws/aws-cdk-rfcs#383).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Nov 5, 2021
This PR introduces the "watch" command, in two variants: as a separate new `cdk watch` command,
and as an argument to the existing `cdk deploy` command.

The "watch" process will observe the project files, defined by the new `"include"` and `"exclude"` settings in `cdk.json`
(see aws/aws-cdk-rfcs#383 for details),
and will trigger a `cdk deploy` when it detects any changes.
The deployment will by default use the new "hotswap" deployments for maximum speed.

Since `cdk deploy` is a relatively slow process for a "watch" command,
there is some logic to perform intelligent queuing of any file events that happen while `cdk deploy` is running.
We will batch all of those events, and trigger a single `cdk deploy` after the current one finishes.
This ensures only a single `cdk deploy` command ever executes at a time.

The observing of the files, and reacting to their changes, is accomplished using the [`chokidar` library](https://www.npmjs.com/package/chokidar).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
iliapolo pushed a commit to aws/aws-cdk that referenced this pull request Nov 7, 2021
This PR introduces the "watch" command, in two variants: as a separate new `cdk watch` command,
and as an argument to the existing `cdk deploy` command.

The "watch" process will observe the project files, defined by the new `"include"` and `"exclude"` settings in `cdk.json`
(see aws/aws-cdk-rfcs#383 for details),
and will trigger a `cdk deploy` when it detects any changes.
The deployment will by default use the new "hotswap" deployments for maximum speed.

Since `cdk deploy` is a relatively slow process for a "watch" command,
there is some logic to perform intelligent queuing of any file events that happen while `cdk deploy` is running.
We will batch all of those events, and trigger a single `cdk deploy` after the current one finishes.
This ensures only a single `cdk deploy` command ever executes at a time.

The observing of the files, and reacting to their changes, is accomplished using the [`chokidar` library](https://www.npmjs.com/package/chokidar).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@marekq
Copy link

marekq commented Nov 7, 2021

Thanks for adding this great feature! I've noticed that adding the following section to 'cdk.json' based on the example will pickup changes to my CDK stack, but also changes in other, non CDK files:

"watch": {
         "include": ["./**"],
         "exclude": ["target"]
       }

If I change something in my README.md file, I see the following on my CLI:

Detected change to 'README.md' (type: change). Triggering 'cdk deploy'

Would it make sense to include only './lib', './bin' for example and to update this in the CDK docs?

@skinny85
Copy link
Contributor Author

skinny85 commented Nov 9, 2021

Hey @marekq,

yes, the default is to look at your entire root directory. This is so that, if you add some runtime code to your CDK application outside bin/ and lib/, it gets picked up by watch. Of course, feel free to customize the "watch" key in your cdk.json as you please!

We will soon update our init templates, so that you'll get the correct values when starting a new CDK project.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
Adds a `build` field to `cdk.json`. The command specified in the `build` will be executed before synthesis. This can be used to build any code that needs to be built before synthesis (for example, CDK App code or Lambda Function code).

This is part of the changes needed for the `cdk watch` command
(aws/aws-cdk-rfcs#383).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
This PR introduces the "watch" command, in two variants: as a separate new `cdk watch` command,
and as an argument to the existing `cdk deploy` command.

The "watch" process will observe the project files, defined by the new `"include"` and `"exclude"` settings in `cdk.json`
(see aws/aws-cdk-rfcs#383 for details),
and will trigger a `cdk deploy` when it detects any changes.
The deployment will by default use the new "hotswap" deployments for maximum speed.

Since `cdk deploy` is a relatively slow process for a "watch" command,
there is some logic to perform intelligent queuing of any file events that happen while `cdk deploy` is running.
We will batch all of those events, and trigger a single `cdk deploy` after the current one finishes.
This ensures only a single `cdk deploy` command ever executes at a time.

The observing of the files, and reacting to their changes, is accomplished using the [`chokidar` library](https://www.npmjs.com/package/chokidar).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants