Gitpod: cannot set environment variables: invalid request: 500

Created on 17 Jul 2020  路  4Comments  路  Source: gitpod-io/gitpod

.gitpod.yml:

tasks:
    - init: gp env -e PATH="/usr/local/cargo/bin:$PATH" && eval $(gp env -e) && /workspace/rustlings/install.sh
    - command: eval $(gp env -e) && /workspace/.cargo/bin/rustlings watch
image:
    file: .gitpod.Dockerfile

vscode:
  extensions:
    - [email protected]:CvNqMTgDdt3UXt+6BCDTVg==

.gitpod.Dockerfile:

FROM rust

ENV export PATH="/usr/local/cargo/bin:$PATH"

Repo:
https://github.com/ryanpcmcquen/rustlings/tree/add-gitpod-support

question

All 4 comments

My end goal here is just to modify the PATH, and I've tried a lot of things, but nothing seems to be working.

Hello @ryanpcmcquen!

There are some pitfalls in the initial Gitpod setup. There are some things to know. I'm happy to help you out.

  1. Is there any good reason that you use your own Docker image based on rust instead of using our default workspace image? It has rust installed already:

https://github.com/gitpod-io/workspace-images/blob/1ed69ba76d99485b8dab7900dc03d1a8e240398d/full/Dockerfile#L244-L273

Please find at https://github.com/corneliusludmann/rustlings/tree/gitpod-test a working example with our image.

https://gitpod.io/#https://github.com/corneliusludmann/rustlings/tree/gitpod-test


If there is a good reason for building your own image, here are some hints that you need to know:

  1. The usage of gp does not work well in init. The init command could be running as prebuild or when the workspace is not fully started. Then, the gp service is not there yet. The best way to change the PATH variable is by adding it to .bashrc, IMO. You can do this in your .gitpod.Dockerfile like this:
# See https://github.com/gitpod-io/workspace-images/blob/1ed69ba76d99485b8dab7900dc03d1a8e240398d/full/Dockerfile#L35-L37
RUN useradd -l -u 33333 -G sudo -md /home/gitpod -s /bin/bash -p gitpod gitpod
USER gitpod

RUN echo 'export PATH="/usr/local/cargo/bin:$PATH"' >> /home/gitpod/.bashrc
  1. Everything that you modify in the /workspaces folder in your Dockerfile will be overwritten by the Git repo contents and it lost. Everything that you modify outside of the /workspace folder (e.g. the home folder) in your .gitpod.yml is be lost after a workspace restart. That also means that changes of an init command during a prebuild outside of /workspace is lost. As a general rule of thumb:
    > Never change something in /workspace in your Dockerfile and never change something outside of /workspace in your .gitpod.yml tasks.

That could be challenging when tools store data in the home folder. Therefore we change some folders in our workspace image. So: If possible, take our base image instead.

  1. Something like this in your .gitpod.yaml:
tasks:
    - init: /workspace/rustlings/install.sh
    - command: /workspace/.cargo/bin/rustlings watch

leads to two separate terminals in parallel. If the second command relies on the first one you need to write it like this:

tasks:
    - init: /workspace/rustlings/install.sh
      command: /workspace/.cargo/bin/rustlings watch

(Be aware of the second - that is missing.)

--

I hope this helps you.

Wow, @corneliusludmann, thank you so much for the fix and the very thorough explanation, I've bookmarked this page because that is very helpful data.

I'm only having one issue, it appears the watch command isn't noticing filesystem changes:
Screen Shot 2020-07-20 at 10 45 13 AM

@corneliusludmann, it appears I was linked to an old container, after destroying that, everything is working perfectly!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ColbyWTaylor picture ColbyWTaylor  路  3Comments

Kreyren picture Kreyren  路  3Comments

akosyakov picture akosyakov  路  3Comments

LezaiNiubi picture LezaiNiubi  路  3Comments

LinqLover picture LinqLover  路  3Comments