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

adding IBEJI_HOME env var for loading the invehicle digital twin config file #61

Merged
merged 8 commits into from
Oct 30, 2023
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
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Install Rust](#install-rust)
- [Install Protobuf Compiler](#install-protobuf-compiler)
- [Install SDL2 library](#install-sdl2-library)
- [Install dotnet-sdk library](#install-dotnet-sdk-library)
- [Install MQTT Broker](#install-mqtt-broker)
- [Cloning the Repo](#cloning-the-repo)
- [Building](#building)
Expand All @@ -18,6 +19,10 @@
- [Seat Massager Sample](#seat-massager-sample)
- [Streaming Sample](#streaming-sample)
- [Using Chariott](#using-chariott)
- [Running in a Container](#running-in-a-container)
- [Dockerfile](#dockerfile)
- [Docker](#docker)
- [Podman](#podman)
- [Trademarks](#trademarks)

## <a name="introduction">Introduction</a>
Expand All @@ -35,6 +40,10 @@ the nature of the capability, how to work with it and how it can be remotely acc

## <a name="prerequisites">Prerequisites</a>

We recommend the use of Ubuntu 22.04 for running the In-Vehicle Digital Twin Service. Other
operating systems or versions of Ubuntu may encounter issues. We invite others to help us find and
resolve any compatibility issues.

### <a name="install-gcc">Install gcc</a>

Rust needs gcc's linker, so you will need to install it. To install gcc, do the following:
Expand Down Expand Up @@ -72,6 +81,14 @@ You will need to install the libsdl2-dev library. This can be done by executing:
sudo apt install -y libsdl2-dev
```

### <a name="install-dotnet-sdk-library">Install dotnet-sdk library</a>

You will need to install dotnet-sdk for the dtdl-tools crate. This can be done by executing:

```shell
sudo apt install -y dotnet-sdk-7.0
```

### <a name="install-mqtt-broker">Install MQTT Broker</a>

If you plan to run any of the samples that use MQTT, then you will need to install a MQTT Broker, like [Mosquitto](https://github.com/eclipse/mosquitto).
Expand Down Expand Up @@ -110,6 +127,16 @@ The demos use config files and we have provided a templated version of each conf
- {repo-root-dir}/core/invehicle-digital-twin/template
- {repo-root-dir}/samples/common/template

Configuration files will be loaded from the current working directory by default
but an `IBEJI_HOME` environment variable can be used to change the base configuration directory to a different one:

```bash
IBEJI_HOME=/etc/ibeji ./invehicle-digital-twin
```

The above example tells `invehicle-digital-twin` to load configuration files from `/etc/ibeji` instead of using
the current working directory.

Chariott may be used to discover the in-vehicle digital twin service. We will discuss how to enable this feature.

### <a name="property-sample">Property Sample</a>
Expand Down Expand Up @@ -270,6 +297,85 @@ rather than having it statically provided in their respective config file, then
`chariott_uri: "http://0.0.0.0:50000"`<br>
1. In the consumer's config file and the provider's config file, remove the setting for invehicle_digital_twin_uri, so that the chariott_uri will be used to find the In-vehicle Digital Twin URI.<br>

## <a name="running-in-a-container">Running in a Container</a>

Below are the steps for running the service in a container. Note that the configuration files used
by the containerized service are cloned from [container/config](./container/config/) defined in the
project's root.

### <a name="dockerfile">Dockerfile</a>

There are currently two dockerfiles provided in the root directory of the project that can be built:

- Dockerfile - A standalone version of the In-Vehicle Digital Twin Service
- Dockerfile.integrated - A version of the In-Vehicle Digital Twin Service that communicates with
the [Chariott Service](https://github.com/eclipse-chariott/chariott) and the
[Agemo Service](https://github.com/eclipse-chariott/Agemo).

### <a name="docker">Docker</a>

<b>Prerequisites</b>

[Install Docker](https://docs.docker.com/engine/install/)

<b>Running in Docker</b>

To run the service in a Docker container:

1. Run the following command in the project's root directory to build the docker container from the
Dockerfile:

```shell
docker build -t invehicle_digital_twin -f Dockerfile .
```

1. Once the container has been built, start the container in interactive mode with the following
command in the project's root directory:

```shell
docker run --name invehicle_digital_twin -p 5010:5010 --env-file=./container/config/docker.env --add-host=host.docker.internal:host-gateway -it --rm invehicle_digital_twin
```

1. To detach from the container, enter:

<kbd>Ctrl</kbd> + <kbd>p</kbd>, <kbd>Ctrl</kbd> + <kbd>q</kbd>

1. To stop the container, enter:

```shell
docker stop invehicle_digital_twin
```

### <a name="podman">Podman</a>

<b>Prerequisites</b>

[Install Podman](https://podman.io/docs/installation)

<b>Running in Podman</b>

To run the service in a Podman container:

1. Run the following command in the project's root directory to build the podman container from the
Dockerfile:

```shell
podman build -t invehicle_digital_twin:latest -f Dockerfile .
```

1. Once the container has been built, start the container with the following command in the
project's root directory:

```shell
podman run -p 5010:5010 --env-file=./container/config/podman.env --network=slirp4netns:allow_host_loopback=true localhost/invehicle_digital_twin
```

1. To stop the container, run:

```shell
podman ps -f ancestor=localhost/invehicle_digital_twin:latest --format="{{.Names}}" | xargs podman stop
```

## <a name="trademarks">Trademarks</a>

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
Expand Down
12 changes: 10 additions & 2 deletions core/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use strum_macros::Display;
use tokio::time::{sleep, Duration};
use tonic::{Request, Status};

const IBEJI_HOME_VAR_NAME: &str = "IBEJI_HOME";

/// An identifier used when discovering a service through Chariott.
#[derive(Debug, Deserialize)]
pub struct ServiceIdentifier {
Expand Down Expand Up @@ -41,8 +43,14 @@ pub fn load_settings<T>(config_filename: &str) -> Result<T, ConfigError>
where
T: for<'de> serde::Deserialize<'de>,
{
let config =
Config::builder().add_source(File::new(config_filename, FileFormat::Yaml)).build()?;
let config_filename_path = match std::env::var(IBEJI_HOME_VAR_NAME) {
Ok(s) => format!("{}/{}", s, config_filename),
_ => config_filename.to_owned(),
};

let config = Config::builder()
.add_source(File::new(config_filename_path.as_str(), FileFormat::Yaml))
.build()?;

config.try_deserialize()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

use config::{Config, File, FileFormat};
use common::utils;
use serde_derive::Deserialize;

const CONFIG_FILENAME: &str = "invehicle_digital_twin_settings";
Expand All @@ -15,10 +15,5 @@ pub struct Settings {

/// Load the settings.
pub fn load_settings() -> Settings {
let config =
Config::builder().add_source(File::new(CONFIG_FILENAME, FileFormat::Yaml)).build().unwrap();

let settings: Settings = config.try_deserialize().unwrap();

settings
utils::load_settings(CONFIG_FILENAME).unwrap()
}
Loading