mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-24 02:04:14 +00:00
Move config.json flag back to the database
Change-type: patch Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
@ -49,7 +49,6 @@ class Config extends EventEmitter {
|
||||
supervisorOfflineMode: { source: 'config.json', default: false },
|
||||
hostname: { source: 'config.json', mutable: true },
|
||||
persistentLogging: { source: 'config.json', default: false, mutable: true },
|
||||
localMode: { source: 'config.json', mutable: true, default: 'false' },
|
||||
|
||||
version: { source: 'func' },
|
||||
currentApiKey: { source: 'func' },
|
||||
@ -82,6 +81,7 @@ class Config extends EventEmitter {
|
||||
pinDevice: { source: 'db', mutable: true, default: 'null' },
|
||||
currentCommit: { source: 'db', mutable: true },
|
||||
targetStateSet: { source: 'db', mutable: true, default: 'false' },
|
||||
localMode: { source: 'db', mutable: true, default: 'false' },
|
||||
};
|
||||
|
||||
public constructor({ db, configPath }: ConfigOpts) {
|
||||
|
41
src/migrations/M00002.js
Normal file
41
src/migrations/M00002.js
Normal file
@ -0,0 +1,41 @@
|
||||
const fs = require('fs');
|
||||
const configJsonPath = process.env.CONFIG_MOUNT_POINT;
|
||||
|
||||
const { checkTruthy } = require('../lib/validation');
|
||||
|
||||
exports.up = function (knex, Promise) {
|
||||
return new Promise(resolve => {
|
||||
if (!configJsonPath) {
|
||||
console.log('Unable to locate config.json! Things may fail unexpectedly!');
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
fs.readFile(configJsonPath, (err, data) => {
|
||||
if (err) {
|
||||
console.log('Failed to read config.json! Things may fail unexpectedly!');
|
||||
return resolve();
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(data.toString());
|
||||
if (parsed.localMode != null) {
|
||||
return resolve(checkTruthy(parsed.localMode));
|
||||
}
|
||||
return resolve(false);
|
||||
} catch (e) {
|
||||
console.log('Failed to parse config.json! Things may fail unexpectedly!');
|
||||
return resolve(false);
|
||||
}
|
||||
});
|
||||
}).then(localMode => {
|
||||
// We can be sure that this does not already exist in the db because of the previous
|
||||
// migration
|
||||
return knex('config').insert({
|
||||
key: 'localMode',
|
||||
value: localMode.toString(),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function (knex, Promise) {
|
||||
return Promise.reject(new Error('Not Implemented'));
|
||||
};
|
Reference in New Issue
Block a user