Skip to content

Commit

Permalink
Use json.dumps to render deployment params that are to be put as envi…
Browse files Browse the repository at this point in the history
…ronment variables
  • Loading branch information
ricardogsilva committed Dec 6, 2024
1 parent 3b69e0f commit 25db9a3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion deployments/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,18 @@ def handle(self) -> None:
self.config.deployment_root / "compose.production.template.yaml"
)
compose_template = Template(compose_teplate_path.read_text())
rendered = compose_template.substitute(dataclasses.asdict(self.config))

render_context = dataclasses.asdict(self.config)
render_kwargs = {}
# conf keys that have _env_ in their name are going to be put as env values
# inside the container and will be consumed by pydantic, so we dump them as
# JSON in order to ensure correct handling of parameters that represent
# collections, for example cors origins, which is a list of strings
for k, v in render_context.items():
if "_env_" in k:
render_kwargs[k] = json.dumps(v)

rendered = compose_template.substitute(render_context, **render_kwargs)
target_path = Path(self.config.deployment_root / "compose.production.yaml")
with target_path.open("w") as fh:
for line in rendered.splitlines(keepends=True):
Expand Down

0 comments on commit 25db9a3

Please sign in to comment.