From 03a701cdedf6a40aa707ca5ca22af8f1c9a14d40 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Mon, 9 Dec 2019 11:28:34 +0000 Subject: [PATCH] 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 --- src/compose/service.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/compose/service.ts b/src/compose/service.ts index 349deaef..33643f69 100644 --- a/src/compose/service.ts +++ b/src/compose/service.ts @@ -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,