Repository: deis/deis

Issue:
ENV variables declared in Dockerfile are not present in applications
Upgraded to to 0.13.0 today and none of my applications are working any more.  They all rely on environment variables declared using `ENV` in their Dockerfiles, and it seems that these are not present by the time the containers are run on deis.

I did a bit of comparison between my working 0.12 cluster and my 0.13 cluster by shelling in and running `docker inspect`.  0.12 shows all the variables I expect in the `Env` entry, whereas 0.13 only shows the values set via `deis config:set`

I'm not too familiar with the deis codebase, but it looks like the changes in registry/private.py in 99ccce4a may have caused this - before the deis config was merged with the existing configuration, but now it's not.



Discussion:
I think you hit the nail on the head there. Apologies for that. I'll fix it up and add a regression test so we don't hit this issue again. Thanks for the bug report!


Resolving patch:
diff --git a/controller/api/models.py b/controller/api/models.py
--- a/controller/api/models.py
+++ b/controller/api/models.py
@@ -618,7 +618,8 @@ def new(self, user, config=None, build=None, summary=None, source_version='lates
         if not build:
             build = self.build
         # always create a release off the latest image
-        source_image = '{}:{}'.format(build.image, source_version)
+        source_tag = 'git-{}'.format(build.sha) if build.sha else source_version
+        source_image = '{}:{}'.format(build.image, source_tag)
         # construct fully-qualified target image
         new_version = self.version + 1
         tag = 'v{}'.format(new_version)
diff --git a/controller/registry/private.py b/controller/registry/private.py
--- a/controller/registry/private.py
+++ b/controller/registry/private.py
@@ -59,7 +59,7 @@ def publish_release(source, config, target):
     image['id'] = _new_id()
     config['DEIS_APP'] = target_image
     config['DEIS_RELEASE'] = target_tag
-    image['config']['Env'] = _construct_env(config)
+    image['config']['Env'] = _construct_env(image['config']['Env'], config)
     # update and tag the new image
     _commit(target_image, image, _empty_tar_archive(), target_tag)
 
@@ -72,8 +72,6 @@ def _commit(repository_path, image, layer, tag):
     cookies = _put_layer(image['id'], layer)
     _put_checksum(image, cookies)
     _put_tag(image['id'], repository_path, tag)
-    # point latest to the new tag
-    _put_tag(image['id'], repository_path, 'latest')
 
 
 def _put_first_image(repository_path):
@@ -162,10 +160,17 @@ def _put_tag(image_id, repository_path, tag):
 
 # utility functions
 
-def _construct_env(config):
+def _construct_env(env, config):
     "Update current environment with latest config"
     new_env = []
-    # add config ENV items
+    # see if we need to update existing ENV vars
+    for e in env:
+        k, v = e.split('=', 1)
+        if k in config:
+            # update values defined by config
+            v = config.pop(k)
+        new_env.append("{}={}".format(encode(k), encode(v)))
+    # add other config ENV items
     for k, v in config.items():
         new_env.append("{}={}".format(encode(k), encode(v)))
     return new_env


Test patch: