Docker toolchain: Pre-Init script

已完成

I'm experimenting with the new Docker toolchain integration of CLion 2021.3. I have a docker image containing my entire toolchain for a Zephyr RTOS project. The Zephyr build requires that before running C-Make an initial "west update" needs to be done. This is more or less similar to the repo command which initializes various git sub repositories. Without this step the C-Make build can't succeed as sources are missing. This brings me to my question:

How can I tell C-Lion to run a custom command / script within docker before running C-Make?

Please note that I can't execute west update from the host before starting docker as the paths where the repos are initialized are docker image specific paths.

I have some additional questions to better understand how the C-Lion docker toolchain works:

- Which folders are mapped into docker?

- Is there a volume that persists the state of the docker container?

Kind regards,

Michael

0

I'm just starting to wrap my head around Docker Toolchains (I guess we all are), so take this with a grain of salt.

When you create a Docker Toolchain (https://www.jetbrains.com/help/clion/clion-toolchains-in-docker.html#create-docker-toolchain), the Add environment option lets you specify a start-up script that is run every time a container is started. It's not obvious from the docs, but this script can do anything, not just set environment variables. You could put your "west update" in this file. For your situation, it might make more sense to put this in your CMakeLists file; that would make it more portable to other development environments. CMake lets you execute system commands, e.g. https://cmake.org/cmake/help/v3.22/command/execute_process.html

CLion mounts your entire project directory into the container as /tmp/<project_name>, so all of your project state should be stored locally. If you're initializing Git submodules via a startup script running in the container, those changes will be made to your local project repo. I think a new container is spun up for each build or Run Configuration execution, so you shouldn't be trying to save any state in a container.

 

0

Hi Michael Klatt

Thanks very much for pointing me to the "Add Environment" feature which perfectly seems to be the feature I was searching for.

I tried to start west update from this script but there seems to be an access right issue. West update modifies contents from the /opt/ folder within docker (expected) but access to these files is forbidden. I guess C-Lion starts the docker container with a user other than root.

I guess even if I could overcome this issue the lack of caching would be a big nogo for Zephyr. So I would love to see 2 improvements in C-Lions Docker Toolchain integration:

- Possibility to specify which user is executing the docker container and thus preventing access right problems.

- Making it possible to specify some sort of persistence (e.g. a docker volume).

 

0

The user permissions are a known limitation of Docker; see CPP-27415. CLion has to run the container using the UID and GID of the host user, i.e. `docker run --user "$(id -u):$(id -g)" ...` The Docker Toolchain documentation shows how to construct a Dockerfile with the correct user permissions.

I'm looking at fixuid for setting the UID and GID of the container user to match the host user at runtime. I can get it to work using the given instructions if I run a container manually, but not with a CLion toolchain. It appears that CLion overrides the image ENTRYPOINT. The fixuid instructions also have an example of running the command in a start-up script, but I cannot get this to work with CLion either.

0

>Making it possible to specify some sort of persistence (e.g. a docker volume)

Michael Glettig For this please follow https://youtrack.jetbrains.com/issue/CPP-27348, it's in progress right now.

0

请先登录再写评论。