workspace-images icon indicating copy to clipboard operation
workspace-images copied to clipboard

How to configure prebuilds with the python image correctly? (Docs: Tips on using the images)

Open huweiATgithub opened this issue 3 years ago • 5 comments

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__.py file 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 the pip install .?

huweiATgithub avatar Sep 29 '22 01:09 huweiATgithub

I install everything in the init section which works. It may be helpful to document the behavior and tips of these images?

huweiATgithub avatar Sep 29 '22 02:09 huweiATgithub

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.

axonasif avatar Sep 30 '22 14:09 axonasif

And for tips, you can use gitpod/workspace-python image.

axonasif avatar Sep 30 '22 14:09 axonasif

Hi @huweiATgithub, the behaviors you're describing was introduced by this PR: #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.

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."

huweiATgithub avatar Oct 02 '22 18:10 huweiATgithub

Thanks a lot for the feedback and suggesting that, will update it.

axonasif avatar Oct 03 '22 16:10 axonasif