Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python init prebuild not working #7078

Closed
quental96 opened this issue Dec 6, 2021 · 4 comments
Closed

Python init prebuild not working #7078

quental96 opened this issue Dec 6, 2021 · 4 comments

Comments

@quental96
Copy link

Bug description

Hello,

Prebuilds in python are not working at all for me, and I am following exactly what the docs advise. My problem is even reproducible in the official gitpod pandas example.

The prebuild looks like this:

tasks:
   - init: pip3 install -r requirements.txt
     command: python3 src/app.py

When I launch any type of workspace that has this sort of prebuild for the first time, it seems to work. However, the second time that I launch it, the init has not been saved; what this means here is that the python packages are not present and the command fails because of import errors.

I have been struggling with this for a couple days now and I found other inconsistencies with the docs. Namely, My pyenv is never saved. This is impossible to work with because I have to reinstall everything each time I reopen a workspace…

Thanks for your quick help, I can’t do any Gitpod work while this is not fixed…

Quentin

Steps to reproduce

  • Launch the example cited above.
  • Wait for init and command.
  • Close workspace.
  • Reopen workspace.

Workspace affected

ivory-cardinal-kxl6nm71

Expected behavior

Workspace should be saved.

Example repository

https://github.com/gitpod-io/Gitpod-Pandas

Anything else?

No response

@quental96
Copy link
Author

Similar to this.

@tiamot
Copy link

tiamot commented Dec 18, 2021

Also Similar to #7110
I also have the same issue.

@tiamot
Copy link

tiamot commented Dec 18, 2021

Here is the fix (thank you @lechien73, see: #7064 (comment)):

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. 👍🏼

@pawlean
Copy link
Contributor

pawlean commented Jan 4, 2022

Thank you @tiamot @quental96 for sharing this. I'll make sure this is reflected in the docs as well. Appreciate the effort, let me know if you are having any more issues 🙏🏼 Can you close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants