Repository navigation
fix(renderer): quote env entries in generated compose files - #565
Open
Abhishek9639 wants to merge 1 commit into
Open
Abhishek9639 wants to merge 1 commit into
Abhishek9639 wants to merge 1 commit into
Conversation
Env entries were rendered as `- KEY=value`, so YAML parsed the value before docker compose saw it. A value containing " #" was cut off at the "#", and a value containing ": " turned into a mapping that docker compose rejects. Add a yaml_quote filter that lets PyYAML emit each entry as a single-line double-quoted scalar, and use it for the additional_env loops. tojson would have been shorter, but it escapes characters outside the BMP as surrogate pairs, which docker compose refuses. Signed-off-by: Abhishek <abhishekup082@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Env entries in the build-target and run compose templates were rendered as
- KEY=value, so YAML parsed the value before docker compose got it. A value with#lost everything after the#, and a value with:(inline JSON, say) became a mapping that docker compose rejects.This adds a small
yaml_quotefilter inrenderer.pythat lets PyYAML write each entry as a single-line, double-quoted scalar, and uses it for the three loops fed byadditional_env: the builder env, the run module env and the builder sidecar passthrough env. The filter is registered in acreate_template_env()helper thatrender_template()now uses, and the template tests build their Jinja environment through it too, so they render with the same filters as production.In the issue I suggested
tojson. I switched because it escapes anything outside the BMP as a surrogate pair (rocket 🚀becomes"rocket \ud83d\ude80"), and docker compose rejects that. Before this change an emoji in a value worked, sotojsonwould have traded one breakage for another. PyYAML emits\U0001F680instead, which both PyYAML and compose read back correctly.${VAR}references still work, since compose interpolates after parsing.Not changed here: framework-owned env and volume lines (paths,
HARNESS_NAME,TARGET_NAME) are still plain scalars. They'd only break on a--work-diror harness name containing#or:, so I left them out to keep this focused.Fixes #548
User Impact
additional_envvalues now reach the containers as written. No config change or migration is needed.Release Note / Changelog
CHANGELOG.md([Unreleased]) for user-facing changesValidation
uv run verify: ruff check, ruff format and pyright pass, plus 830 unit tests and 31 libCRS tests.test_renderer_build_target.pyandtest_renderer_run_compose.pycover#, inline JSON,:, double quotes,${VAR}and a non-BMP character, plus a direct test thatyaml_quotekeeps long values on one line. Against the old templates the#, JSON and:cases fail; withtojsoninstead ofyaml_quotethe non-BMP case fails.oss-crs build-targetfails withservices.target_builder.environment.[8]: unexpected type map[string]interface {}. With this branch it builds, and the container sees-max_len=100 #keep,{"temperature": 0.2},mode: fastandrocket 🚀exactly, with${HOME}expanded.docker compose config; module and builder sidecar env come through unchanged.Checklist