Repository: jboss-dockerfiles/dogen

Issue:
Generate "maintainer" label instead using the MAINTAINER instruction
https://docs.docker.com/engine/reference/builder/#maintainer-deprecated

We should use `maintainer` label.

Discussion:

Patch:
diff --git a/dogen/generator.py b/dogen/generator.py
index d59602d..50ed93c 100644
--- a/dogen/generator.py
+++ b/dogen/generator.py
@@ -226,6 +226,15 @@ class Generator(object):
         self.log.info("Finished!")
 
     def render_from_template(self):
+        maintainer = self.cfg.get('maintainer')
+
+        # https://github.com/jboss-dockerfiles/dogen/issues/129
+        if maintainer:
+            if not self.cfg.get('labels'):
+                self.cfg['labels'] = []
+
+            self.cfg['labels'].append({'name': 'maintainer', 'value': maintainer})
+
         if self.template:
             template_file = self.template
         else:
diff --git a/dogen/templates/template.jinja b/dogen/templates/template.jinja
index 7b81139..4754bb0 100644
--- a/dogen/templates/template.jinja
+++ b/dogen/templates/template.jinja
@@ -18,11 +18,6 @@
 
 FROM {{ helper.base_image(from, version) }}
 
-{% if maintainer %}
-MAINTAINER {{ maintainer }}
-
-{% endif -%}
-
 # Environment variables
 ENV JBOSS_IMAGE_NAME="{{name}}" \
     JBOSS_IMAGE_VERSION="{{version}}" {% if helper.envs(envs) %}\{% for env in helper.envs(envs) %}


Test patch:
diff --git a/tests/test_dockerfile.py b/tests/test_dockerfile.py
index 1c6fec8..33534bb 100644
--- a/tests/test_dockerfile.py
+++ b/tests/test_dockerfile.py
@@ -131,9 +131,6 @@ class TestDockerfile(unittest.TestCase):
 
     # https://github.com/jboss-dockerfiles/dogen/issues/124
     def test_debug_port(self):
-        """
-        Test that cmd: is mapped into a CMD instruction
-        """
         with open(self.yaml, 'ab') as f:
             f.write("ports:\n  - value: 8080\n  - value: 9999\n    expose: False".encode())
 
@@ -147,3 +144,19 @@ class TestDockerfile(unittest.TestCase):
             dockerfile = f.read()
             regex = re.compile(r'.*EXPOSE 8080$',  re.MULTILINE)
             self.assertRegexpMatches(dockerfile, regex)
+
+    # https://github.com/jboss-dockerfiles/dogen/issues/129
+    def test_generating_maintainer_label(self):
+        with open(self.yaml, 'ab') as f:
+            f.write("maintainer: Marek Goldmann".encode())
+
+        generator = Generator(self.log, self.args)
+        generator.configure()
+        generator.render_from_template()
+
+        self.assertEqual(generator.cfg['labels'], [{'name': 'maintainer', 'value': 'Marek Goldmann'}])
+
+        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+maintainer=\"Marek Goldmann\"',  re.MULTILINE)
+            self.assertRegexpMatches(dockerfile, regex)