mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-18 18:56:24 +00:00
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:
parent
fe0fd453d8
commit
3af89cd13f
@ -909,6 +909,7 @@ export class Service {
|
||||
SERVICE_NAME: serviceName,
|
||||
DEVICE_UUID: options.uuid,
|
||||
DEVICE_TYPE: options.deviceType,
|
||||
DEVICE_ARCH: options.deviceArch,
|
||||
HOST_OS_VERSION: options.osVersion,
|
||||
SUPERVISOR_VERSION: options.version,
|
||||
APP_LOCK_PATH: '/tmp/balena/updates.lock',
|
||||
|
@ -187,6 +187,7 @@ export interface DeviceMetadata {
|
||||
appName: string;
|
||||
version: string;
|
||||
deviceType: string;
|
||||
deviceArch: string;
|
||||
deviceApiKey: string;
|
||||
apiEndpoint: string;
|
||||
listenPort: number;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as Bluebird from 'bluebird';
|
||||
import * as _ from 'lodash';
|
||||
import { fs } from 'mz';
|
||||
import { URL } from 'url';
|
||||
|
||||
import supervisorVersion = require('../lib/supervisor-version');
|
||||
@ -7,6 +8,7 @@ import supervisorVersion = require('../lib/supervisor-version');
|
||||
import Config from '.';
|
||||
import * as constants from '../lib/constants';
|
||||
import * as osRelease from '../lib/os-release';
|
||||
import log from '../lib/supervisor-console';
|
||||
|
||||
export const fnSchema = {
|
||||
version: () => {
|
||||
@ -32,6 +34,22 @@ export const fnSchema = {
|
||||
osVariant: () => {
|
||||
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) => {
|
||||
return config
|
||||
.getMany([
|
||||
@ -40,6 +58,7 @@ export const fnSchema = {
|
||||
'applicationId',
|
||||
'apiKey',
|
||||
'deviceApiKey',
|
||||
'deviceArch',
|
||||
'deviceType',
|
||||
'apiEndpoint',
|
||||
'apiTimeout',
|
||||
@ -51,6 +70,7 @@ export const fnSchema = {
|
||||
uuid: conf.uuid,
|
||||
applicationId: conf.applicationId,
|
||||
userId: conf.userId,
|
||||
deviceArch: conf.deviceArch,
|
||||
deviceType: conf.deviceType,
|
||||
provisioningApiKey: conf.apiKey,
|
||||
deviceApiKey: conf.deviceApiKey,
|
||||
@ -79,6 +99,7 @@ export const fnSchema = {
|
||||
'apiEndpoint',
|
||||
'deviceApiKey',
|
||||
'version',
|
||||
'deviceArch',
|
||||
'deviceType',
|
||||
'osVersion',
|
||||
]);
|
||||
|
@ -38,6 +38,10 @@ export const schemaTypes = {
|
||||
type: t.string,
|
||||
default: '',
|
||||
},
|
||||
deviceArch: {
|
||||
type: t.string,
|
||||
default: 'unknown',
|
||||
},
|
||||
deviceType: {
|
||||
type: t.string,
|
||||
default: 'unknown',
|
||||
@ -225,6 +229,7 @@ export const schemaTypes = {
|
||||
apiEndpoint: t.string,
|
||||
version: t.string,
|
||||
deviceType: t.string,
|
||||
deviceArch: t.string,
|
||||
osVersion: t.union([t.string, NullOrUndefined]),
|
||||
}),
|
||||
default: t.never,
|
||||
|
@ -1,7 +1,6 @@
|
||||
import * as Bluebird from 'bluebird';
|
||||
import { NextFunction, Request, Response, Router } from 'express';
|
||||
import * as _ from 'lodash';
|
||||
import { fs } from 'mz';
|
||||
|
||||
import { ApplicationManager } from '../application-manager';
|
||||
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) => {
|
||||
// Return the device type and slug so that local mode builds can use this to
|
||||
// resolve builds
|
||||
// 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(
|
||||
'/mnt/root/resin-boot/device-type.json',
|
||||
'utf8',
|
||||
);
|
||||
const deviceInfo = JSON.parse(data);
|
||||
try {
|
||||
const { deviceType, deviceArch } = await applications.config.getMany([
|
||||
'deviceType',
|
||||
'deviceArch',
|
||||
]);
|
||||
|
||||
return res.status(200).json({
|
||||
status: 'success',
|
||||
info: {
|
||||
arch: deviceInfo.arch,
|
||||
deviceType: deviceInfo.slug,
|
||||
},
|
||||
});
|
||||
return res.status(200).json({
|
||||
status: 'success',
|
||||
info: {
|
||||
arch: deviceArch,
|
||||
deviceType,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
res.status(500).json({
|
||||
status: 'failed',
|
||||
message: e.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/v2/local/logs', async (_req, res) => {
|
||||
|
@ -35,6 +35,7 @@ describe('compose/service', () => {
|
||||
commit: 'abcdef',
|
||||
name: 'awesomeDevice',
|
||||
version: 'v1.0.0',
|
||||
deviceArch: 'amd64',
|
||||
deviceType: 'raspberry-pi',
|
||||
osVersion: 'Resin OS 2.0.2',
|
||||
};
|
||||
@ -57,6 +58,7 @@ describe('compose/service', () => {
|
||||
RESIN_APP_ID: '23',
|
||||
RESIN_APP_NAME: 'awesomeApp',
|
||||
RESIN_DEVICE_UUID: '1234',
|
||||
RESIN_DEVICE_ARCH: 'amd64',
|
||||
RESIN_DEVICE_TYPE: 'raspberry-pi',
|
||||
RESIN_HOST_OS_VERSION: 'Resin OS 2.0.2',
|
||||
RESIN_SERVICE_NAME: 'serviceName',
|
||||
@ -67,6 +69,7 @@ describe('compose/service', () => {
|
||||
BALENA_APP_ID: '23',
|
||||
BALENA_APP_NAME: 'awesomeApp',
|
||||
BALENA_DEVICE_UUID: '1234',
|
||||
BALENA_DEVICE_ARCH: 'amd64',
|
||||
BALENA_DEVICE_TYPE: 'raspberry-pi',
|
||||
BALENA_HOST_OS_VERSION: 'Resin OS 2.0.2',
|
||||
BALENA_SERVICE_NAME: 'serviceName',
|
||||
|
@ -97,6 +97,7 @@
|
||||
"apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd",
|
||||
"deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a",
|
||||
"version": "7.18.0",
|
||||
"deviceArch": "amd64",
|
||||
"deviceType": "raspberrypi3",
|
||||
"osVersion": "Resin OS 2.13.6+rev1"
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,7 @@
|
||||
"RESIN_APP_NAME=supervisortest",
|
||||
"RESIN_SERVICE_NAME=main",
|
||||
"RESIN_DEVICE_UUID=a7feb967fac7f559ccf2a006a36bcf5d",
|
||||
"RESIN_DEVICE_ARCH=amd64",
|
||||
"RESIN_DEVICE_TYPE=raspberrypi3",
|
||||
"RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
|
||||
"RESIN_SUPERVISOR_VERSION=7.18.0",
|
||||
@ -155,6 +156,7 @@
|
||||
"BALENA_APP_NAME=supervisortest",
|
||||
"BALENA_SERVICE_NAME=main",
|
||||
"BALENA_DEVICE_UUID=a7feb967fac7f559ccf2a006a36bcf5d",
|
||||
"BALENA_DEVICE_ARCH=amd64",
|
||||
"BALENA_DEVICE_TYPE=raspberrypi3",
|
||||
"BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
|
||||
"BALENA_SUPERVISOR_VERSION=7.18.0",
|
||||
|
@ -123,6 +123,7 @@
|
||||
"apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd",
|
||||
"deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a",
|
||||
"version": "7.16.6",
|
||||
"deviceArch": "amd64",
|
||||
"deviceType": "raspberrypi3",
|
||||
"osVersion": "Resin OS 2.13.6+rev1"
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,7 @@
|
||||
"RESIN_APP_NAME=supervisortest",
|
||||
"RESIN_SERVICE_NAME=main",
|
||||
"RESIN_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f",
|
||||
"RESIN_DEVICE_ARCH=amd64",
|
||||
"RESIN_DEVICE_TYPE=raspberrypi3",
|
||||
"RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
|
||||
"RESIN_SUPERVISOR_VERSION=7.16.6",
|
||||
@ -155,6 +156,7 @@
|
||||
"BALENA_APP_NAME=supervisortest",
|
||||
"BALENA_SERVICE_NAME=main",
|
||||
"BALENA_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f",
|
||||
"BALENA_DEVICE_ARCH=amd64",
|
||||
"BALENA_DEVICE_TYPE=raspberrypi3",
|
||||
"BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
|
||||
"BALENA_SUPERVISOR_VERSION=7.16.6",
|
||||
|
@ -123,6 +123,7 @@
|
||||
"apiSecret": "d4bf8369519c32adaa5dd1f84367aa817403f2a3ce976be9c9bacd4d344fdd",
|
||||
"deviceApiKey": "ff89e1d8db58a7ca52a435f2adea319a",
|
||||
"version": "7.16.6",
|
||||
"deviceArch": "amd64",
|
||||
"deviceType": "raspberrypi3",
|
||||
"osVersion": "Resin OS 2.13.6+rev1"
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,7 @@
|
||||
"RESIN_APP_NAME=supervisortest",
|
||||
"RESIN_SERVICE_NAME=main",
|
||||
"RESIN_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f",
|
||||
"RESIN_DEVICE_ARCH=amd64",
|
||||
"RESIN_DEVICE_TYPE=raspberrypi3",
|
||||
"RESIN_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
|
||||
"RESIN_SUPERVISOR_VERSION=7.16.6",
|
||||
@ -155,6 +156,7 @@
|
||||
"BALENA_APP_NAME=supervisortest",
|
||||
"BALENA_SERVICE_NAME=main",
|
||||
"BALENA_DEVICE_UUID=7dadabd4edec3067948d5952c2f2f26f",
|
||||
"BALENA_DEVICE_ARCH=amd64",
|
||||
"BALENA_DEVICE_TYPE=raspberrypi3",
|
||||
"BALENA_HOST_OS_VERSION=Resin OS 2.13.6+rev1",
|
||||
"BALENA_SUPERVISOR_VERSION=7.16.6",
|
||||
|
Loading…
Reference in New Issue
Block a user