Merge branch 'master' into typo

This commit is contained in:
xginn8 2019-01-15 14:27:02 -05:00 committed by GitHub
commit 8bbb1966a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 65 additions and 31 deletions

3
.gitignore vendored
View File

@ -39,3 +39,6 @@ balenarc.yml
build/ build/
build-bin/ build-bin/
build-zip/ build-zip/
# Ignore fast-boot cache file
/bin/.fast-boot.json

View File

@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## 9.10.0 - 2019-01-14
* Improve startup time by adding fast-boot [Shaun Mulligan]
## 9.9.4 - 2019-01-13
* Lazy load the sdk as much as possible [Pagan Gazzard]
## 9.9.3 - 2019-01-13
* Lazy-load docker-toolbelt [Pagan Gazzard]
## 9.9.2 - 2019-01-11 ## 9.9.2 - 2019-01-11
* Lazy-load etcher-sdk to speed up startup [Pagan Gazzard] * Lazy-load etcher-sdk to speed up startup [Pagan Gazzard]

View File

@ -4,4 +4,8 @@
// operations otherwise, if the pool runs out. // operations otherwise, if the pool runs out.
process.env.UV_THREADPOOL_SIZE = '64'; process.env.UV_THREADPOOL_SIZE = '64';
// Use fast-boot to cache require lookups, speeding up startup
require('fast-boot2').start({
cacheFile: __dirname + '/.fast-boot.json'
})
require('../build/app'); require('../build/app');

View File

@ -9,6 +9,10 @@
// operations otherwise, if the pool runs out. // operations otherwise, if the pool runs out.
process.env.UV_THREADPOOL_SIZE = '64'; process.env.UV_THREADPOOL_SIZE = '64';
// Use fast-boot to cache require lookups, speeding up startup
require('fast-boot2').start({
cacheFile: '.fast-boot.json'
})
process.env['TS_NODE_PROJECT'] = require('path').dirname(__dirname); process.env['TS_NODE_PROJECT'] = require('path').dirname(__dirname);
require('coffeescript/register'); require('coffeescript/register');
require('ts-node/register'); require('ts-node/register');

View File

