Python packages not persisting between workspace restarts
Bug description
Packages installed with Pip are not persisting between workspace restarts.
Steps to reproduce
Open the following in gitpod: https://github.com/kevin-ci/gitpod-bug-demo
Use pip3 install -r requirements.txt to install the requirements. Then run pip3 freeze to ensure they're installed.
Manually stop and restart the workspace. When it restarts, run pip3 freeze again. The installed packages (Django in this case) will be gone. A bunch of default packages will still be present.
Workspace affected
No response
Expected behavior
The packages persist between restarts, as they used to.
Example repository
No response
Anything else?
This seems to be related to an issue I raised the other day: https://github.com/gitpod-io/gitpod/issues/7064
Thanks @quental96 - please also link https://github.com/gitpod-io/gitpod/issues/7064 to the discussion due to the bloatware libraries that are now installed.
As of now, Gitpod only persists the /workspace folder between sessions. You might want to install the packages using a custom dockerfile or teach pip3 to use a subdir under /workspaces (https://stackoverflow.com/questions/2915471/install-a-python-package-into-a-different-directory-using-pip)
As of now, Gitpod only persists the /workspace folder between sessions.
Is this new behaviour? @JanKoehnlein
Pip modules always used to be stored under the /workspace directory. Could you offer some feedback as to the huge amount of superfluous Python libraries that are now installed by default too? If this is the new default behaviour, then it seems that the only option for us is to teach students how to use virtual environments, in which case, we may as well just teach them VSCode locally.
@JanKoehnlein I really don't understand the reasoning behind these changes, or apathy shown in this thread.
The Gitpod homepage says:
Spin up fresh, automated dev environments for each task, in the cloud, in seconds.
The workspaces can hardly be called fresh if they're now bloated with so many packages that it breaks Heroku deployments, and the lack of package persistence between restarts has now made Gitpod objectively worse than Codespaces, its main competitor. I don't see how you can brush this off as "this is how it works" when even the sample prebuilds provided are no longer working: https://github.com/gitpod-io/gitpod/issues/7078
Sorry for the late reply. The persistence of the workspace folder only has always been this way. I suspect something has changed in the setup of the workspace-full image such that python packages are no longer persisted there.
/cc @ghuntley could you try to find out what's going wrong here?
You should be able to work around this by switching to an earlier workspace image in your .gitpod.yml file
image: gitpod/workspace-full:<tag>
See https://hub.docker.com/r/gitpod/workspace-full/tags for tags.
Thanks @JanKoehnlein - this seems to half work. I used one of the previous commits (commit-8fc141dbdd92030a435ead06617c6d37651d8312) and the build worked fine with none of the bloat; however, on stopping and restarting the workspace, the bloatware appears again. I'm going to try with an older commit and see what happens.
The issue most likely lies with this commit https://github.com/gitpod-io/workspace-images/commit/507a50aeb98b86396d8d3b705e1ed651ed0af6fe
Removing PIP_USER=yes makes PYTHONUSERBASE=/workspace/.pip-modules ineffective by installing all packages under /home/gitpod/.pyenv/.... which is not persistent between WS restarts.
Can probably merge this with the discussion here: https://github.com/gitpod-io/gitpod/issues/7064
@lechien73, I think this is a different issue from 7064. Issue 7064 is focused on removing unwanted packages that are installed in the workspace-full image (removing bloat).
I think the issue described by @kevin-ci is more focused on packages being installed in one workspace, and then not persisting to another.
I have a similar problem as the op. My issue is when I setup my environment to have init do pip installs, those installed packages work fine until I attempt to use pre-builds. Once I turn on prebuild for a repo things stop working.
To recreate:
- create a new repo in gitlab
- launch gitpod from repo
- gp init
- Set init: pip install
- turn on prebuild
- launch a new gitpod and run pip freeze (package installed by init is not in the workspace)
Similar to https://github.com/gitpod-io/gitpod/issues/7110
Here is the fix (thank you @lechien73, see: https://github.com/gitpod-io/gitpod/issues/7064#issuecomment-988049050):
Problem & Solution Walkthrough
- Create a new repo (e.g.
test-for-prebuild) in gitlab with a readme (or github or bitbucket, etc) - Launch gitpod
- Initialize gitpod with
gp init - Edit .gitpod.yml
tasks:
- init: pip install pip_install_test
- Commit your changes and sync
The library is installed in new workspaces
- Manually stop the workspace and restart it
- From the terminal:
gitpod /workspace/test-for-prebuild $ pip freeze | grep pip-install-test
pip-install-test==0.5
We can see from the pip freeze, that the library pip-install-test is indeed available in this new workspace. 👍🏼
Turning on prebuild breaks something
- Manually stop the workspace
- Launch a prebuild by prefixing the repo path with
gitpod.io/#prebuild/ - From the terminal:
gitpod /workspace/test-for-prebuild $ pip freeze | grep pip-install-test
We can see from the pip freeze, that the library pip-install-test is not available in this workspace. 👎🏼
Fix the problem with a custom docker image
By default gitpod uses the gitpod/workspace-full docker image, so for this example I will use that image as the base, but you can use any image you like.
- Manually stop the workspace and restart it
- Edit .gitpod.yml add these lines to the top
Image:
file: .gitpod.Dockerfile
- Create the file .gitpod.Dockerfile
FROM gitpod/workspace-full
ENV PYTHONUSERBASE=/workspace/.pip-modules
ENV PATH=$PYTHONUSERBASE/bin:$PATH
ENV PIP_USER=yes
- Commit your changes and sync
Final Test
- Manually stop the workspace and restart it
- From the terminal:
gitpod /workspace/test-for-prebuild $ pip freeze | grep pip-install-test
pip-install-test==0.5
We can see from the pip freeze, that the library pip-install-test is indeed available in this new workspace. 👍🏼
Thank you for sharing that @tiamot. 🙏
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.