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

Setting environment variables that depend on other environment variables using extraEnv #1255

Closed
stevenstetzler opened this issue Apr 28, 2019 · 4 comments

Comments

@stevenstetzler
Copy link
Contributor

stevenstetzler commented Apr 28, 2019

Hi. I am trying to set an environment variable like so:

jupyterhub:
  singleuser:
    extraEnv:
      SPARK_PUBLIC_DNS: my.url.com${JUPYTERHUB_SERVICE_PREFIX}proxy/4040/jobs/

The issue is that this will get parsed to the literal string "my.url.com${JUPYTERHUB_SERVICE_PREFIX}proxy/4040/jobs/" instead of evaluating the environment variable.

A further issue is that since both SPARK_PUBLIC_DNS and JUPYTERHUB_SERVICE_PREFIX are set only on container creation, there doesn't seem to be a way to set an environment variable that requires e.g. JUPYTERHUB_SERVICE_PREFIX before the container is started. I have worked around this by altering my single-user container's Entrypoint script to set SPARK_PUBLIC_DNS, but this feels like an inelegant solution given the option to set extra environment variables directly in the config.yaml. Is there any other way I could go about doing this?

I could also imagine that a situation where I pass a list of environment variables that all depend on one another to extraEnv, none that depend on environment variables that are only set on container creation. For example,

jupyterhub:
  singleuser:
    extraEnv:
      - A: "env_1"
      - B: "env_2_${A}"
      - C: "env_3_${B}_${A}"

or something like that. Here, environment variables B and C won't be set correctly, but it would be reasonable to imagine that they would be since A precedes both B and C and B precedes C in definition. Is this functionality possible?

@consideRatio
Copy link
Member

If you need to evaluate other env vars while setting these, they must be set after container startup from within the container, but before the jupyter server starts etc, i think.

It doesnt work now because kubernetes is configured to start a container with these variables, and kubernetes doesnt know of various env vars in the container on startup.

If look into modifying singleuser.cmd, add an extra volume and volumemount, with a script referenced by singleuser.cmd, to first load additional vars, and then start the previous command.

Prepare for some tough debugging sessions ahead, but that is the way i see this done atm.

@stevenstetzler
Copy link
Contributor Author

Thanks for the help. I can't find singleuser.cmd in the z2jh configuration reference. Are you able to provide additional details about what I would do here? Is changing singleuser.cmd different from providing a different Entrypoint script for the single user image?

@consideRatio
Copy link
Member

It will configure kubespawner within images/hub/jupyterhub_config.py, and kubespawner will then use that to configure the kubernetes pod spec, that will in turn configure the Docker container with certain things to do when it starts up.

I'm unable to provide much further help to solve this as I'm out of time to do so overall =/ It is a spare time thing for me to contribute to this repo. Good luck!

@stevenstetzler
Copy link
Contributor Author

Currently, I am setting these environment variables in an entrypoint script (what is run on container start up before calling the command jupyterhub-singleuser). When altering singleuser.cmd as suggested, I ran into issues executing jupyterhub-singleuser with its original arguments. Thanks for the help!

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

2 participants