Skip to content

Commit 55e1148

Browse files
authored
docs: create and run custom container (#146)
Adds documentation on how to run a custom container. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent 66f20a8 commit 55e1148

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Create and Run Custom Container
2+
3+
This guide will walk you through the process of creating and running a custom Ocre container on your board.
4+
5+
We will build the container using ocre-sdk and then use ocre-runtime to deploy it to the board and run it.
6+
7+
## Set up
8+
9+
The [Devcontainer](Devcontainer.md) provides the easiest and most convenient way to set up your development environment.
10+
11+
It is also possible to configure the build environment as described in [Get started with Linux](GetStartedLinux.md) and [Get started with Zephyr](GetStartedZephyr.md).
12+
13+
Make sure you have a working build environment both for WASM (based on Ocre SDK) and for Ocre Runtime.
14+
15+
## Building the container
16+
17+
If you have checked out the `ocre-runtime` repository, `ocre-sdk` is available as a Git submodule in the root. Make sure it is initialized and checked out:
18+
19+
```sh
20+
git submodule update --init ocre-sdk
21+
```
22+
23+
In fact, you might just want to make sure all submodules are initialized and checked out:
24+
25+
```sh
26+
git submodule update --init --recursive
27+
```
28+
29+
Using `ocre-sdk`, we can build a custom container. Please refer to the Ocre SDK documentation for more details.
30+
31+
For this guide, we will just use the `filesystem` sample from ocre-sdk:
32+
33+
```sh
34+
cd ocre-sdk/generic/filesystem
35+
mkdir build
36+
cmake ..
37+
make
38+
```
39+
40+
This should generate the file `filesystem.wasm` in the current directory. We will call this the "container build directory".
41+
42+
## Deployment to the board
43+
44+
There are at least two easy ways of having the container image available for execution on the board.
45+
46+
We can provide it as a preloaded image, which gets flashed with the board firmware (and Ocre runtime), or we can use `ocre image pull` to retrieve from a web server.
47+
48+
These methods are described in the following sections.
49+
50+
### Preloaded images
51+
52+
When we build Ocre Runtime [Supervisor sample](samples/supervisor.md), we can provide extra images to be preloaded in the `merged.hex` binary on supported boards, using the `OCRE_PRELOADED_IMAGES` cmake variable.
53+
54+
For example, when we build the supervisor sample for Zephyr, we can do (from ocre-runtime root):
55+
56+
```sh
57+
west build -p always -b b_u585i_iot02a src/samples/supervisor/zephyr/ -- -DOCRE_PRELOADED_IMAGES=${PWD}/ocre-sdk/generic/filesystem/build/filesystem.wasm
58+
```
59+
60+
Make sure to flash the `merged.hex` to the board, which includes the storage partition:
61+
62+
```sh
63+
west flash --hex-file=build/zephyr/merged.hex
64+
```
65+
66+
For Linux build we can add custom images also, from `ocre-runtime` repository root:
67+
68+
```sh
69+
mkdir build
70+
cd build
71+
cmake .. -DOCRE_PRELOADED_IMAGES=${PWD}/ocre-sdk/generic/filesystem/build/filesystem.wasm
72+
make
73+
```
74+
75+
And this will build the supervisor sample with the custom filesystem container preloaded.
76+
77+
### ocre image pull
78+
79+
If we already have the supervisor running on the board, connected to a network, we can run a web server on the host, and use Ocre to pull the image into the board.
80+
81+
To do this, in the "container build directory" (i.e. the directory which contains `filesystem.wasm`), run:
82+
83+
```sh
84+
python3 -m http.server 8000
85+
```
86+
87+
This will start a web server on port 8000. Please take a moment to make sure there is no firewall blocking the port, and that the server is accessible from the board.
88+
89+
Also, find the server IP in the local network configuration.
90+
91+
Then, on the board, run:
92+
93+
```sh
94+
ocre image pull http://<host-ip>:8000/filesystem.wasm
95+
```
96+
97+
### Running the container
98+
99+
We can check that the image is available on the board by running:
100+
101+
```
102+
ocre image ls
103+
```
104+
105+
And we can start the container. Note that the `filesystem.wasm` sample container from Ocre SDK requires the `filesystem` runtime capability. Make sure you enable any other capabilities your container might require:
106+
107+
```
108+
ocre run -k filesystem filesystem.wasm
109+
```
110+
111+
Check the [Supervisor sample](samples/supervisor.md) documentation for more information.

0 commit comments

Comments
 (0)