gitpod-io / workspace-images

Ready to use docker images for Gitpod workspaces
https://hub.docker.com/u/gitpod
MIT License
476 stars 322 forks source link

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

Open huweiATgithub opened 2 years ago

huweiATgithub commented 2 years ago

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.

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 commented 2 years ago

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

axonasif commented 2 years ago

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 commented 2 years ago

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

huweiATgithub commented 2 years ago

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

axonasif commented 2 years ago

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