Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iox #15 add docker environment #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ This build method makes the most sense in combination with [rmw_iceoryx](https:/

Congrats! You've build all the necessary things to continue playing around with the examples.

##### Build and run in a Docker environment

If you want to avoid installing anything on your host machine but you have Docker installed, it is possible to use it to build and run iceoryx applications.

Please see the dedicated [README.md](tools/docker/README.md) for information on how to do this.

## Examples

Great that you're still here, time for code! The following examples give you a quick and easy introduction into the inner
Expand Down
1 change: 1 addition & 0 deletions tools/docker/.screenrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shell "/usr/bin/fish"
34 changes: 34 additions & 0 deletions tools/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2019 by Cornel Izbasa. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is you @Mr-Slippery? I need to confirm that we have the approval from the Author to use this codesnippet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dkroenke, yes, it's just my Github username. :) The Eclipse account linked to this Github username has my real name, Cornel Izbasa. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you maybe located in Berlin? I found a LinkedIn Profile which says that you are in Tempelhof.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I work at HELLA in Tempelhof, but live in North-East of Berlin :)

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ubuntu:bionic
ARG REVISION
ARG B_ICEORYX_BUILD
ENV ICEORYX_BUILD=$B_ICEORYX_BUILD

RUN apt update && apt install -y \
cmake \
libacl1-dev \
libncurses5-dev \
pkg-config \
screen \
fish \
git

ADD . /iceoryx

WORKDIR /iceoryx

