faas-cli
faas-cli copied to clipboard
[WIP] File watch
Description
Adds a --watch flag to the up command which will watch the filesystem for changes and trigger an up command, this includes a 500ms debounce interval to avoid unnecessary builds when many files change in quick succession.
Ignores changes some standard dirs, build, template, .git, and some temp files ~, can be appended to with the ignore-dir and ignore-suffix args.
Currently does not honour filter argument when working in a multi function dir.
Changes are watched relative to the pwd.
Motivation and Context
- [x] This fixes #472
How Has This Been Tested?
Tested locally on Windows10.
Needs feedback from Linux/OSX users.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I've read the CONTRIBUTION guide
- [ ] I have signed-off my commits with
git commit -s - [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. That's something we need before your Pull Request can be merged. Please see our contributing guide.
Tip: if you only have one commit so far then run: git commit --amend --signoff and then git push --force.
Excited to see this John, thank you for working on it again.
Currently does not honour filter argument when working in a multi function dir.
^ can you explain what this means in practice?
You'd also mentioned something on DM to me about there not being a clean separation or similar? I wasn't sure what you were referring do. Was that meaning > 1 function in a stack.yml file?
I feel like the watch should do an initial build?
alex@alexx:~/go/src/github.com/openfaas/faas-cli/tests$ faas-cli new --lang node12 quick
2020/02/09 19:53:17 No templates found in current directory.
2020/02/09 19:53:17 Attempting to expand templates from https://github.com/openfaas/templates.git
2020/02/09 19:53:19 Fetched 19 template(s) : [csharp csharp-armhf dockerfile go go-armhf java11 java11-vert-x java8 node node-arm64 node-armhf node12 php7 python python-armhf python3 python3-armhf python3-debian ruby] from https://github.com/openfaas/templates.git
Folder: quick created.
___ _____ ____
/ _ \ _ __ ___ _ __ | ___|_ _ __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) | __/ | | | _| (_| | (_| |___) |
\___/| .__/ \___|_| |_|_| \__,_|\__,_|____/
|_|
Function created in folder: quick
Stack file written: quick.yml
Notes:
You have created a new function which uses Node.js 12 (TLS) and the OpenFaaS
of-watchdog which gives greater control over HTTP responses.
npm i --save can be used to add third-party packages like request or cheerio
npm documentation: https://docs.npmjs.com/
Unit tests are run at build time via "npm run", edit package.json to specify
how you want to execute them.
alex@alexx:~/go/src/github.com/openfaas/faas-cli/tests$ faas-cli up --skip-push --watch
Unknown flag: --watch
alex@alexx:~/go/src/github.com/openfaas/faas-cli/tests$ ../faas-cli up --skip-push --watch
2020/02/09 19:53:31 Watching: /home/alex/go/src/github.com/openfaas/faas-cli/tests
If you set a watch in a multi-function dir the --filter does not limit change watches to just that function.
This is what happened when editing the js file:
alex@alexx:~/go/src/github.com/openfaas/faas-cli/tests$ ../faas-cli up --skip-push --watch
2020/02/09 19:53:31 Watching: /home/alex/go/src/github.com/openfaas/faas-cli/tests
2020/02/09 19:54:09 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/.handler.js.swx": REMOVE
2020/02/09 19:54:09 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/.handler.js.swp": REMOVE
2020/02/09 19:54:09 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/.handler.js.swp": CREATE
2020/02/09 19:54:09 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/.handler.js.swp": WRITE
2020/02/09 19:54:09 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/.handler.js.swp": CHMOD
2020/02/09 19:54:09 Error detecting change: please provide a valid --image name for your Docker image
2020/02/09 19:54:12 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/.handler.js.swp": WRITE
2020/02/09 19:54:13 Error detecting change: please provide a valid --image name for your Docker image
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/4913": REMOVE
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/handler.js": RENAME
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/handler.js~": CREATE
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/handler.js": CREATE
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/handler.js": WRITE
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/handler.js": CHMOD
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/handler.js": CHMOD
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/.handler.js.swp": WRITE
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/handler.js~": REMOVE
2020/02/09 19:54:14 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/quick/.handler.js.swp": REMOVE
2020/02/09 19:54:15 Error detecting change: please provide a valid --image name for your Docker image
Yep, WIP has debug logging for fs events.
Edited the quick.yml file and added my Docker Hub prefix, then got this:
2020/02/09 19:55:12 changed: "/home/alex/go/src/github.com/openfaas/faas-cli/tests/.quick.yml.swp": REMOVE
2020/02/09 19:55:12 Error detecting change: please provide a valid --image name for your Docker image
Think it's because I missed -f quick.yml - so maybe --watch should fail in that circumstance?
What happens, if there's a build in progress, but it's slow i.e. pulling node_modules and I save again, but outside of the debounce time?
Removing intermediate container e986af75e6cb
---> 10b71cc0b220
Step 25/29 : ENV exec_timeout="10s"
---> Running in 71f3fbe51123
---> Running in 3af82da8ad48
Removing intermediate container a773fa64453e
---> d3cc3b2936ea
Step 28/29 : HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1
Removing intermediate container 71f3fbe51123
---> 213933305019
Step 26/29 : ENV write_timeout="15s"
Removing intermediate container 3af82da8ad48
---> 4ef7cffea8ff
Step 26/29 : ENV write_timeout="15s"
---> Running in 069815cdda02
---> Running in e405854e92d3
---> Running in d1bdf101cb4a
Removing intermediate container 069815cdda02
---> 6f76201dd4a6
Step 29/29 : CMD ["fwatchdog"]
Removing intermediate container e405854e92d3
---> 3d712333c80e
Step 27/29 : ENV read_timeout="15s"
Removing intermediate container d1bdf101cb4a
---> dd5f59c71e6b
Step 27/29 : ENV read_timeout="15s"
---> Running in 509ddc2fee52
---> Running in 922d28768b78
---> Running in 13fb28f4954a
Removing intermediate container 509ddc2fee52
---> d35b7f05eed5
Successfully built d35b7f05eed5
Successfully tagged alexellis2/quick-test:latest
Image: alexellis2/quick-test:latest built.
[0] < Building quick done in 98.93s.
[0] Worker done.
Total build time: 98.93s
Might be running several concurrent builds? It's just one function here.