@ -71,8 +71,6 @@ BalenaSdk.setSharedOptions(
retries: 2 retries: 2
) )
balena = BalenaSdk.fromSharedOptions()
actions = require('./actions') actions = require('./actions')
errors = require('./errors') errors = require('./errors')
events = require('./events') events = require('./events')
@ -86,6 +84,7 @@ update = require('./utils/update')
require('any-promise/register/bluebird') require('any-promise/register/bluebird')
capitano.permission 'user', (done) -> capitano.permission 'user', (done) ->
balena = BalenaSdk.fromSharedOptions()
balena.auth.isLoggedIn().then (isLoggedIn) -> balena.auth.isLoggedIn().then (isLoggedIn) ->
if not isLoggedIn if not isLoggedIn
exitWithExpectedError(''' exitWithExpectedError('''

View File

@ -7,16 +7,17 @@ import Promise = require('bluebird');
import BalenaSdk = require('balena-sdk'); import BalenaSdk = require('balena-sdk');
import packageJSON = require('../package.json'); import packageJSON = require('../package.json');
const balena = BalenaSdk.fromSharedOptions(); const getBalenaSdk = _.once(() => BalenaSdk.fromSharedOptions());
const getMatchCommandAsync = Promise.promisify(Capitano.state.getMatchCommand); const getMatchCommandAsync = Promise.promisify(Capitano.state.getMatchCommand);
const getMixpanel = _.memoize<any>(() => const getMixpanel = _.once<any>(() =>
balena.models.config getBalenaSdk()
.getAll() .models.config.getAll()
.get('mixpanelToken') .get('mixpanelToken')
.then(Mixpanel.init), .then(Mixpanel.init),
); );
export function trackCommand(capitanoCli: Capitano.Cli) { export function trackCommand(capitanoCli: Capitano.Cli) {
const balena = getBalenaSdk();
return Promise.props({ return Promise.props({
balenaUrl: balena.settings.get('balenaUrl'), balenaUrl: balena.settings.get('balenaUrl'),
username: balena.auth.whoami().catchReturn(undefined), username: balena.auth.whoami().catchReturn(undefined),

View File

@ -1,6 +1,7 @@
# Functions to help actions which rely on using docker # Functions to help actions which rely on using docker
Promise = require('bluebird') Promise = require('bluebird')
_ = require('lodash')
# Use this function to seed an action's list of capitano options # Use this function to seed an action's list of capitano options
# with the docker options. Using this interface means that # with the docker options. Using this interface means that
@ -153,14 +154,7 @@ exports.getDocker = (options) ->
.then(createClient) .then(createClient)
.tap(ensureDockerSeemsAccessible) .tap(ensureDockerSeemsAccessible)
exports.createClient = createClient = do -> getDockerToolbelt = _.once ->
# docker-toolbelt v3 is not backwards compatible as it removes all *Async
# methods that are in wide use in the CLI. The workaround for now is to
# manually promisify the client and replace all `new Docker()` calls with
# this shared function that returns a promisified client.
#
# **New code must not use the *Async methods.**
#
Docker = require('docker-toolbelt') Docker = require('docker-toolbelt')
Promise.promisifyAll Docker.prototype, { Promise.promisifyAll Docker.prototype, {
filter: (name) -> name == 'run' filter: (name) -> name == 'run'
@ -169,9 +163,18 @@ exports.createClient = createClient = do ->
Promise.promisifyAll(Docker.prototype) Promise.promisifyAll(Docker.prototype)
Promise.promisifyAll(new Docker({}).getImage().constructor.prototype) Promise.promisifyAll(new Docker({}).getImage().constructor.prototype)
Promise.promisifyAll(new Docker({}).getContainer().constructor.prototype) Promise.promisifyAll(new Docker({}).getContainer().constructor.prototype)
return Docker
return (opts) -> # docker-toolbelt v3 is not backwards compatible as it removes all *Async
return new Docker(opts) # methods that are in wide use in the CLI. The workaround for now is to
# manually promisify the client and replace all `new Docker()` calls with
# this shared function that returns a promisified client.
#
# **New code must not use the *Async methods.**
#
exports.createClient = createClient = (opts) ->
Docker = getDockerToolbelt()
return new Docker(opts)
ensureDockerSeemsAccessible = (docker) -> ensureDockerSeemsAccessible = (docker) ->
{ exitWithExpectedError } = require('./patterns') { exitWithExpectedError } = require('./patterns')

View File

@ -23,12 +23,13 @@ import chalk from 'chalk';
import validation = require('./validation'); import validation = require('./validation');
import messages = require('./messages'); import messages = require('./messages');
const balena = BalenaSdk.fromSharedOptions(); const getBalenaSdk = _.once(() => BalenaSdk.fromSharedOptions());
const getForm = _.once((): typeof _form => require('resin-cli-form')); const getForm = _.once((): typeof _form => require('resin-cli-form'));
const getVisuals = _.once((): typeof _visuals => require('resin-cli-visuals')); const getVisuals = _.once((): typeof _visuals => require('resin-cli-visuals'));
export function authenticate(options: {}): Promise<void> { export function authenticate(options: {}): Promise<void> {
const balena = getBalenaSdk();
return getForm() return getForm()
.run( .run(
[ [
@ -101,17 +102,19 @@ export function askLoginType() {
} }
export function selectDeviceType() { export function selectDeviceType() {
return balena.models.config.getDeviceTypes().then(deviceTypes => { return getBalenaSdk()
deviceTypes = _.sortBy(deviceTypes, 'name'); .models.config.getDeviceTypes()
return getForm().ask({ .then(deviceTypes => {
message: 'Device Type', deviceTypes = _.sortBy(deviceTypes, 'name');
type: 'list', return getForm().ask({
choices: _.map(deviceTypes, ({ slug: value, name }) => ({ message: 'Device Type',
name, type: 'list',
value, choices: _.map(deviceTypes, ({ slug: value, name }) => ({
})), name,
value,
})),
});
}); });
});
} }
export function confirm( export function confirm(
@ -142,6 +145,7 @@ export function confirm(
export function selectApplication( export function selectApplication(
filter: (app: BalenaSdk.Application) => boolean, filter: (app: BalenaSdk.Application) => boolean,
) { ) {
const balena = getBalenaSdk();
return balena.models.application return balena.models.application
.hasAny() .hasAny()
.then(function(hasAnyApplications) { .then(function(hasAnyApplications) {
@ -165,6 +169,7 @@ export function selectApplication(
} }
export function selectOrCreateApplication() { export function selectOrCreateApplication() {
const balena = getBalenaSdk();
return balena.models.application return balena.models.application
.hasAny() .hasAny()
.then(hasAnyApplications => { .then(hasAnyApplications => {
@ -205,6 +210,7 @@ export function selectOrCreateApplication() {
} }
export function awaitDevice(uuid: string) { export function awaitDevice(uuid: string) {
const balena = getBalenaSdk();
return balena.models.device.getName(uuid).then(deviceName => { return balena.models.device.getName(uuid).then(deviceName => {
const visuals = getVisuals(); const visuals = getVisuals();
const spinner = new visuals.Spinner( const spinner = new visuals.Spinner(
@ -233,6 +239,7 @@ export function awaitDevice(uuid: string) {
} }
export function inferOrSelectDevice(preferredUuid: string) { export function inferOrSelectDevice(preferredUuid: string) {
const balena = getBalenaSdk();
return balena.models.device return balena.models.device
.getAll() .getAll()
.filter<BalenaSdk.Device>(device => device.is_online) .filter<BalenaSdk.Device>(device => device.is_online)

View File

@ -17,7 +17,7 @@ export class DriveList extends CustomDynamicList<
} }
protected *getThings() { protected *getThings() {
const sdk: typeof _sdk = require('etcher-sdk') const sdk: typeof _sdk = require('etcher-sdk');
for (const drive of this.scanner.drives) { for (const drive of this.scanner.drives) {
if (drive instanceof sdk.sourceDestination.BlockDevice) { if (drive instanceof sdk.sourceDestination.BlockDevice) {
yield drive; yield drive;

View File

@ -1,6 +1,6 @@
{ {
"name": "balena-cli", "name": "balena-cli",
"version": "9.9.2", "version": "9.10.0",
"description": "The official balena CLI tool", "description": "The official balena CLI tool",
"main": "./build/actions/index.js", "main": "./build/actions/index.js",
"homepage": "https://github.com/balena-io/balena-cli", "homepage": "https://github.com/balena-io/balena-cli",
@ -109,7 +109,7 @@
"balena-preload": "^8.0.4", "balena-preload": "^8.0.4",
"balena-sdk": "^11.2.0", "balena-sdk": "^11.2.0",
"balena-settings-client": "^4.0.0", "balena-settings-client": "^4.0.0",
"balena-sync": "^10.0.0", "balena-sync": "^10.0.2",
"bash": "0.0.1", "bash": "0.0.1",
"bluebird": "^3.3.3", "bluebird": "^3.3.3",
"body-parser": "^1.14.1", "body-parser": "^1.14.1",
@ -130,6 +130,7 @@
"etcher-sdk": "^0.2.0", "etcher-sdk": "^0.2.0",
"event-stream": "3.3.4", "event-stream": "3.3.4",
"express": "^4.13.3", "express": "^4.13.3",
"fast-boot2": "^1.0.9",
"global-tunnel-ng": "^2.1.1", "global-tunnel-ng": "^2.1.1",
"hasbin": "^1.2.3", "hasbin": "^1.2.3",
"humanize": "0.0.9", "humanize": "0.0.9",
@ -153,7 +154,7 @@
"reconfix": "^0.1.0", "reconfix": "^0.1.0",
"request": "^2.81.0", "request": "^2.81.0",
"resin-bundle-resolve": "^0.6.0", "resin-bundle-resolve": "^0.6.0",
"resin-cli-form": "^2.0.0", "resin-cli-form": "^2.0.1",
"resin-cli-visuals": "^1.4.0", "resin-cli-visuals": "^1.4.0",
"resin-compose-parse": "^2.0.0", "resin-compose-parse": "^2.0.0",
"resin-doodles": "0.0.1", "resin-doodles": "0.0.1",