Repository: jboss-dockerfiles/dogen

Issue:
Add support for volumes
The MaaS broker images needs a volume.  Can support be added for this?  https://docs.docker.com/engine/reference/builder/#volume

Discussion:

Patch:
diff --git a/dogen/schema/kwalify_schema.yaml b/dogen/schema/kwalify_schema.yaml
index 040cd19..58ea832 100644
--- a/dogen/schema/kwalify_schema.yaml
+++ b/dogen/schema/kwalify_schema.yaml
@@ -43,6 +43,9 @@ map:
     seq:
       - map:
           value: {type: int, required: True}
+  volumes:
+      seq:
+        - {type: str, required: True}
   debugport: {type: int}
   dogen:
     map:
diff --git a/dogen/templates/template.jinja b/dogen/templates/template.jinja
index 170fd59..0912004 100644
--- a/dogen/templates/template.jinja
+++ b/dogen/templates/template.jinja
@@ -121,6 +121,12 @@ USER root
 RUN rm -rf /tmp/artifacts
 {% endif %}
 
+{%- if volumes %}
+{% for volume in volumes %}
+VOLUME ["{{ volume }}"]
+{% endfor %}
+{% endif %}
+
 {%- if workdir %}
 # Specify the working directory
 WORKDIR {{ workdir }}


Test patch:
diff --git a/tests/test_dockerfile.py b/tests/test_dockerfile.py
index 119b6de..63033dc 100644
--- a/tests/test_dockerfile.py
+++ b/tests/test_dockerfile.py
@@ -110,3 +110,21 @@ class TestDockerfile(unittest.TestCase):
             dockerfile = f.read()
             regex = re.compile(r'.*ENTRYPOINT \["/usr/bin/time"\]',  re.MULTILINE)
             self.assertRegexpMatches(dockerfile, regex)
+
+    def test_volumes(self):
+        """
+        Test that cmd: is mapped into a CMD instruction
+        """
+        with open(self.yaml, 'ab') as f:
+            f.write("volumes:\n  - '/var/lib'\n  - '/usr/lib'".encode())
+
+        generator = Generator(self.log, self.args)
+        generator.configure()
+        generator.render_from_template()
+
+        self.assertEqual(generator.cfg['volumes'], ['/var/lib', '/usr/lib'])
+
+        with open(os.path.join(self.target, "Dockerfile"), "r") as f:
+            dockerfile = f.read()
+            regex = re.compile(r'.*VOLUME \["/var/lib"\]\nVOLUME \["/usr/lib"\]',  re.MULTILINE)
+            self.assertRegexpMatches(dockerfile, regex)