I'm new to Dagger, so sorry in advance. Is there some way in the API to do with_env? As in, I am using with_exec to do the steps I would normally use Dockerfile RUN for, and now I wish to do the Dockerfile ENV equivalent, but there is no with_env API. Specific use case is that I am setting up Python virtual environment as a cache volume, and then I want to set my PATH=/path/to/venv:$PATH but I don't see a way. I have the venv caching working and for subsequent calls to python I am using /src/venv/bin/[python,pip] and it's working great. I just feel like I am missing something and I can't find any examples. Thanks
#Dockerfile ENV availability
1 messages ยท Page 1 of 1 (latest)
for some context I am just translating this guide (which is great btw) into python venv rather than node_modules https://docs.dagger.io/635927/quickstart-caching
๐ @fluid vortex. I think this is what you're looking for: https://dagger-io.readthedocs.io/en/sdk-python-v0.5.0/api.html#dagger.api.gen.Container.with_env_variable
Hey @fluid vortex, there's an example of that in #1083752578032095263 message
@blazing tundra thanks that is what I needed
@chrome python and thank you, I tried with_env_variable("PATH", "/somepath:$PATH") which I knew wouldn't work when I typed it but tried anyway ๐
you already answered the follow-up thanks
How are you activating the venv if I may ask? ๐
i didn't, if you use the path to the python which is in a venv then magic happens (at least it has always worked for every case I've had)
Yep, that's right. I like to also set VIRTUAL_ENV. Poetry for example detects that automatically.
i'm sure this is wrong, but works. if you have a hint I would gladly activate it properly
No, not wrong. This is how we're doing it in our CI: https://github.com/dagger/dagger/blob/a04e61f797628fad0e471e0644b551f96053cfc0/internal/mage/sdk/python.go#L194-L196
Explanation here: https://pythonspeed.com/articles/activate-virtualenv-dockerfile/
excellent, thanks for the assistance
@chrome python yes perfect, now I have unmangled my path. i was trying with path=container.env_variable(PATH) and then with_env_variable(f"{venv}/bin:{path}") but that was not working as expected
you just set a fixed path in your ci, which is fine for me
seems like what I was trying should work but maybe I just messed it up
It should work ๐ Maybe you're missing something. Can you share?
I will try it again and get it in a sharable state if it's still not working
Cool ๐
@chrome python ok, i was messing it up. path = AWAIT container.env_variable...
path was a coroutine, not a string
Yep, that's right ๐
thanks muchly ๐