Merge pull request #1159 from balena-io/fix-committed-image

Always filter environment configuration
This commit is contained in:
CameronDiver 2019-12-09 13:20:58 +00:00 committed by GitHub
commit e42935d84e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,7 @@ import * as updateLock from '../lib/update-lock';
import { sanitiseComposeConfig } from './sanitise';
import log from '../lib/supervisor-console';
import { EnvVarObject } from '../lib/types';
const SERVICE_NETWORK_MODE_REGEX = /service:\s*(.+)/;
const CONTAINER_NETWORK_MODE_REGEX = /container:\s*(.+)/;
@ -232,11 +233,16 @@ export class Service {
}
// Add default environment variables and labels
config.environment = Service.extendEnvVars(
config.environment || {},
options,
service.appId || 0,
service.serviceName || '',
// 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 || {},
options,
service.appId || 0,
service.serviceName || '',
),
);
config.labels = ComposeUtils.normalizeLabels(
Service.extendLabels(
@ -496,9 +502,8 @@ export class Service {
_.keys(container.Config.Volumes || {}),
),
image: container.Config.Image,
environment: _.omit(
environment: Service.omitDeviceNameVars(
conversions.envArrayToObject(container.Config.Env || []),
['RESIN_DEVICE_NAME_AT_INIT', 'BALENA_DEVICE_NAME_AT_INIT'],
),
privileged: container.HostConfig.Privileged || false,
labels: ComposeUtils.normalizeLabels(container.Config.Labels || {}),
@ -965,6 +970,13 @@ export class Service {
return sameNetwork;
}
private static omitDeviceNameVars(env: EnvVarObject) {
return _.omit(env, [
'RESIN_DEVICE_NAME_AT_INIT',
'BALENA_DEVICE_NAME_AT_INIT',
]);
}
private static extendLabels(
labels: { [labelName: string]: string } | null | undefined,
{ imageInfo }: DeviceMetadata,