From 0c1c108b2bf32a93c3e6e3d4eeacbc8f1e4e2ab6 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Mon, 20 Aug 2018 18:19:10 +0200 Subject: [PATCH] Check for correct architecture when preloading, instead of correct device type Preload will now propose to preload any app that matches the image architecture. Change-type: major Signed-off-by: Alexis Svinartchouk --- doc/cli.markdown | 4 +-- lib/actions/preload.coffee | 64 +++++++++++++++++++++++++------------- package.json | 2 +- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/doc/cli.markdown b/doc/cli.markdown index 8298da50..1feb9512 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -1215,9 +1215,9 @@ the commit hash for a specific application release to preload, use "latest" to s path to a png image to replace the splash screen -#### --dont-check-device-type +#### --dont-check-arch -Disables check for matching device types in image and application +Disables check for matching architecture in image and application #### --pin-device-to-release, -p diff --git a/lib/actions/preload.coffee b/lib/actions/preload.coffee index b25b31f3..3c8f74b5 100644 --- a/lib/actions/preload.coffee +++ b/lib/actions/preload.coffee @@ -18,24 +18,46 @@ dockerUtils = require('../utils/docker') LATEST = 'latest' +allDeviceTypes = undefined + +getDeviceTypes = -> + Bluebird = require('bluebird') + if allDeviceTypes != undefined + return Bluebird.resolve(allDeviceTypes) + resin = require('resin-sdk').fromSharedOptions() + resin.models.config.getDeviceTypes() + .tap (dt) -> + allDeviceTypes = dt + +getDeviceTypesWithSameArch = (deviceTypeSlug) -> + _ = require('lodash') + + getDeviceTypes() + .then (deviceTypes) -> + deviceType = _.find(deviceTypes, slug: deviceTypeSlug) + _(deviceTypes).filter(arch: deviceType.arch).map('slug').value() + getApplicationsWithSuccessfulBuilds = (deviceType) -> preload = require('resin-preload') resin = require('resin-sdk').fromSharedOptions() - resin.pine.get - resource: 'my_application' - options: - $filter: - device_type: deviceType - owns__release: - $any: - $alias: 'r' - $expr: - r: - status: 'success' - $expand: preload.applicationExpandOptions - $select: [ 'id', 'app_name', 'device_type', 'commit', 'should_track_latest_release' ] - $orderby: 'app_name asc' + getDeviceTypesWithSameArch(deviceType) + .then (deviceTypes) -> + resin.pine.get + resource: 'my_application' + options: + $filter: + device_type: + $in: deviceTypes + owns__release: + $any: + $alias: 'r' + $expr: + r: + status: 'success' + $expand: preload.applicationExpandOptions + $select: [ 'id', 'app_name', 'device_type', 'commit', 'should_track_latest_release' ] + $orderby: 'app_name asc' selectApplication = (deviceType) -> visuals = require('resin-cli-visuals') @@ -144,9 +166,9 @@ module.exports = alias: 's' } { - signature: 'dont-check-device-type' + signature: 'dont-check-arch' boolean: true - description: 'Disables check for matching device types in image and application' + description: 'Disables check for matching architecture in image and application' } { signature: 'pin-device-to-release' @@ -191,10 +213,10 @@ module.exports = options.splashImage = options['splash-image'] delete options['splash-image'] - options.dontCheckDeviceType = options['dont-check-device-type'] || false - delete options['dont-check-device-type'] - if options.dontCheckDeviceType and not options.appId - exitWithExpectedError('You need to specify an app id if you disable the device type check.') + options.dontCheckArch = options['dont-check-arch'] || false + delete options['dont-check-arch'] + if options.dontCheckArch and not options.appId + exitWithExpectedError('You need to specify an app id if you disable the architecture check.') options.pinDevice = options['pin-device-to-release'] || false delete options['pin-device-to-release'] @@ -211,7 +233,7 @@ module.exports = options.image options.splashImage options.proxy - options.dontCheckDeviceType + options.dontCheckArch options.pinDevice ) diff --git a/package.json b/package.json index c019ecdb..3469dc88 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,7 @@ "resin-image-fs": "^5.0.2", "resin-image-manager": "^5.0.0", "resin-multibuild": "^0.5.1", - "resin-preload": "^6.3.0", + "resin-preload": "^7.0.0", "resin-release": "^1.2.0", "resin-sdk": "10.0.0-beta2", "resin-sdk-preconfigured": "^6.9.0",