How to configure prebuilds with the python image correctly? (Docs: Tips on using the images)
I am configuring a project to have its dependencies set up automatically.
We know that tasks[n].init and tasks[n].before can help with this.
Besides, we know that only those cached in the /workspace folder are preserved.
When I set up python packages with pip (without pipenv or something like that), I thought I should put that in before as pip install into $HOME which is not under /workspace; the stuff in init is executed only once and persisted through /workspace storage.
However, it seems that packages are installed both to a folder under $HOME and the /workspace/.pyenv_mirror folder: e.g.
- which pytest gives me a binary in
$HOME/.pyenv/... python -c "import pytest; print(pytest.__file__)"gives me a__init__.pyfile in/workspace/.pyenv_mirror/...
The mirror sounds like some distribution mirror. I guess such behavior is being configured through: https://github.com/gitpod-io/workspace-images/blob/6b4bf48bebe4db3a9fdf6e6b778244bd88143d84/chunks/lang-python/Dockerfile#L39-L42
What is the suggested way of setting up dependencies in prebuilds to reduce workspace startup time (without creating a Dockerfile)? To be specific, where should I put the
pip install ${dependencies}$? where should I put thepip install .?
I install everything in the init section which works. It may be helpful to document the behavior and tips of these images?
Hi @huweiATgithub, the behaviors you're describing was introduced by this PR: https://github.com/gitpod-io/workspace-images/pull/868
It's essentially a hack to avoid the ah-ha moment of things getting lost outside of /workspace for python CLI commands during prebuild and custom dockerfiles.
As you already explored, it should work if you put the installation commands on init tasks.
And for tips, you can use gitpod/workspace-python image.
Hi @huweiATgithub, the behaviors you're describing was introduced by this PR: #868
It's essentially a hack to avoid the
ah-hamoment of things getting lost outside of/workspacefor python CLI commands during prebuild and custom dockerfiles.As you already explored, it should work if you put the installation commands on
inittasks.
Thank you! That's helpful. I see that it is done by hooking pyenv. It is a great work that makes the image easy to use. It would be better if it is documented somewhere. (It is documented that everything outside /workspace folder is discarded. People like me might consider commands like pyenv global, pip install will not preserve.)
And for tips, you can use gitpod/workspace-python image.
yes. I am using the workspace-full as I also need lang-c. It works well. For tips, I mean something like "You can do pip, pyenv commands directly. They will be preserved."
Thanks a lot for the feedback and suggesting that, will update it.