diff --git a/lib/utils/device/api.ts b/lib/utils/device/api.ts index 5006e51f..4e1e1429 100644 --- a/lib/utils/device/api.ts +++ b/lib/utils/device/api.ts @@ -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 { + 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 { const url = this.getUrlForAction('logs'); diff --git a/lib/utils/device/deploy.ts b/lib/utils/device/deploy.ts index 8301cbe8..6aace978 100644 --- a/lib/utils/device/deploy.ts +++ b/lib/utils/device/deploy.ts @@ -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 { 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}`);