RUN ./tools/iceoryx_build_test.sh \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your original version (https://github.com/Mr-Slippery/iceoryx-dockerfiles/blob/master/Dockerfile) you were cloning iceoryx before executing this script. How is the script coming in the docker container?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mossmaurice, indeed, initially I was cloning, but for this "integrated version", I thought it makes sense to build and include into the container the current source that is cloned. This makes it into the container via ADD . / in the Dockerfile.

Copy link
Contributor Author

@Mr-Slippery Mr-Slippery Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now that you mention it, there is perhaps an issue here, maybe some unintended things make it inside as well, I'll check and fix this. In my case the source was in an otherwise empty dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated now, indeed, there was an issue, I was going to the parent of top-level iceoryx and adding everything into Docker /. Now I just go to iceoryx and add its content into Docker /iceoryx. Rebased branch, melded changes into existing commit. Thanks for the catch!

&& cp ./tools/docker/.screenrc /root
222 changes: 222 additions & 0 deletions tools/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# Overview

This directory contains files related to building and running [Eclipse iceoryx](https://github.com/eclipse/iceoryx) using [Docker](https://www.docker.com/).

# Building the Docker image and running the container

To create and run a Docker image with a built iceoryx library and examples from your current sources, from the top-level iceoryx repo, run: `./tools/docker/build_and_run.sh`. Or you can navigate to `./tools/docker` and then run `./build_and_run.sh`, per your preference.

For the rest of this text, for brevity, we assume `./tools/docker` is the current directory.

Expected output of `./build_and_run.sh` looks like:

```
Sending build context to Docker daemon 3.352MB
Step 1/8 : FROM ubuntu:bionic
---> 4c108a37151f
Step 2/8 : ARG REVISION
---> Using cache
---> a398e6040568
Step 3/8 : ARG B_ICEORYX_BUILD
---> Using cache
---> 6adec4590084
Step 4/8 : ENV ICEORYX_BUILD=$B_ICEORYX_BUILD
---> Using cache
---> c0ff19e371ca
Step 5/8 : RUN apt update && apt install -y cmake libacl1-dev libncurses5-dev pkg-config screen git
---> Using cache
---> 6c0d2d84c2f9
Step 6/8 : ADD . /
---> 65602097702b
Step 7/8 : WORKDIR /iceoryx
---> Running in 61ce7c4b3718
Removing intermediate container 61ce7c4b3718
---> 987569d9f854
Step 8/8 : RUN ./tools/iceoryx_build_test.sh && cp ./tools/docker/.screenrc /root
---> Running in 28767c2c7c9f
[i] Create a new build directory and change the current working directory
[i] Current working directory:
/iceoryx/build
>>>>>> Start building iceoryx utils package <<<<<<
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
...
[100%] Linking CXX executable icedelivery/ice_receiver_simple
[100%] Built target ice_receiver_simple
>>>>>> finished building iceoryx examples <<<<<<
Removing intermediate container 28767c2c7c9f
---> ab28011a1a6b
Successfully built ab28011a1a6b
Successfully tagged iceoryx:master
```

After the Docker image is built and tagged, a corresponding container is launched, and you are dropped in a shell inside the `iceoryx` directory containing the library source and binaries.

# Launching the RouDi daemon and example applications inside the container

The next step is to launch the RouDi daemon to enable communication and run example communicating applications.

## Using `docker exec`

After using `./build_and_run.sh`, you can launch the RouDi daemon in the provided shell:

```
$ ./build_and_run.sh
...
root@03043f96ae10:/iceoryx# ./build/install/prefix/bin/RouDi
Reserving 95306080 bytes in the shared memory [/iceoryx_mgmt]
[ Reserving shared memory successful ]
Reserving 595259200 bytes in the shared memory [/root]
[ Reserving shared memory successful ]
```

then, in a new terminal, issue `docker ps` to see running containers:

```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
03043f96ae10 iceoryx:current "/bin/bash" About a minute ago Up About a minute roudi
```

and start the sender application:

```
badc0ded@localhost:~$ docker exec -it roudi /bin/bash
root@03043f96ae10:/iceoryx# ./build/iceoryx_examples/icedelivery/ice_sender
Sending: 0
Sending: 1
Sending: 2
Sending: 3
```

and in another terminal, start the receiver application:

```
$ docker exec -it roudi /bin/bash
root@03043f96ae10:/iceoryx# ./build/iceoryx_examples/icedelivery/ice_receiver
Not subscribed
Receiving: 78
Receiving: 79
Receiving: 80
Receiving: 81
```

## Using `screen` to launch RouDi and examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great chapter!


Another way of interacting with the daemon and examples is to use [screen](https://www.gnu.org/software/screen/) (also included in the Docker image) to start executables in different virtual screens that you attach to and detach from as your experiments may require.

This may be a better option if you are working on a remote machine and don't want to have to open multiple connections to it in separate terminals and/or if you're comfortable with using `screen`.

To prepare a virtual screen in which we'll launch the RouDi daemon, enter:

```
$ ./build_and_run.sh
...
root@03043f96ae10:/iceoryx# screen
```

and press `[Enter]`.

Inside the virtual screen shell, you can then launch the RouDi daemon as follows:

```
root@3b93f0d3eda2:/iceoryx# ./build/install/prefix/bin/RouDi
Reserving 95306080 bytes in the shared memory [/iceoryx_mgmt]
[ Reserving shared memory successful ]
Reserving 595259200 bytes in the shared memory [/root]
[ Reserving shared memory successful ]
```

and then press `[Ctrl]+A D` to detach from the virtual screen.

You should a see a message like this:
```
[detached from 16.pts-0.3b93f0d3eda2]
```

To launch an example sender application, start a new virtual screen and run the corresponding binary:

```
root@3b93f0d3eda2:/iceoryx# screen
#[Enter]
root@3b93f0d3eda2:/iceoryx# ./build/iceoryx_examples/icedelivery/ice_sender
Sending: 0
Sending: 1
Sending: 2
Sending: 3
Sending: 4
...
```

As above, press `[Ctrl]+A D` to detach from this virtual screen.

Then the receiver application can be started, again in a separate virtual screen:

```
root@3b93f0d3eda2:/iceoryx# screen
#[Enter]
root@3b93f0d3eda2:/iceoryx# ./build/iceoryx_examples/icedelivery/ice_receiver
Not subscribed
Receiving: 12
Receiving: 13
Receiving: 14
Receiving: 15
...
```

You can now detach from this virtual screen with `[Ctrl]+A D`, and, as an exercise, list all screens and return to the one with the sender.

```
root@d3e51ca29d56:/iceoryx# screen -r
There are several suitable screens on:
66.pts-0.d3e51ca29d56 (12/06/19 08:55:00) (Detached)
35.pts-0.d3e51ca29d56 (12/06/19 08:54:48) (Detached)
17.pts-0.d3e51ca29d56 (12/06/19 08:53:57) (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
```

Try the following to return to the sender application (adjust the PID as per your exact `screen -r` output above):

```
screen -r 35
```

You should see again the virtual screen of the sender application:

```
Sending: 212
Sending: 213
Sending: 214
Sending: 215
Sending: 216
...
```

You can stop the sender with `[Ctrl]+C`, and then detach from this screen with `[Ctrl]+A D`, and return to the receiver screen with (adjusting the PID as per your `screen -r` output above):

```
screen -r 66
```

and you should see current receiver output such as:

```
Not subscribed
Not subscribed
Not subscribed
Not subscribed
Not subscribed
...
```

As an exercise, try return to the sender screen and relaunch the sender, then detach from the sender screen and attach to the receiver screen and see the output based on the new sender:

```
Receiving: 103
Receiving: 104
Receiving: 105
Receiving: 106
Receiving: 107
...
```
32 changes: 32 additions & 0 deletions tools/docker/build_and_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Copyright (c) 2019 by Cornel Izbasa. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

REVISION="current"
IMAGE_NAME="iceoryx:${REVISION}"
CONTAINER_NAME=roudi
ICEORYX_BUILD=/iceoryx/build
DOCKERFILE_DIR="$(dirname "$(readlink -fm "$0")")"
ICEORYX_SRC="$(dirname "$(dirname "${DOCKERFILE_DIR}")")"
LAUNCH_FLAGS=(\
-it \
--rm \
--shm-size 700M \
)

cd "${ICEORYX_SRC}"
docker build -f "${DOCKERFILE_DIR}/Dockerfile" --build-arg B_ICEORYX_BUILD="${ICEORYX_BUILD}" --build-arg REVISION="${REVISION}" . -t "${IMAGE_NAME}"
docker run "${LAUNCH_FLAGS[@]}" --name="${CONTAINER_NAME}" "${IMAGE_NAME}"