Update and improve debug and development tools

Add a debounce to the livepush invocations, execute on start and also
add a wait on the supervisor CMD line for those rare occassions where
the supervisor enters a restart loop.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-05-29 12:44:48 +01:00
parent 1597aeb895
commit 392c56b4d3
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
4 changed files with 23 additions and 10 deletions

View File

@ -72,4 +72,4 @@ HEALTHCHECK --interval=5m --start-period=1m --timeout=30s --retries=3 \
RUN [ "cross-build-end" ] RUN [ "cross-build-end" ]
CMD DEBUG=1 ./entry.sh CMD DEBUG=1 ./entry.sh || while true; do echo 'Supervisor runtime exited - waiting for changes'; sleep 100; done;

6
package-lock.json generated
View File

@ -6303,9 +6303,9 @@
} }
}, },
"livepush": { "livepush": {
"version": "1.2.1", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/livepush/-/livepush-1.2.1.tgz", "resolved": "https://registry.npmjs.org/livepush/-/livepush-1.2.4.tgz",
"integrity": "sha512-6BD16S8EtyVsNqI5PHI/MRiho1LhkYR9Gjy2AXWm3S/cssV0TlVJpyhz1nMWxCDGjbJAWjcYwbvSAeBua7RUhA==", "integrity": "sha512-AKGlJ+QuelyDoOV0cbGfeskLf2RaYIcHnKogfircvTl9//BNDrGVhrcO6bN3kcVaJnYKnvXwXOtGOyrsl6wI9A==",
"dev": true, "dev": true,
"requires": { "requires": {
"bluebird": "^3.5.1", "bluebird": "^3.5.1",

View File

@ -73,7 +73,7 @@
"json-mask": "^0.3.8", "json-mask": "^0.3.8",
"knex": "~0.15.2", "knex": "~0.15.2",
"lint-staged": "^8.1.0", "lint-staged": "^8.1.0",
"livepush": "^1.2.1", "livepush": "^1.2.4",
"lockfile": "^1.0.1", "lockfile": "^1.0.1",
"lodash": "^4.17.5", "lodash": "^4.17.5",
"log-timestamp": "^0.1.2", "log-timestamp": "^0.1.2",

View File

@ -50,9 +50,20 @@ function extractMessage(msgBuf) {
return; return;
} }
let changedFiles = [];
let deletedFiles = [];
const performLivepush = _.debounce(async livepush => {
await livepush.performLivepush(changedFiles, deletedFiles);
changedFiles = [];
deletedFiles = [];
}, 1000);
(async () => { (async () => {
console.log('Starting up...');
// Get the supervisor container id // Get the supervisor container id
const container = await docker.getContainer('resin_supervisor').inspect(); const container = await docker.getContainer('resin_supervisor').inspect();
console.log('Supervisor container id: ', container.Id);
const containerId = container.Id; const containerId = container.Id;
const image = container.Image; const image = container.Image;
@ -67,20 +78,22 @@ function extractMessage(msgBuf) {
docker, docker,
); );
// TODO: Debounce these calls
chokidar chokidar
.watch('.', { .watch('.', {
ignored: /((^|[\/\\])\..|node_modules.*)/, ignored: /((^|[\/\\])\..|node_modules.*)/,
ignoreInitial: true, ignoreInitial: false,
}) })
.on('add', path => { .on('add', path => {
livepush.performLivepush([path], []); changedFiles.push(path);
performLivepush(livepush);
}) })
.on('change', path => { .on('change', path => {
livepush.performLivepush([path], []); changedFiles.push(path);
performLivepush(livepush);
}) })
.on('unlink', path => { .on('unlink', path => {
livepush.performLivepush([], [path]); deletedFiles.push(path);
performLivepush(livepush);
}); });
livepush.on('commandExecute', ({ command }) => { livepush.on('commandExecute', ({ command }) => {