-
Notifications
You must be signed in to change notification settings - Fork 162
Use Docker with CLion
For performance reasons, we do not recommend you to develop with Docker containers. However, you might run into trouble with unsupported OS versions. Also, some of you might want to avoid installing dependencies on their systems. In these cases, a Docker development setup can make sense.
Currently, we can assure this tutorial works for Linux-based hosts. (e.g. Ubuntu 20.04 w/ Clion 2020.1) Although it should work, we experienced compilation errors when using a macOS host system. In terms of Windows-based hosts, we have not experience yet. So please tell us about your results, if you try it yourself.
CLion offers several remote development capabilities, which can be used to interact with Docker containers. Although running on the same host, the Docker container is treated as a remote instance. CLion controls it using the ssh protocol.
- Create a working directory which to hold the project.
- Clone Hyrise into it using
git clone
. -
cd
into it and usegit submodule update --init --recursive
to fetch the project's dependencies. - Build a Docker image using
docker build . -t hyrise
(in project root) - Run a container from the image using
docker run -itd --cap-add sys_ptrace -p 2222:22 --name hyrise_dev_env hyrise sleep infinity
Now that we have a basic container for compiling Hyrise running (with the name hyrise_dev_env
), we have to set up SSH. Type in the following commands:
docker exec -it hyrise_dev_env mkdir /root/.ssh
docker exec -it hyrise_dev_env bash -c "echo $(cat ~/.ssh/id_rsa.pub) > /root/.ssh/authorized_keys"
docker exec -it hyrise_dev_env service ssh start
Start CLion and import the project from your working directory. In the following steps, we prepare CLion to interact with our Docker container.
- Go to
File | Settings | Build, Execution, Deployment | Toolchains
- Click
+ Add
andRemote Host
- Configure
Credentials
in the right pane (click the little gear icon) and enter the following details:
- Host:
localhost
- Port:
2222
- User name:
root
- Authentication type:
OpenSSH config and authentication agent
- Click
Test connection
to ensure CLion is able to connect to the container. ClickOK
to close theSSH configurations
-dialog. - In the right pane, under CMake, a "Not found" message should show up. In this case, click the button with the three dots to locate the correct CMake binary. In our case it was located at
/cmake-3.16.0/bin/cmake
.
Next, we want to create a CMake profile to use our Docker-toolchain.
- Click
CMake
in the left sidebar of the preferences window. - Create a new profile or change an existing one to use the Remote Host or Docker toolchain we created earlier.
- Add CMake options as required. For example, add
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- Under
Build options
, you may want to add-j <number of cores>
to speed up the compilation process later on. - Close the settings by clicking
OK
CLion should now transfer all the source code into the Docker container using rsync
. Wait for the file transfer and the build files to be written. In the following, you should be able to select the CMake configuration in the toolbar at the top. Choose a build target, like for instance hyriseTest
. Click the hammer icon or use the Build menu to initiate the compile process.
In case the Docker container is stopped (check via docker ps -a
), restart it using
docker start hyrise_dev_env
. You may want to automate the process using a different restart policy.
After restarting your container, you have to restart the SSH service as well. For this, use docker exec -it service ssh start
. Feel free to automate this.
Credits to @ramboldio for bringing up this tutorial with #2081.