EnigmaCurry / d.rymcg.tech

A collection of self-hosted docker-compose projects with Traefik reverse proxy, integrated auth, and administrative Makefiles for easy maintainance
MIT License
49 stars 8 forks source link

switching contexts while in tmp-context actually switches main context, not tmp-context #248

Closed mcmikemn closed 3 months ago

mcmikemn commented 3 months ago

I'm guessing there's nothing wrong with the code, but I just experienced this and so perhaps there shuld be something in the README alerting to the possibility.

I was in context "maincontext" in one shell and I did d tmp-context in another shell to open context "subcontext01" at the same time. Then in "subcontext01" I did d context and switched to "subcontext02", but the shell I was in remained in "subshell01', and the original shell switched from being in "maincontext" to "subcontext02".

EnigmaCurry commented 3 months ago

This is how docker itself works. DOCKER_CONTEXT env var will supercede the selected context (which is what tmp-context does). But extra documentation would be good.

mcmikemn commented 3 months ago

I realized that after you explained how tmp-context worked. But could we do something like this?

EnigmaCurry commented 3 months ago

We can spit out a Warning:

DOCKER_CONTEXT=blah - changing your context will have no effect right now

But we can't set a new DOCKER_CONTEXT unless we enter another sub-shell (so now you're in a sub-sub-shell), which I think would be too confusing.

So if we only can issue a warning, should we still allow the context to be changed, or should the warning be upgraded to an error and it quits without doing anything?

mcmikemn commented 3 months ago

If we allow users to change the context while in a tmp-context subshell, the context of the original shell will get updated. I think that is confusing and almost certainly not what the user wants to do.

I think we should prevent users from changing the context while in a tmp-context subshell. The message could be something like:

DOCKER_CONTEXT=blah - To change the context in a subshell, exit the subshell (`ctrl-D`) and create a new subshell (`d tmp-context`).
EnigmaCurry commented 3 months ago

Hopefully this message captures everything:

$ d context
DOCKER_CONTEXT=wg-sentry-1
The Docker context cannot be switched because the DOCKER_CONTEXT env var is currently set, and this would override your selection.

You may use `d tmp-context` instead, or try exiting the shell you are in, or unset DOCKER_CONTEXT, and try again. 
Exiting.
EnigmaCurry commented 3 months ago

Implemented in 125ced8 as part of #237

mcmikemn commented 3 months ago

That sounds good.