mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 17:33:18 +00:00
Improve livepush UX
Change-type: patch Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
4557cf626f
commit
a832f47508
@ -16,6 +16,7 @@ import {
|
||||
rebuildSingleTask,
|
||||
} from './deploy';
|
||||
import { BuildError } from './errors';
|
||||
import { getServiceColourFn } from './logs';
|
||||
|
||||
// How often do we want to check the device state
|
||||
// engine has settled (delay in ms)
|
||||
@ -131,9 +132,11 @@ export class LivepushManager {
|
||||
);
|
||||
}
|
||||
|
||||
const log = (msg: string) => {
|
||||
this.logger.logLivepush(`[service ${serviceName}] ${msg}`);
|
||||
};
|
||||
const msgString = (msg: string) =>
|
||||
`[${getServiceColourFn(serviceName)(serviceName)}] ${msg}`;
|
||||
const log = (msg: string) => this.logger.logLivepush(msgString(msg));
|
||||
const error = (msg: string) => this.logger.logError(msgString(msg));
|
||||
const debugLog = (msg: string) => this.logger.logDebug(msgString(msg));
|
||||
|
||||
const livepush = await Livepush.init(
|
||||
dockerfile,
|
||||
@ -149,6 +152,16 @@ export class LivepushManager {
|
||||
livepush.on('commandOutput', output =>
|
||||
log(` ${output.output.data.toString()}`),
|
||||
);
|
||||
livepush.on('commandReturn', ({ returnCode, command }) => {
|
||||
if (returnCode !== 0) {
|
||||
error(` Command ${command} failed with exit code: ${returnCode}`);
|
||||
} else {
|
||||
debugLog(`Command ${command} exited successfully`);
|
||||
}
|
||||
});
|
||||
livepush.on('containerRestart', () => {
|
||||
log('Restarting service...');
|
||||
});
|
||||
|
||||
// TODO: Memoize this for containers which share a context
|
||||
const monitor = chokidar.watch('.', {
|
||||
@ -294,7 +307,16 @@ export class LivepushManager {
|
||||
this.logger.logLivepush(
|
||||
`Detected changes for container ${fsEvent.serviceName}, updating...`,
|
||||
);
|
||||
await livepush.performLivepush(updates, deletes);
|
||||
|
||||
try {
|
||||
await livepush.performLivepush(updates, deletes);
|
||||
} catch (e) {
|
||||
this.logger.logError(
|
||||
`An error occured whilst trying to perform a livepush: `,
|
||||
);
|
||||
this.logger.logError(` ${e.message}`);
|
||||
this.logger.logDebug(e.stack);
|
||||
}
|
||||
}
|
||||
|
||||
private async handleServiceRebuild(serviceName: string): Promise<void> {
|
||||
|
@ -107,7 +107,7 @@ export function displayLogObject<T extends Log>(
|
||||
logger.logLogs(toPrint);
|
||||
}
|
||||
|
||||
const getServiceColourFn = _.memoize(_getServiceColourFn);
|
||||
export const getServiceColourFn = _.memoize(_getServiceColourFn);
|
||||
|
||||
const colorHash = new ColorHash();
|
||||
function _getServiceColourFn(serviceName: string): (msg: string) => string {
|
||||
|
@ -144,7 +144,7 @@
|
||||
"is-root": "^1.0.0",
|
||||
"js-yaml": "^3.10.0",
|
||||
"klaw": "^3.0.0",
|
||||
"livepush": "^1.1.3",
|
||||
"livepush": "^1.2.0",
|
||||
"lodash": "^4.17.4",
|
||||
"minimatch": "^3.0.4",
|
||||
"mixpanel": "^0.10.1",
|
||||
|
Loading…
x
Reference in New Issue
Block a user