Repository: jboss-dockerfiles/dogen

Issue:
Remove debugport key
Instead a port key should be used with a specific type, optionally.

Discussion:

Patch:
diff --git a/dogen/plugins/cct.py b/dogen/plugins/cct.py
index 5df1945..75f1ca0 100644
--- a/dogen/plugins/cct.py
+++ b/dogen/plugins/cct.py
@@ -32,10 +32,7 @@ class CCT(Plugin):
     def setup_cct(self, version):
         cctdist = '%s/.dogen/plugin/cct/%s/%s.zip' % (os.path.expanduser('~'), version, version)
         cct_runtime = '%s/.dogen/plugin/cct/%s/cct.zip' % (os.path.expanduser('~'), version)
-        if version == 'master':
-            # we dont care if it doesnt exist - so we ignore errors here
-            shutil.rmtree('%s/.dogen/plugin/cct/%s/' % (os.path.expanduser('~'), version), ignore_errors=True)
-        elif os.path.exists(cctdist):
+        if os.path.exists(cctdist):
             return cct_runtime
 
         os.makedirs(os.path.dirname(cctdist))
@@ -116,11 +113,13 @@ class CCT(Plugin):
 
         self.log.info("CCT plugin downloaded artifacts")
 
+        cfg['entrypoint'] = ['/usr/bin/cct']
+
         if 'runtime' in cfg['cct']:
-            cfg['entrypoint'] = ['/usr/bin/cct']
             self.runtime_changes(cfg)
             cfg['entrypoint'].append(cfg['cct']['runtime_changes'])
-            cfg['entrypoint'].append("-c")
+
+        cfg['entrypoint'].append("-c")
 
         if 'user' not in cfg['cct']:
             cfg['cct']['user'] = 'root'
diff --git a/dogen/schema/kwalify_schema.yaml b/dogen/schema/kwalify_schema.yaml
index 4a5a660..50ba8a0 100644
--- a/dogen/schema/kwalify_schema.yaml
+++ b/dogen/schema/kwalify_schema.yaml
@@ -43,10 +43,11 @@ map:
     seq:
       - map:
           value: {type: int, required: True}
+          expose: {type: bool}
+          description: {type: str}
   volumes:
       seq:
         - {type: str, required: True}
-  debugport: {type: int}
   dogen:
     map:
       version: {type: text}
diff --git a/dogen/template_helper.py b/dogen/template_helper.py
index 4f32ca7..3e88f03 100644
--- a/dogen/template_helper.py
+++ b/dogen/template_helper.py
@@ -63,3 +63,17 @@ class TemplateHelper(object):
 
         return envs
 
+    def ports(self, available_ports):
+        """
+        Combines all ports that should be added to the
+        Dockerfile into one array
+        """
+
+        port_list = []
+
+        for p in available_ports:
+            if p.get('expose', True):
+                port_list.append(p.get('value'))
+
+        return port_list
+
diff --git a/dogen/templates/template.jinja b/dogen/templates/template.jinja
index 4afbd7e..7b81139 100644
--- a/dogen/templates/template.jinja
+++ b/dogen/templates/template.jinja
@@ -45,7 +45,7 @@ LABEL name="$JBOSS_IMAGE_NAME" \
 
 {% if ports %}
 # Exposed ports
-EXPOSE {%- for port in ports %} {{ port.value }}{% endfor %}
+EXPOSE {%- for port in helper.ports(ports) %} {{ port }}{% endfor %}
 
 {% endif %}
 


Test patch:
diff --git a/tests/schemas/good/debugport.yaml b/tests/schemas/good/debugport.yaml
new file mode 100644
index 0000000..57a26a9
--- /dev/null
+++ b/tests/schemas/good/debugport.yaml
@@ -0,0 +1,13 @@
+# The minimal permitted configuration
+release: '1'
+version: '1'
+cmd:
+ - whoami
+from: scratch
+name: someimage
+ports:
+  - value: 8080
+    description: "This is default port"
+  - value: 9999
+    description: "This is debug port port"
+    expose: False
diff --git a/tests/test_dockerfile.py b/tests/test_dockerfile.py
index 63033dc..1c6fec8 100644
--- a/tests/test_dockerfile.py
+++ b/tests/test_dockerfile.py
@@ -128,3 +128,22 @@ class TestDockerfile(unittest.TestCase):
             dockerfile = f.read()
             regex = re.compile(r'.*VOLUME \["/var/lib"\]\nVOLUME \["/usr/lib"\]',  re.MULTILINE)
             self.assertRegexpMatches(dockerfile, regex)
+
+    # 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())
+
+        generator = Generator(self.log, self.args)
+        generator.configure()
+        generator.render_from_template()
+
+        self.assertEqual(generator.cfg['ports'], [{'value': 8080}, {'expose': False, 'value': 9999}])
+
+        with open(os.path.join(self.target, "Dockerfile"), "r") as f:
+            dockerfile = f.read()
+            regex = re.compile(r'.*EXPOSE 8080$',  re.MULTILINE)
+            self.assertRegexpMatches(dockerfile, regex)