Repository: jboss-dockerfiles/dogen

Issue:
Set the "description" label based on the value of "description" field

Discussion:

Patch:
diff --git a/dogen/generator.py b/dogen/generator.py
index 50ed93c..335db99 100644
--- a/dogen/generator.py
+++ b/dogen/generator.py
@@ -226,14 +226,16 @@ class Generator(object):
         self.log.info("Finished!")
 
     def render_from_template(self):
-        maintainer = self.cfg.get('maintainer')
+        if not self.cfg.get('labels'):
+            self.cfg['labels'] = []
 
         # https://github.com/jboss-dockerfiles/dogen/issues/129
-        if maintainer:
-            if not self.cfg.get('labels'):
-                self.cfg['labels'] = []
+        # https://github.com/jboss-dockerfiles/dogen/issues/137
+        for label in ['maintainer', 'description']:
+            value = self.cfg.get(label)
 
-            self.cfg['labels'].append({'name': 'maintainer', 'value': maintainer})
+            if value:
+                self.cfg['labels'].append({'name': label, 'value': value})
 
         if self.template:
             template_file = self.template


Test patch:
diff --git a/tests/test_dockerfile.py b/tests/test_dockerfile.py
index 33534bb..2ffa5a6 100644
--- a/tests/test_dockerfile.py
+++ b/tests/test_dockerfile.py
@@ -160,3 +160,19 @@ class TestDockerfile(unittest.TestCase):
             dockerfile = f.read()
             regex = re.compile(r'LABEL name=\"\$JBOSS_IMAGE_NAME\" \\\s+version=\"\$JBOSS_IMAGE_VERSION\" \\\s+architecture=\"x86_64\" \\\s+com.redhat.component=\"someimage\" \\\s+maintainer=\"Marek Goldmann\"',  re.MULTILINE)
             self.assertRegexpMatches(dockerfile, regex)
+
+    # https://github.com/jboss-dockerfiles/dogen/issues/137
+    def test_generating_description_label(self):
+        with open(self.yaml, 'ab') as f:
+            f.write("description: This is a nice image".encode())
+
+        generator = Generator(self.log, self.args)
+        generator.configure()
+        generator.render_from_template()
+
+        self.assertEqual(generator.cfg['labels'], [{'name': 'description', 'value': 'This is a nice image'}])
+
+        with open(os.path.join(self.target, "Dockerfile"), "r") as f:
+            dockerfile = f.read()
+            regex = re.compile(r'LABEL name=\"\$JBOSS_IMAGE_NAME\" \\\s+version=\"\$JBOSS_IMAGE_VERSION\" \\\s+architecture=\"x86_64\" \\\s+com.redhat.component=\"someimage\" \\\s+description=\"This is a nice image\"',  re.MULTILINE)
+            self.assertRegexpMatches(dockerfile, regex)