mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Check supervisor version before attempting to do a local push
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
parent
947f91d570
commit
fe751fdb23
@ -24,6 +24,7 @@ const deviceEndpoints = {
|
||||
getDeviceInformation: 'v2/local/device-info',
|
||||
logs: 'v2/local/logs',
|
||||
ping: 'ping',
|
||||
version: 'v2/version',
|
||||
};
|
||||
|
||||
export class DeviceAPI {
|
||||
@ -93,6 +94,23 @@ export class DeviceAPI {
|
||||
);
|
||||
}
|
||||
|
||||
public getVersion(): Promise<string> {
|
||||
const url = this.getUrlForAction('version');
|
||||
|
||||
return DeviceAPI.promisifiedRequest(request.get, {
|
||||
url,
|
||||
json: true,
|
||||
}).then(body => {
|
||||
if (body.status !== 'success') {
|
||||
throw new ApiErrors.DeviceAPIError(
|
||||
'Non-successful response from supervisor version endpoint',
|
||||
);
|
||||
}
|
||||
|
||||
return body.version;
|
||||
});
|
||||
}
|
||||
|
||||
public getLogStream(): Bluebird<Stream.Readable> {
|
||||
const url = this.getUrlForAction('logs');
|
||||
|
||||
|
@ -3,6 +3,7 @@ import * as Docker from 'dockerode';
|
||||
import * as _ from 'lodash';
|
||||
import { Composition } from 'resin-compose-parse';
|
||||
import { BuildTask, LocalImage } from 'resin-multibuild';
|
||||
import * as semver from 'resin-semver';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
import Logger = require('../logger');
|
||||
@ -39,9 +40,30 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
|
||||
|
||||
const api = new DeviceAPI(logger, opts.deviceHost);
|
||||
|
||||
// TODO: Before merge, replace this with the supervisor version endpoint, to
|
||||
// ensure we're working with a supervisor version that supports the stuff we need
|
||||
await api.ping();
|
||||
// First check that we can access the device with a ping
|
||||
try {
|
||||
await api.ping();
|
||||
} catch (e) {
|
||||
exitWithExpectedError(
|
||||
`Could not communicate with local mode device at address ${
|
||||
opts.deviceHost
|
||||
}`,
|
||||
);
|
||||
}
|
||||
|
||||
const versionError = new Error(
|
||||
'The supervisor version on this remote device does not support multicontainer local mode. ' +
|
||||
'Please update your device to resinOS v2.20.0 or greater from the dashboard.',
|
||||
);
|
||||
|
||||
try {
|
||||
const version = await api.getVersion();
|
||||
if (!semver.satisfies(version, '>=7.21.4')) {
|
||||
exitWithExpectedError(versionError);
|
||||
}
|
||||
} catch {
|
||||
exitWithExpectedError(versionError);
|
||||
}
|
||||
|
||||
logger.logInfo(`Starting build on device ${opts.deviceHost}`);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user