Skip to content

Commit e645930

Browse files
authored
Improving dev container documentation (#201)
1 parent 136cd78 commit e645930

7 files changed

+96
-30
lines changed

content/building/using-dev-container.md

+96-30
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,94 @@ We offer the possibility to use such a Dev Container to build any of the support
66

77
## Requirements
88

9-
- **Step 0**: Make sure your have cloned [nf-interpreter](https://github.com/nanoframework/nf-interpreter) nanoFramework directory. The working branch is `main`.
10-
- **Step 1**: Make sure you have [VS Code](https://code.visualstudio.com/Download) installed.
11-
- **Step 2**: Make sure you have [Docker Desktop](https://www.docker.com/products/docker-desktop) installed.
12-
- **Step 3**: Optional but strongly recommended for performance reasons: activate [Windows Subsystem for Linux 2](https://docs.microsoft.com/windows/wsl/install-win10) on your Windows host machine.
9+
- **Step 0**: Install WSL - We strongly recommended for performance reasons: activate [Windows Subsystem for Linux 2](https://learn.microsoft.com/windows/wsl/install) on your Windows host machine.
1310

1411
> note: that may require a reboot
1512
16-
- **Step 4**: Check Docker configuration and make sure you are signed in. In the bellow picture, the top right corner should have you Docker account. If you are not signed in, you'll get an error. And if you're using WSL2 (recommended), the checkbox for the WSL2 support should be checked.
13+
- **Step 1**: We **DO NOT** recommend to have any application like Docker Desktop installed but rather use directly a clean installation of Docker or Podman directly on a WSL Ubuntu Linux instance.
14+
The measure performances between native WSL Docker or Podman and using Docker Desktop are about **50 times faster without** and **with the git project also directly cloned in the WSL instance**.
15+
1. you can install a new version of WSL like the Ubuntu 22.04: `wsl --install Ubuntu-22.04`
16+
1. Create your user and password.
17+
1. Install directly a container engine, let's say the Docker engine, follow the [instructions here](https://docs.docker.com/engine/install/ubuntu/). For an Ubuntu based image:
1718

18-
![Docker steetings](../../images/dev-container-docker.jpg)
19+
```shell
20+
# Add Docker's official GPG key:
21+
sudo apt-get update
22+
sudo apt-get install ca-certificates curl
23+
sudo install -m 0755 -d /etc/apt/keyrings
24+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
25+
sudo chmod a+r /etc/apt/keyrings/docker.asc
1926

20-
- **Step 5**: Make sure you have the [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed.
21-
- **Step 6**: Copy the two template files (in `nf-interpreter\config` folder) `user-tools-repos.TEMPLATE.json` and `user-prefs.TEMPLATE.json` to (new) files named `user-tools-repos.json` and `user-prefs.json`.
22-
Change the content of your "new" `user-tools-repos.json` file as follows:
23-
- Rename the json section `user-tools-repos-container` to `user-tools-repos`.
24-
- **Step 7**: Open the full `nf-interpreter`directory with VS Code.
25-
- **Step 8**: Choose your container.
27+
# Add the repository to Apt sources:
28+
echo \
29+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
30+
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
31+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
32+
sudo apt-get update
33+
```
2634

27-
Go to the file `.devcontainer/devcontainer.json` and choose the container you want. You will find the details in the file itself:
35+
Then make the install and confirm you want to install:
2836

29-
```json
30-
// Adjust this file to chose the platform you want using the prebuild containers
31-
// - Dockerfile.All = you can build anything but it's a very large container
32-
// - Dockerfile.AzureRTOS = for AzureRTOS targets
33-
// - Dockerfile.ChibiOS = for ChibiOS based targets (ex: STM32, Netduino, Orgpal)
34-
// - Dockerfile.ESP32 = for ESP32 targets
35-
// - Dockerfile.TI = for TI targets
36-
// If you prefer, you can use the source files and adjust them they are located, with the same names in ./sources. This will alow you to customize them and add anything you may need on top.
37-
"dockerFile": "Dockerfile.ChibiOS",
38-
```
37+
```shell
38+
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
39+
```
40+
41+
Add your user to the group who can run docker without elevated priviledges:
42+
43+
```shell
44+
sudo usermod -aG docker $USER
45+
```
46+
47+
Exit WSL with `exit`
48+
49+
- **Step 2**: Make sure you have [VS Code](https://code.visualstudio.com/Download) installed.
50+
- **Step 3**: Make sure you have the `DevContainer` extention installed in VS Code: select the extension icon (or File -> Preferences -> Extensions) and search for `DevContainer`. Install the Microsoft one:
51+
52+
![install dev container extention](../../images/building/devcontainer-extension.png)
53+
54+
1. Create a profile in VS Code (File -> Preferences -> Profile -> Create profile), call it for example nanoFramework:
55+
56+
![create profile](../../images/building/nano-profile.png)
57+
58+
1. Adjust DevContainer options: Go to the settings (File -> Preferences -> Settings) and search for container, set the WSL distribution you just prepared (in our example Ubuntu-22.04):
59+
60+
![wsl default istro](../../images/building/devcontainer-wsl-version.png)
61+
62+
Adjust as well the commands to be luanch in WSL and not from Windows:
63+
64+
![execute command in wsl](../../images/building/devcontainer-execute-in-container.png)
65+
66+
- **Step 4**: From the command line, reconnect to WSL (just type `wsl`), go to your home (just do `cd ~`).
67+
- **Step 5**: Make sure your have cloned [nf-interpreter](https://github.com/nanoframework/nf-interpreter) nanoFramework directory. The working branch is `main`.
3968

40-
> Note: as a beginner, we recommend you to use the pre built containers. If you are familiar with containers and need to adjust resources in them, then use the one which you can build yourself. Use the one in the `./sources` subdirectory. So the file name will be for example `./source/Dockerfile.All` to use the container containing everything and build it from the source.
41-
> Error: if you get error message like "Bad CMake executable "". Is it installed or settings contain the correct path (cmake.cmakePath)? The solution: uninstall the CMake and CMake tool from Visual Studio Code and restart Visual Studio Code.
69+
```shell
70+
git clone https://github.com/nanoframework/nf-interpreter.git
71+
```
72+
73+
- **Step 6**: Open the full `nf-interpreter`directory with VS Code. Form your home, in WSL, you can just type `code ./nf-interpreter`
74+
- **Step 7**: Copy the two template files (in `nf-interpreter\config` folder) `user-tools-repos.TEMPLATE.json` and `user-prefs.TEMPLATE.json` to (new) files named `user-tools-repos.json` and `user-prefs.json`.
75+
Change the content of your "new" `user-tools-repos.json` file as follows:
76+
- Rename the json section `user-tools-repos-container` to `user-tools-repos`.
77+
- You will have to close VS Code
78+
- Reopen VS Code from your home `code ./nf-interpreter`
79+
80+
- **Step 8**: Choose your container.
4281

4382
- **Step 9**: Once prompted, open the dev container.
4483

4584
This is illustrating how to do this:
4685

4786
![remote container animation](https://microsoft.github.io/vscode-remote-release/images/remote-containers-readme.gif)
4887

49-
> note: in our case, the dev container is called `nanoFramework`.
88+
> note: in our case, we have multiple DevContainers all starting with `nanoFramework`. Select the one you need!
89+
90+
![list of nano dev containers](../../images/building/containers.png)
5091

5192
If VS Code does not show the prompt, you can press F1 to show all commands. In this list, you can select the item "Remote-Containers: Open Folder in Container..." to open the dev container manually. This option will require you to select the folder through the folder selection dialog.
5293

5394
- **Step 10**: At that point, like in the previous illustration, when clicking on the logs, you should see activities. Be patient. Yes, super patient.
54-
- **Step 11**: We told you to be patient, go for a tea, or a coffee. This part is resource intensive, most of your memory and processor will be used.
55-
- **Step 12**: More patience, yes, all the needed tools and directory are cloned, all the needed settings are cloned as well. This may take a very long time if you have a low bandwidth Internet. See the advance section to understand how you can skip some of the elements if you are only interested in a very specific board.
95+
- **Step 11**: The prebuild container will be downloaded, depending on your internet bandwith, this may take a little bit of time.
96+
- **Step 12**: More patience, yes, all the needed tools and directory are cloned, all the needed settings are cloned as well.
5697
- **Step 13**: It will be over when your VS Code will give you access to the files and will look like this:
5798

5899
![Docker steetings](../../images/dev-container-vscode-ok.jpg)
@@ -69,12 +110,15 @@ To select a new image, just click on the name of the target, the menu will pop u
69110

70111
- **Step 15**: This will actually prepare all what is needed in the `build`folder.
71112

72-
> **Important**: this may take up to 1h or more depending on the target and the performance of your machine. So be patient! While the project will be in preparation, you'll get the small window on the right:
113+
> **Important**: If you did not follow the path of cloning the repository in the WSL instance but rather use a clone in Windows,
114+
this may take up to 1h or more depending on the target and the performance of your machine. So be patient! While the project will be in preparation, you'll get the small window on the right:
73115
74116
![configuration the project](../../images/dev-container-prepare.jpg)
75117
76-
- **Step 16**: did we already told you to be patient? :-) If you still have the little windows from the previous image, be patient! once done, go to the next step.
118+
- **Step 16**: If you are using the recommended configuration and followed the steps, everything should be done in couple of seconds.
77119
- **Step 17**: Hit `F7` this will trigger the build. The build will take some time as well. If all goes right, it will finish with a code 0 with something like: `[build] Build finished with exit code 0`
120+
- **Step 18**: When the build succeed, your build file is located on `~/nf-interpreter/build/nanoCLR.bin`. You can copy it into a Windows folder
121+
(for example `cp ~/nf-interpreter/build/nanoCLR.bin /mnt/c/tmp`). From there, you can use `nanoff` to flash it, see [flashing image section](#flashing-image).
78122
79123
## Tips and tricks
80124
@@ -195,3 +239,25 @@ Example:
195239
```console
196240
nanoff --update --platform esp32 --serialport COM3 --clrfile nanoCLR.bin
197241
```
242+
243+
### Using podman as a container engine
244+
245+
If you are using podman as a container engine, you need to adjust couple of more settings:
246+
247+
![podman settings](../../images/building/podman-settings.png)
248+
249+
In the `devcontainre.json` files, add the following entries:
250+
251+
```json
252+
"runArgs": ["--userns=keep-id"],
253+
"containerUser": "vscode",
254+
```
255+
256+
This is needed for the DevContainer to work as a standard user.
257+
Podman works as a standard user per default compare to Docker which runs as root per default.
258+
259+
### Using Docker Desktop
260+
261+
We **DO NOT** recommand to use Docker Destop as the performances are not good with it. It does create an overlayer that makes all the commands and traffic to go through Windows.
262+
263+
If you still want to use it and are happy to pay a performance price, you need to make sure you uncheck the option "Execute in WSL".

images/building/containers.png

22.4 KB
Loading
Loading
46.5 KB
Loading
36.9 KB
Loading

images/building/nano-profile.png

17.4 KB
Loading

images/building/podman-settings.png

40.9 KB
Loading

0 commit comments

Comments
 (0)