mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-21 14:37:49 +00:00
Add livepush capabilities for debug builds
Change-type: minor Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
6bfeaf7ae7
commit
73f207a76f
@ -37,7 +37,7 @@ WORKDIR /usr/src/app
|
|||||||
|
|
||||||
RUN apt-get update && apt-get install ca-certificates \
|
RUN apt-get update && apt-get install ca-certificates \
|
||||||
iptables libnss-mdns nodejs rsync git python make wget g++ \
|
iptables libnss-mdns nodejs rsync git python make wget g++ \
|
||||||
kmod
|
kmod vim
|
||||||
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
@ -53,11 +53,11 @@ COPY typings typings/
|
|||||||
COPY tsconfig.json hardcode-migrations.js fix-jsonstream.js ./
|
COPY tsconfig.json hardcode-migrations.js fix-jsonstream.js ./
|
||||||
|
|
||||||
RUN npm run build:debug
|
RUN npm run build:debug
|
||||||
RUN mkdir dist && echo "require('../build/app.js')" > dist/app.js
|
RUN mkdir -p dist && echo "require('../build/app.js')" > dist/app.js
|
||||||
|
|
||||||
COPY entry.sh .
|
COPY entry.sh .
|
||||||
|
|
||||||
RUN mkdir -p rootfs-overlay && ln -s /lib rootfs-overlay/lib64
|
RUN mkdir -p rootfs-overlay && ([ ! -e rootfs-overlay/lib64 ] && ln -s /lib rootfs-overlay/lib64)
|
||||||
|
|
||||||
ENV CONFIG_MOUNT_POINT=/boot/config.json \
|
ENV CONFIG_MOUNT_POINT=/boot/config.json \
|
||||||
LED_FILE=/dev/null \
|
LED_FILE=/dev/null \
|
||||||
|
2116
package-lock.json
generated
2116
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -52,6 +52,7 @@
|
|||||||
"body-parser": "^1.12.0",
|
"body-parser": "^1.12.0",
|
||||||
"buffer-equal-constant-time": "^1.0.1",
|
"buffer-equal-constant-time": "^1.0.1",
|
||||||
"chai-events": "0.0.1",
|
"chai-events": "0.0.1",
|
||||||
|
"chokidar": "^3.0.0",
|
||||||
"coffee-loader": "^0.9.0",
|
"coffee-loader": "^0.9.0",
|
||||||
"coffeescript": "^1.12.7",
|
"coffeescript": "^1.12.7",
|
||||||
"common-tags": "^1.8.0",
|
"common-tags": "^1.8.0",
|
||||||
@ -72,6 +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",
|
||||||
"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",
|
||||||
|
95
sync-debug.js
Executable file
95
sync-debug.js
Executable file
@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
if (!process.argv[2] || ['help', '-h', '--help'].includes(process.argv[2])) {
|
||||||
|
console.log(`
|
||||||
|
Sync changes in the javascript code to a running local mode supervisor on a device on the local network
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
./sync-debug.js <device IP>
|
||||||
|
|
||||||
|
Note that the device should be running a debug image.
|
||||||
|
`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ip = process.argv[2];
|
||||||
|
|
||||||
|
const { Livepush } = require('livepush');
|
||||||
|
const { fs } = require('mz');
|
||||||
|
const dockerode = require('dockerode');
|
||||||
|
const chokidar = require('chokidar');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const docker = new dockerode({
|
||||||
|
host: ip,
|
||||||
|
port: 2375,
|
||||||
|
});
|
||||||
|
|
||||||
|
function extractMessage(msgBuf) {
|
||||||
|
// Non-tty message format from:
|
||||||
|
// https://docs.docker.com/engine/api/v1.30/#operation/ContainerAttach
|
||||||
|
if (
|
||||||
|
_.includes([0, 1, 2], msgBuf[0]) &&
|
||||||
|
_.every(msgBuf.slice(1, 7), c => c === 0)
|
||||||
|
) {
|
||||||
|
// Take the header from this message, and parse it as normal
|
||||||
|
msgBuf = msgBuf.slice(8);
|
||||||
|
}
|
||||||
|
const logLine = msgBuf.toString();
|
||||||
|
const space = logLine.indexOf(' ');
|
||||||
|
if (space > 0) {
|
||||||
|
let timestamp = new Date(logLine.substr(0, space)).getTime();
|
||||||
|
if (_.isNaN(timestamp)) {
|
||||||
|
timestamp = Date.now();
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
timestamp,
|
||||||
|
message: logLine.substr(space + 1),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
// Get the supervisor container id
|
||||||
|
const container = await docker.getContainer('resin_supervisor').inspect();
|
||||||
|
const containerId = container.Id;
|
||||||
|
const image = container.Image;
|
||||||
|
|
||||||
|
const livepush = await Livepush.init(
|
||||||
|
await fs.readFile('Dockerfile.debug'),
|
||||||
|
'.',
|
||||||
|
containerId,
|
||||||
|
// a bit of a hack, as the multistage images aren't
|
||||||
|
// present, but it shouldn't make a difference as these
|
||||||
|
// will never change
|
||||||
|
_.times(7, () => image),
|
||||||
|
docker,
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: Debounce these calls
|
||||||
|
chokidar
|
||||||
|
.watch('.', {
|
||||||
|
ignored: /((^|[\/\\])\..|node_modules.*)/,
|
||||||
|
ignoreInitial: true,
|
||||||
|
})
|
||||||
|
.on('add', path => {
|
||||||
|
livepush.performLivepush([path], []);
|
||||||
|
})
|
||||||
|
.on('change', path => {
|
||||||
|
livepush.performLivepush([path], []);
|
||||||
|
})
|
||||||
|
.on('unlink', path => {
|
||||||
|
livepush.performLivepush([], [path]);
|
||||||
|
});
|
||||||
|
|
||||||
|
livepush.on('commandExecute', ({ command }) => {
|
||||||
|
console.log('SYNC: executing:', command);
|
||||||
|
});
|
||||||
|
livepush.on('commandOutput', ({ output }) => {
|
||||||
|
console.log(`\t${output.data.toString()}`);
|
||||||
|
});
|
||||||
|
livepush.on('containerRestart', () => {
|
||||||
|
console.log('SYNC: Restarting container...');
|
||||||
|
});
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user