mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 21:57:54 +00:00
Always filter environment configuration
This means that if an image is created with a committed container, we won't assume that it does not contain the balena env vars Change-type: patch Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
2a1d82ced2
commit
03a701cded
@ -22,6 +22,7 @@ import * as updateLock from '../lib/update-lock';
|
|||||||
import { sanitiseComposeConfig } from './sanitise';
|
import { sanitiseComposeConfig } from './sanitise';
|
||||||
|
|
||||||
import log from '../lib/supervisor-console';
|
import log from '../lib/supervisor-console';
|
||||||
|
import { EnvVarObject } from '../lib/types';
|
||||||
|
|
||||||
const SERVICE_NETWORK_MODE_REGEX = /service:\s*(.+)/;
|
const SERVICE_NETWORK_MODE_REGEX = /service:\s*(.+)/;
|
||||||
const CONTAINER_NETWORK_MODE_REGEX = /container:\s*(.+)/;
|
const CONTAINER_NETWORK_MODE_REGEX = /container:\s*(.+)/;
|
||||||
@ -232,11 +233,16 @@ export class Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add default environment variables and labels
|
// Add default environment variables and labels
|
||||||
config.environment = Service.extendEnvVars(
|
// We also omit any device name variables which may have
|
||||||
|
// been input from the image (for example, if you docker
|
||||||
|
// commit a container which has been run on a balena device)
|
||||||
|
config.environment = Service.omitDeviceNameVars(
|
||||||
|
Service.extendEnvVars(
|
||||||
config.environment || {},
|
config.environment || {},
|
||||||
options,
|
options,
|
||||||
service.appId || 0,
|
service.appId || 0,
|
||||||
service.serviceName || '',
|
service.serviceName || '',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
config.labels = ComposeUtils.normalizeLabels(
|
config.labels = ComposeUtils.normalizeLabels(
|
||||||
Service.extendLabels(
|
Service.extendLabels(
|
||||||
@ -496,9 +502,8 @@ export class Service {
|
|||||||
_.keys(container.Config.Volumes || {}),
|
_.keys(container.Config.Volumes || {}),
|
||||||
),
|
),
|
||||||
image: container.Config.Image,
|
image: container.Config.Image,
|
||||||
environment: _.omit(
|
environment: Service.omitDeviceNameVars(
|
||||||
conversions.envArrayToObject(container.Config.Env || []),
|
conversions.envArrayToObject(container.Config.Env || []),
|
||||||
['RESIN_DEVICE_NAME_AT_INIT', 'BALENA_DEVICE_NAME_AT_INIT'],
|
|
||||||
),
|
),
|
||||||
privileged: container.HostConfig.Privileged || false,
|
privileged: container.HostConfig.Privileged || false,
|
||||||
labels: ComposeUtils.normalizeLabels(container.Config.Labels || {}),
|
labels: ComposeUtils.normalizeLabels(container.Config.Labels || {}),
|
||||||
@ -965,6 +970,13 @@ export class Service {
|
|||||||
return sameNetwork;
|
return sameNetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static omitDeviceNameVars(env: EnvVarObject) {
|
||||||
|
return _.omit(env, [
|
||||||
|
'RESIN_DEVICE_NAME_AT_INIT',
|
||||||
|
'BALENA_DEVICE_NAME_AT_INIT',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
private static extendLabels(
|
private static extendLabels(
|
||||||
labels: { [labelName: string]: string } | null | undefined,
|
labels: { [labelName: string]: string } | null | undefined,
|
||||||
{ imageInfo }: DeviceMetadata,
|
{ imageInfo }: DeviceMetadata,
|
||||||
|
Loading…
Reference in New Issue
Block a user