Check supervisor version before attempting to do a local push

Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
Cameron Diver 2018-10-16 16:41:38 +01:00 committed by Tim Perry
parent 947f91d570
commit fe751fdb23
2 changed files with 43 additions and 3 deletions

View File

@ -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');

View File

@ -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}`);