Open mahendrapaipuri opened 3 months ago
You are right, this is difference in behavior to docker-compose
:
% docker inspect test-app | grep TEST
"TEST=true"
% podman inspect test-app | grep TEST
"TEST=True",
One workaround is to quote your strings in the yaml file, e.g. as test: 'true'
.
>>> import yaml
>>> yaml.safe_load("xyz: 'true'")
{'xyz': 'true'}
>>> yaml.safe_load("xyz: true")
{'xyz': True}
Another ugly hack is to clear out the implicit type conversions happening inside pyyaml's cache, although his might break other portions of the config. Ideally would be path-dependant to only happen inside environment tags:
% python
Python 3.9.19 (main, Mar 19 2024, 16:08:27)
[Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> sl = yaml.SafeLoader("xyz: true")
>>> del sl.yaml_implicit_resolvers['t']
>>> yaml.safe_load("xyz: true")
{'xyz': 'true'}
The implicit resolver cache is global, so this now affects all yaml parsing within the process.
If you patch the sl =
and del
lines above into your podman-compose.py
file, it seems to work (for this very limited case):
% podman rm test-app
% podman image rm localhost/t2_test
% podman-compose --verbose up -d
...
% podman inspect test-app | grep TEST
"TEST=true",
Hello @shuckc Cheers for the reply!!
One workaround is to quote your strings in the yaml file, e.g. as test: 'true'
Yes, this is what we ended up doing.
I agree that patching this globally with pyyaml can have a lot of broken cases. Maybe documenting this behaviour can help users.
Describe the bug
When we use boolean types in compose file, Python will convert them into its native boolean types. This means a value set as
test: true
in compose file will be stored at{'value': True}
once it is loaded. If this valuetest
is used inside the Dockerfile it will be eventually set asTrue
while we set the value astrue
on compose file and we expect it to be set astrue
in the container.To Reproduce For instance for a compose file as follows:
and in the
config
folder, a Dockerfile as follows:By starting the containers using
podman-compose up -d
and inspecting the container, we can see env varTEST
will be set toTrue
and nottrue
.Expected behavior Arguments must be set the value defined in compose file.
Actual behavior Boolean arguments getting capitalized.
Output