mirror of
https://github.com/docker/compose.git
synced 2025-07-14 17:24:29 +02:00
Disallow booleans in environment
When users were putting true/false/yes/no in the environment key, the YML parser was converting them into True/False, rather than leaving them as a string. This change will force people to put them in quotes, thus ensuring that the value gets passed through as intended. Signed-off-by: Mazz Mosley <mazz@houseofmnowster.com>
This commit is contained in:
parent
e33ab0cdd8
commit
a594a2ccc2
@ -36,7 +36,15 @@
|
|||||||
|
|
||||||
"environment": {
|
"environment": {
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{"type": "object"},
|
{
|
||||||
|
"type": "object",
|
||||||
|
"patternProperties": {
|
||||||
|
"^[a-zA-Z0-9_]+$": {
|
||||||
|
"type": ["string", "number"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
{"type": "array", "items": {"type": "string"}, "uniqueItems": true}
|
{"type": "array", "items": {"type": "string"}, "uniqueItems": true}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -184,17 +184,21 @@ Mount all of the volumes from another service or container.
|
|||||||
|
|
||||||
### environment
|
### environment
|
||||||
|
|
||||||
Add environment variables. You can use either an array or a dictionary.
|
Add environment variables. You can use either an array or a dictionary. Any
|
||||||
|
boolean values; true, false, yes no, need to be enclosed in quotes to ensure
|
||||||
|
they are not converted to True or False by the YML parser.
|
||||||
|
|
||||||
Environment variables with only a key are resolved to their values on the
|
Environment variables with only a key are resolved to their values on the
|
||||||
machine Compose is running on, which can be helpful for secret or host-specific values.
|
machine Compose is running on, which can be helpful for secret or host-specific values.
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
RACK_ENV: development
|
RACK_ENV: development
|
||||||
|
SHOW: 'true'
|
||||||
SESSION_SECRET:
|
SESSION_SECRET:
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
- RACK_ENV=development
|
- RACK_ENV=development
|
||||||
|
- SHOW=true
|
||||||
- SESSION_SECRET
|
- SESSION_SECRET
|
||||||
|
|
||||||
### env_file
|
### env_file
|
||||||
|
@ -270,15 +270,15 @@ class ConfigTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(service[0]['entrypoint'], entrypoint)
|
self.assertEqual(service[0]['entrypoint'], entrypoint)
|
||||||
|
|
||||||
def test_validation_message_for_invalid_type_when_multiple_types_allowed(self):
|
def test_config_environment_contains_boolean_validation_error(self):
|
||||||
expected_error_msg = "Service 'web' configuration key 'mem_limit' contains an invalid type, it should be a number or a string"
|
expected_error_msg = "Service 'web' configuration key 'environment' contains an invalid type"
|
||||||
|
|
||||||
with self.assertRaisesRegexp(ConfigurationError, expected_error_msg):
|
with self.assertRaisesRegexp(ConfigurationError, expected_error_msg):
|
||||||
config.load(
|
config.load(
|
||||||
config.ConfigDetails(
|
config.ConfigDetails(
|
||||||
{'web': {
|
{'web': {
|
||||||
'image': 'busybox',
|
'image': 'busybox',
|
||||||
'mem_limit': ['incorrect']
|
'environment': {'SHOW_STUFF': True}
|
||||||
}},
|
}},
|
||||||
'working_dir',
|
'working_dir',
|
||||||
'filename.yml'
|
'filename.yml'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user