Skip to content

Add environment variables interpolation#1390

Open
antonpetrov145 wants to merge 2 commits intocontainers:mainfrom
antonpetrov145:env-vars-interploation
Open

Add environment variables interpolation#1390
antonpetrov145 wants to merge 2 commits intocontainers:mainfrom
antonpetrov145:env-vars-interploation

Conversation

@antonpetrov145
Copy link
Copy Markdown

Added the existing functionality to interpolate the environment set in compose.

Refers to 1384

@p12tic
Copy link
Copy Markdown
Collaborator

p12tic commented Feb 16, 2026

Tests are broken.

@antonpetrov145
Copy link
Copy Markdown
Author

@p12tic seems the tests are passing now, what got me confused are these lines

os.environ.update({
    key: value  # type: ignore[misc]
    for key, value in dotenv_dict.items()
    if key.startswith("PODMAN_")  # type: ignore[misc]
})
self.environ = dotenv_dict  # type: ignore[assignment]
self.environ.update(dict(os.environ))

when we have the dotenv_dict from file we set self.environ to it and then update with whatever we have in os.environ which means that everything gets replaced back, so my mistake was that I tried to set the dotenv_dict with the interpolated values, then update the whole os.environ object before it gets assigned back to self.environ which seems that broke the test for env files

now I set the interpolation to be done directly on the self.environ object, tell me if the logic is not correct, but now all values get interpolated and set correctly

@p12tic
Copy link
Copy Markdown
Collaborator

p12tic commented Feb 21, 2026

Seems that the PR is still incomplete because 2 lines above we have self.environ = <...>.

Also, it would be great to have integration tests that show in a reproducible way what exactly didn't work before and is now fixed.

Copy link
Copy Markdown
Collaborator

@p12tic p12tic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as "request changes" for myself

@antonpetrov145
Copy link
Copy Markdown
Author

antonpetrov145 commented Feb 23, 2026

@p12tic you mean the lines above what I added right, I left those as they are because

self.environ = dotenv_dict  # here we are creating the self.environ obect

then here

self.environ.update(dict(os.environ))  # we are updating that with what we have in os.environ

and my change just interpolates the variables in the final object so there are no variables like $Abar

self.environ = rec_subs(dotenv_dict, dict(os.environ))

tell me if this logic is not correct, if I move the line above where we have the first assign, we will have the same result as now - variables are not interpolated because they are stored like that in os.environ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants