Prechádzať zdrojové kódy

Allowing null for build args

Signed-off-by: Dimitar Bonev <[email protected]>
Dimitar Bonev 9 rokov pred
rodič
commit
81b7fba33e

+ 1 - 14
compose/config/config_schema_v2.0.json

@@ -58,20 +58,7 @@
               "properties": {
                 "context": {"type": "string"},
                 "dockerfile": {"type": "string"},
-                "args": {
-                  "oneOf": [
-                    {"$ref": "#/definitions/list_of_strings"},
-                    {
-                      "type": "object",
-                      "patternProperties": {
-                        "^.+$": {
-                          "type": ["string", "number"]
-                        }
-                      },
-                      "additionalProperties": false
-                    }
-                  ]
-                }
+                "args": {"$ref": "#/definitions/list_or_dict"}
               },
               "additionalProperties": false
             }

+ 26 - 1
tests/unit/config/config_test.py

@@ -404,7 +404,7 @@ class ConfigTest(unittest.TestCase):
             config.load(config_details)
         assert (
             "services.web.build.args contains an invalid type, it should be an "
-            "array, or an object" in exc.exconly()
+            "object, or an array" in exc.exconly()
         )
 
     def test_config_integer_service_name_raise_validation_error(self):
@@ -689,6 +689,31 @@ class ConfigTest(unittest.TestCase):
         assert service['build']['args']['opt1'] == '42'
         assert service['build']['args']['opt2'] == 'foobar'
 
+    def test_build_args_allow_empty_properties(self):
+        service = config.load(
+            build_config_details(
+                {
+                    'version': '2',
+                    'services': {
+                        'web': {
+                            'build': {
+                                'context': '.',
+                                'dockerfile': 'Dockerfile-alt',
+                                'args': {
+                                    'foo': None
+                                }
+                            }
+                        }
+                    }
+                },
+                'tests/fixtures/extends',
+                'filename.yml'
+            )
+        ).services[0]
+        assert 'args' in service['build']
+        assert 'foo' in service['build']['args']
+        assert service['build']['args']['foo'] == 'None'
+
     def test_load_with_multiple_files_mismatched_networks_format(self):
         base_file = config.ConfigFile(
             'base.yaml',