menu
Channels
Team

How do I commit the user's Theia preferences to Docker?

March 4, 2020 at 6:14pm

How do I commit the user's Theia preferences to Docker?

March 4, 2020 at 6:14pm
One user comes in to configure the Theia UI, changing preferences, adding panels, etc. I want that state to be saved in the Docker image so the next user to start a container from that image would see the same set of panels.
Is this possible? How would you recommend doing it?

March 4, 2020 at 6:51pm
{HOME}/.theia in your docker would be having those settings saved in settings.json if I am not mistaken ... You can cross-check that and share it across. You can also create an image (not recommended) from the container you have right now using commit; but please make sure there is no private data inside the container like your SSH keys etc.
Edited
like-fill
2
  • reply
  • like
{HOME}/.theia in your docker would be having those settings saved in settings.json if I am not mistaken ... You can cross-check that and share it across. You can also create an image (not recommended) from the container you have right now using commit; but please make sure there is no private data inside the container like your SSH keys etc.
Thanks, !
  • reply
  • like
One thing to consider: some of what you may wish to save is not persisted in the container as such. For example the IDE workbench layout, including currently opened editors, is saved in the client's local web storage (i.e. the browser used to access the Theia backend running in the container).
  • reply
  • like

March 6, 2020 at 1:17am
When I destroy and recreate the docker container (nightly build), the local web cache is reset* and everything re-initialises. I did use a volume for ~/.theia but it's always empty. Is this a bug (or a feature :) )?
*Steps:
  • Launch container
  • Change theme
  • Destroy container
  • Launch again
  • Refresh the web page: theme gone
Is it possible to preserve the settings by using a docker volume or some configuration flag?
Edited
  • reply
  • like

March 6, 2020 at 2:12pm
Hi . One pitfall to using docker volumes is that the user on the host generally will not match the user in the container, which often causes permission issues. That might explain the result you get above. Another thing: depending on which Theia image you're using, the default user in the container might be "theia" or "root", so you would need to mount the docker volume under the correct user's home.
Edited
like-fill
1
  • reply
  • like
I gave this a try and it seemed to work for me:
$> mkdir /tmp/.theia
$> chmod 777 /tmp/.theia
$> docker run -it -p 3000:3000 -v "/tmp/.theia:/home/theia/.theia" theiaide/theia:latest
Access the Theia app with my browser (localhost:3000) and swithed to theme "red". Kill the docker container and close browser tab, start a new container and connect to it in a new tab
Result: Theme "red" is used.
like-fill
1
  • reply
  • like
Thank you very much! 🍻 With your example, I realised my mistake: I was using the wrong path in the volume mount :| (/home/.theia instead of /home/theia/.theia)
like-fill
1
  • reply
  • like

July 6, 2020 at 3:34pm
Does the approach you shared above still work in v1.0 of Theia?
  • reply
  • like
Yes, I think it should.
  • reply
  • like
We're trying to save the user's state such as which files are open, which panes are open, which extensions are installed (in particular the Preview extension)
  • reply
  • like
Are you suggesting that these should be captured in the user's home directory? /home/theia/.theia?
  • reply
  • like
no, at least not without modifications. Some of these things are not saved in the .theia folder.
The following things are saved in the browser's local storage, upon closing a Theia browser tab:
  • workbench layout. including panels content, opened editors and widgets' states
For performance reasons we do not save/restore some things. The Problem Markers come to mind. They should be re-created automatically though.
For more information, look in your browser's dev tools under the Application tab. On the left, look for "Local Storage". Under that, you should have an entry for each origin that has content saved. For a given selected entry, you'll have a series of key-value pairs. The workspace URI is used as a secondary key, so each workspace has its own storage.
  • reply
  • like
How do we snapshot the things in the browser's local storage so that those config settings can be loaded when a new user launches a Theia session?
  • reply
  • like
  • reply
  • like
This is what we're seeing in the local browser storage.
  • reply
  • like
the black boxes are to obfuscate the IP address of the server we're testing this on
  • reply
  • like
we want what's appearing on right to be the default, not what's happening on the left.
  • reply
  • like
So you would like to provide a default workbench state, that would replace the current default (on the left)?
AFAIK it would not be possible to pre-populate the browser's local storage for the user.
An alternate approach that I have seen is at the workspace server level - In Gitpod, one could do similar to the right screenshot by adding "gp open" commands in the repo's Gitpod config.
  • reply
  • like

July 7, 2020 at 2:09pm
We're not using Gitpod but instead our own solution for launching Theia containers. If we can't pre-populate the browser's local storage, is there a way to set an initiate state using Theia extensions?
  • reply
  • like
You should implement the custom extension and do required customizations in FrontendApplicationContirbution.intitializeLayout lifecycle callback to set the initial state.
  • reply
  • like