Add BALENA_DEVICE_ARCH environment variable for containers

Closes: #1232
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2020-03-30 14:57:27 +01:00
parent fe0fd453d8
commit 3af89cd13f
12 changed files with 61 additions and 20 deletions

View File

@ -909,6 +909,7 @@ export class Service {
SERVICE_NAME: serviceName, SERVICE_NAME: serviceName,
DEVICE_UUID: options.uuid, DEVICE_UUID: options.uuid,
DEVICE_TYPE: options.deviceType, DEVICE_TYPE: options.deviceType,
DEVICE_ARCH: options.deviceArch,
HOST_OS_VERSION: options.osVersion, HOST_OS_VERSION: options.osVersion,
SUPERVISOR_VERSION: options.version, SUPERVISOR_VERSION: options.version,
APP_LOCK_PATH: '/tmp/balena/updates.lock', APP_LOCK_PATH: '/tmp/balena/updates.lock',

View File

@ -187,6 +187,7 @@ export interface DeviceMetadata {
appName: string; appName: string;
version: string; version: string;
deviceType: string; deviceType: string;
deviceArch: string;
deviceApiKey: string; deviceApiKey: string;
apiEndpoint: string; apiEndpoint: string;
listenPort: number; listenPort: number;

View File

@ -1,5 +1,6 @@
import * as Bluebird from 'bluebird'; import * as Bluebird from 'bluebird';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { fs } from 'mz';
import { URL } from 'url'; import { URL } from 'url';
import supervisorVersion = require('../lib/supervisor-version'); import supervisorVersion = require('../lib/supervisor-version');
@ -7,6 +8,7 @@ import supervisorVersion = require('../lib/supervisor-version');
import Config from '.'; import Config from '.';
import * as constants from '../lib/constants'; import * as constants from '../lib/constants';
import * as osRelease from '../lib/os-release'; import * as osRelease from '../lib/os-release';
import log from '../lib/supervisor-console';
export const fnSchema = { export const fnSchema = {
version: () => { version: () => {
@ -32,6 +34,22 @@ export const fnSchema = {
osVariant: () => { osVariant: () => {
return osRelease.getOSVariant(constants.hostOSVersionPath); return osRelease.getOSVariant(constants.hostOSVersionPath);
}, },
deviceArch: async () => {
try {
// FIXME: We should be mounting the following file into the supervisor from the
// start-resin-supervisor script, changed in meta-resin - but until then, hardcode it
const data = await fs.readFile(
`${constants.rootMountPoint}/resin-boot/device-type.json`,
'utf8',
);
const deviceInfo = JSON.parse(data);
return deviceInfo.arch;
} catch (e) {
log.error(`Unable to get architecture: ${e}`);
return 'unknown';
}
},
provisioningOptions: (config: Config) => { provisioningOptions: (config: Config) => {
return config return config
.getMany([ .getMany([
@ -40,6 +58,7 @@ export const fnSchema = {
'applicationId', 'applicationId',
'apiKey', 'apiKey',
'deviceApiKey', 'deviceApiKey',
'deviceArch',
'deviceType', 'deviceType',
'apiEndpoint', 'apiEndpoint',
'apiTimeout', 'apiTimeout',
@ -51,6 +70,7 @@ export const fnSchema = {
uuid: conf.uuid, uuid: conf.uuid,
applicationId: conf.applicationId, applicationId: conf.applicationId,
userId: conf.userId, userId: conf.userId,
deviceArch: conf.deviceArch,
deviceType: conf.deviceType, deviceType: conf.deviceType,
provisioningApiKey: conf.apiKey, provisioningApiKey: conf.apiKey,
deviceApiKey: conf.deviceApiKey, deviceApiKey: conf.deviceApiKey,
@ -79,6 +99,7 @@ export const fnSchema = {
'apiEndpoint', 'apiEndpoint',
'deviceApiKey', 'deviceApiKey',
'version', 'version',
'deviceArch',
'deviceType', 'deviceType',
'osVersion', 'osVersion',
]); ]);

View File

@ -38,6 +38,10 @@ export const schemaTypes = {
type: t.string, type: t.string,
default: '', default: '',
}, },
deviceArch: {
type: t.string,
default: 'unknown',
},
deviceType: { deviceType: {
type: t.string, type: t.string,
default: 'unknown', default: 'unknown',
@ -225,6 +229,7 @@ export const schemaTypes = {
apiEndpoint: t.string, apiEndpoint: t.string,
version: t.string, version: t.string,
deviceType: t.string, deviceType: t.string,
deviceArch: t.string,
osVersion: t.union([t.string, NullOrUndefined]), osVersion: t.union([t.string, NullOrUndefined]),
}), }),
default: t.never, default: t.never,

View File

@ -1,7 +1,6 @@
import * as Bluebird from 'bluebird'; import * as Bluebird from 'bluebird';
import { NextFunction, Request, Response, Router } from 'express'; import { NextFunction, Request, Response, Router } from 'express';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { fs } from 'mz';
import { ApplicationManager } from '../application-manager'; import { ApplicationManager } from '../application-manager';
import { Service } from '../compose/service'; import { Service } from '../compose/service';
@ -311,23 +310,25 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
}); });
router.get('/v2/local/device-info', async (_req, res) => { router.get('/v2/local/device-info', async (_req, res) => {
// Return the device type and slug so that local mode builds can use this to try {
// resolve builds const { deviceType, deviceArch } = await applications.config.getMany([
// FIXME: We should be mounting the following file into the supervisor from the 'deviceType',
// start-resin-supervisor script, changed in meta-resin - but until then, hardcode it 'deviceArch',
const data = await fs.readFile( ]);
'/mnt/root/resin-boot/device-type.json',
'utf8',
);
const deviceInfo = JSON.parse(data);
return res.status(200).json({ return res.status(200).json({
status: 'success', status: 'success',
info: { info: {
arch: deviceInfo.arch, arch: deviceArch,
deviceType: deviceInfo.slug, deviceType,
}, },
}); });
} catch (e) {
res.status(500).json({
status: 'failed',
message: e.message,
});
}
}); });
router.get('/v2/local/logs', async (_req, res) => { router.get('/v2/local/logs', async (_req, res) => {

View File

@ -35,6 +35,7 @@ describe('compose/service', () => {
commit: 'abcdef', commit: 'abcdef',
name: 'awesomeDevice', name: 'awesomeDevice',
version: 'v1.0.0', version: 'v1.0.0',
deviceArch: 'amd64',
deviceType: 'raspberry-pi', deviceType: 'raspberry-pi',
osVersion: 'Resin OS 2.0.2', osVersion: 'Resin OS 2.0.2',
}; };
@ -57,6 +58,7 @@ describe('compose/service', () => {
RESIN_APP_ID: '23', RESIN_APP_ID: '23',
RESIN_APP_NAME: 'awesomeApp', RESIN_APP_NAME: 'awesomeApp',
RESIN_DEVICE_UUID: '1234', RESIN_DEVICE_UUID: '1234',
RESIN_DEVICE_ARCH: 'amd64',
RESIN_DEVICE_TYPE: 'raspberry-pi', RESIN_DEVICE_TYPE: 'raspberry-pi',
RESIN_HOST_OS_VERSION: 'Resin OS 2.0.2', RESIN_HOST_OS_VERSION: 'Resin OS 2.0.2',
RESIN_SERVICE_NAME: 'serviceName', RESIN_SERVICE_NAME: 'serviceName',
@ -67,6 +69,7 @@ describe('compose/service', () => {
BALENA_APP_ID: '23', BALENA_APP_ID: '23',
BALENA_APP_NAME: 'awesomeApp', BALENA_APP_NAME: 'awesomeApp',
BALENA_DEVICE_UUID: '1234', BALENA_DEVICE_UUID: '1234',
BALENA_DEVICE_ARCH: 'amd64',
BALENA_DEVICE_TYPE: 'raspberry-pi', BALENA_DEVICE_TYPE: 'raspberry-pi',
BALENA_HOST_OS_VERSION: 'Resin OS 2.0.2', BALENA_HOST_OS_VERSION: 'Resin OS 2.0.2',
BALENA_SERVICE_NAME: 'serviceName', BALENA_SERVICE_NAME: 'serviceName',

View File

@ -97,6 +97,7 @@
"apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd", "apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd",
"deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a", "deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a",
"version": "7.18.0", "version": "7.18.0",
"deviceArch": "amd64",
"deviceType": "raspberrypi3", "deviceType": "raspberrypi3",
"osVersion": "Resin OS 2.13.6+rev1" "osVersion": "Resin OS 2.13.6+rev1"
} }

View File

@ -145,6 +145,7 @@
"RESIN_APP_NAME=supervisortest", "RESIN_APP_NAME=supervisortest",
"RESIN_SERVICE_NAME=main", "RESIN_SERVICE_NAME=main",
"RESIN_DEVICE_UUID=a7feb967fac7f559ccf2a006a36bcf5d", "RESIN_DEVICE_UUID=a7feb967fac7f559ccf2a006a36bcf5d",
"RESIN_DEVICE_ARCH=amd64",
"RESIN_DEVICE_TYPE=raspberrypi3", "RESIN_DEVICE_TYPE=raspberrypi3",
"RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1", "RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
"RESIN_SUPERVISOR_VERSION=7.18.0", "RESIN_SUPERVISOR_VERSION=7.18.0",
@ -155,6 +156,7 @@
"BALENA_APP_NAME=supervisortest", "BALENA_APP_NAME=supervisortest",
"BALENA_SERVICE_NAME=main", "BALENA_SERVICE_NAME=main",
"BALENA_DEVICE_UUID=a7feb967fac7f559ccf2a006a36bcf5d", "BALENA_DEVICE_UUID=a7feb967fac7f559ccf2a006a36bcf5d",
"BALENA_DEVICE_ARCH=amd64",
"BALENA_DEVICE_TYPE=raspberrypi3", "BALENA_DEVICE_TYPE=raspberrypi3",
"BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1", "BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
"BALENA_SUPERVISOR_VERSION=7.18.0", "BALENA_SUPERVISOR_VERSION=7.18.0",

View File

@ -123,6 +123,7 @@
"apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd", "apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd",
"deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a", "deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a",
"version": "7.16.6", "version": "7.16.6",
"deviceArch": "amd64",
"deviceType": "raspberrypi3", "deviceType": "raspberrypi3",
"osVersion": "Resin OS 2.13.6+rev1" "osVersion": "Resin OS 2.13.6+rev1"
} }

View File

@ -145,6 +145,7 @@
"RESIN_APP_NAME=supervisortest", "RESIN_APP_NAME=supervisortest",
"RESIN_SERVICE_NAME=main", "RESIN_SERVICE_NAME=main",
"RESIN_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f", "RESIN_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f",
"RESIN_DEVICE_ARCH=amd64",
"RESIN_DEVICE_TYPE=raspberrypi3", "RESIN_DEVICE_TYPE=raspberrypi3",
"RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1", "RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
"RESIN_SUPERVISOR_VERSION=7.16.6", "RESIN_SUPERVISOR_VERSION=7.16.6",
@ -155,6 +156,7 @@
"BALENA_APP_NAME=supervisortest", "BALENA_APP_NAME=supervisortest",
"BALENA_SERVICE_NAME=main", "BALENA_SERVICE_NAME=main",
"BALENA_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f", "BALENA_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f",
"BALENA_DEVICE_ARCH=amd64",
"BALENA_DEVICE_TYPE=raspberrypi3", "BALENA_DEVICE_TYPE=raspberrypi3",
"BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1", "BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
"BALENA_SUPERVISOR_VERSION=7.16.6", "BALENA_SUPERVISOR_VERSION=7.16.6",

View File

@ -123,6 +123,7 @@
"apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd", "apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd",
"deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a", "deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a",
"version": "7.16.6", "version": "7.16.6",
"deviceArch": "amd64",
"deviceType": "raspberrypi3", "deviceType": "raspberrypi3",
"osVersion": "Resin OS 2.13.6+rev1" "osVersion": "Resin OS 2.13.6+rev1"
} }

View File

@ -145,6 +145,7 @@
"RESIN_APP_NAME=supervisortest", "RESIN_APP_NAME=supervisortest",
"RESIN_SERVICE_NAME=main", "RESIN_SERVICE_NAME=main",
"RESIN_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f", "RESIN_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f",
"RESIN_DEVICE_ARCH=amd64",
"RESIN_DEVICE_TYPE=raspberrypi3", "RESIN_DEVICE_TYPE=raspberrypi3",
"RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1", "RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
"RESIN_SUPERVISOR_VERSION=7.16.6", "RESIN_SUPERVISOR_VERSION=7.16.6",
@ -155,6 +156,7 @@
"BALENA_APP_NAME=supervisortest", "BALENA_APP_NAME=supervisortest",
"BALENA_SERVICE_NAME=main", "BALENA_SERVICE_NAME=main",
"BALENA_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f", "BALENA_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f",
"BALENA_DEVICE_ARCH=amd64",
"BALENA_DEVICE_TYPE=raspberrypi3", "BALENA_DEVICE_TYPE=raspberrypi3",
"BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1", "BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
"BALENA_SUPERVISOR_VERSION=7.16.6", "BALENA_SUPERVISOR_VERSION=7.16.6",