Merge pull request #1970 from balena-os/1968-read-hostname-from-config-or-container-etc

Read hostname from config.json with container /etc/hostname as backup
This commit is contained in:
bulldozer-balena[bot] 2022-06-15 23:31:20 +00:00 committed by GitHub
commit 6d6f09eb59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 15 deletions

View File

@ -1,6 +1,5 @@
import * as _ from 'lodash';
import { promises as fs } from 'fs';
import * as path from 'path';
import Network from './network';
import Volume from './volume';
@ -742,7 +741,7 @@ export class App {
opts,
supervisorApiHost,
hostPathExists,
hostnameOnHost,
hostname,
] = await Promise.all([
config.get('extendedEnvOptions'),
dockerUtils
@ -752,20 +751,17 @@ export class App {
firmware: await pathExistsOnHost('/lib/firmware'),
modules: await pathExistsOnHost('/lib/modules'),
}))(),
(async () =>
_.trim(
await fs.readFile(
path.join(constants.rootMountPoint, '/etc/hostname'),
'utf8',
),
))(),
(
(await config.get('hostname')) ??
(await fs.readFile('/etc/hostname', 'utf-8'))
).trim(),
]);
const svcOpts = {
appName: app.name,
supervisorApiHost,
hostPathExists,
hostnameOnHost,
hostname,
...opts,
};

View File

@ -300,7 +300,7 @@ export class Service {
// Any other special case handling
if (config.networkMode === 'host' && !config.hostname) {
config.hostname = options.hostnameOnHost;
config.hostname = options.hostname;
}
config.restart = ComposeUtils.createRestartPolicy(config.restart);
config.command = ComposeUtils.getCommand(config.command, options.imageInfo);

View File

@ -327,7 +327,7 @@ export interface DeviceMetadata {
apiSecret: string;
supervisorApiHost: string;
osVersion: string;
hostnameOnHost: string;
hostname: string;
hostPathExists: {
modules: boolean;
firmware: boolean;

View File

@ -90,7 +90,7 @@
"firmware": true,
"modules": true
},
"hostnameOnHost": "7dadabd",
"hostname": "7dadabd",
"uuid": "a7feb967fac7f559ccf2a006a36bcf5d",
"listenPort": "48484",
"name": "Office",

View File

@ -116,7 +116,7 @@
"firmware": true,
"modules": true
},
"hostnameOnHost": "7dadabd",
"hostname": "7dadabd",
"uuid": "7dadabd4edec3067948d5952c2f2f26f",
"listenPort": "48484",
"name": "Office",

View File

@ -116,7 +116,7 @@
"firmware": true,
"modules": true
},
"hostnameOnHost": "7dadabd",
"hostname": "7dadabd",
"uuid": "7dadabd4edec3067948d5952c2f2f26f",
"listenPort": "48484",
"name": "Office",