From af9eee4565268f93e0c8cdec0e3e3962ffef4b54 Mon Sep 17 00:00:00 2001
From: Devin Kelley <105753233+devkelley@users.noreply.github.com>
Date: Thu, 2 Nov 2023 17:40:46 -0700
Subject: [PATCH 1/7] Add containerization for samples w/ container
documentation
---
.accepted_words.txt | 2 +
.github/workflows/check-spelling.yml | 2 +
Dockerfile | 4 +-
Dockerfile.integrated | 4 +-
README.md | 77 +--------
container/.accepted_words.txt | 91 +++++++++++
container/README.md | 117 ++++++++++++++
samples/Dockerfile.consumer | 85 ++++++++++
samples/Dockerfile.provider | 85 ++++++++++
samples/common/Cargo.toml | 3 +
samples/common/src/consumer_config.rs | 10 +-
samples/common/src/provider_config.rs | 10 +-
samples/common/src/utils.rs | 64 +++++++-
samples/container/.accepted_words.txt | 93 +++++++++++
samples/container/README.md | 153 ++++++++++++++++++
.../config/consumer/consumer_settings.yaml | 14 ++
samples/container/config/docker.env | 9 ++
samples/container/config/podman.env | 9 ++
.../config/provider/provider_settings.yaml | 14 ++
samples/managed_subscribe/Cargo.toml | 3 +
.../managed_subscribe/consumer/src/main.rs | 4 +-
.../provider/src/provider_impl.rs | 5 +-
samples/property/Cargo.toml | 3 +
samples/property/consumer/src/main.rs | 4 +-
samples/property/provider/src/main.rs | 6 +-
25 files changed, 768 insertions(+), 103 deletions(-)
create mode 100644 container/.accepted_words.txt
create mode 100644 container/README.md
create mode 100644 samples/Dockerfile.consumer
create mode 100644 samples/Dockerfile.provider
create mode 100644 samples/container/.accepted_words.txt
create mode 100644 samples/container/README.md
create mode 100644 samples/container/config/consumer/consumer_settings.yaml
create mode 100644 samples/container/config/docker.env
create mode 100644 samples/container/config/podman.env
create mode 100644 samples/container/config/provider/provider_settings.yaml
diff --git a/.accepted_words.txt b/.accepted_words.txt
index b30a7faf..2ec8814c 100644
--- a/.accepted_words.txt
+++ b/.accepted_words.txt
@@ -11,6 +11,7 @@ chariott
com
config
containerized
+Containerization
Ctrl
dev
digitaltwins
@@ -48,6 +49,7 @@ libfontconfig
libsdl
localhost
loopback
+md
microsoft
minimalistic
mosquitto
diff --git a/.github/workflows/check-spelling.yml b/.github/workflows/check-spelling.yml
index a4a0309e..086c23a8 100644
--- a/.github/workflows/check-spelling.yml
+++ b/.github/workflows/check-spelling.yml
@@ -17,8 +17,10 @@ jobs:
- name: Check spelling
run: |
./tools/check_spelling.sh ./README.md
+ ./tools/check_spelling.sh ./container/README.md
./tools/check_spelling.sh ./core/common/README.md
./tools/check_spelling.sh ./dtdl-parser/README.md
./tools/check_spelling.sh ./docs/design/README.md
+ ./tools/check_spelling.sh ./samples/container/README.md
./tools/check_spelling.sh ./samples/managed_subscribe/README.md
shell: bash
diff --git a/Dockerfile b/Dockerfile
index c208cd2c..0eaf11b7 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -63,13 +63,13 @@ USER appuser
WORKDIR /sdv
# Set home environment variable.
-ENV IBEJI_HOME=/sdv
+ENV IBEJI_HOME=/sdv/config
# Copy the executable from the "build" stage.
COPY --from=build /sdv/service /sdv/
# Copy configuration for service.
-COPY --from=build /sdv/container/config/standalone/ /sdv/
+COPY --from=build /sdv/container/config/standalone/ /sdv/config
# Expose the port that the application listens on.
EXPOSE 5010
diff --git a/Dockerfile.integrated b/Dockerfile.integrated
index 6ba75701..859a57aa 100644
--- a/Dockerfile.integrated
+++ b/Dockerfile.integrated
@@ -63,13 +63,13 @@ USER appuser
WORKDIR /sdv
# Set home environment variable.
-ENV IBEJI_HOME=/sdv
+ENV IBEJI_HOME=/sdv/config
# Copy the executable from the "build" stage.
COPY --from=build /sdv/service /sdv/
# Copy configuration for service.
-COPY --from=build /sdv/container/config/integrated/ /sdv/
+COPY --from=build /sdv/container/config/integrated/ /sdv/config
# Expose the port that the application listens on.
EXPOSE 5010
diff --git a/README.md b/README.md
index c13a74fb..f0c8c5c1 100644
--- a/README.md
+++ b/README.md
@@ -299,82 +299,9 @@ rather than having it statically provided in their respective config file, then
## Running in a Container
-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.
+To run the In-Vehicle Digital Twin Service in a container, please refer to [Ibeji Containerization](./container/README.md).
-### Dockerfile
-
-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).
-
-### Docker
-
-Prerequisites
-
-[Install Docker](https://docs.docker.com/engine/install/)
-
-Running in Docker
-
-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:
-
- Ctrl + p, Ctrl + q
-
-1. To stop the container, enter:
-
- ```shell
- docker stop invehicle_digital_twin
- ```
-
-### Podman
-
-Prerequisites
-
-[Install Podman](https://podman.io/docs/installation)
-
-Running in Podman
-
-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
- ```
+To run the samples in a container, please refer to [Samples Containerization](./samples/container/README.md).
## Trademarks
diff --git a/container/.accepted_words.txt b/container/.accepted_words.txt
new file mode 100644
index 00000000..4e86eebb
--- /dev/null
+++ b/container/.accepted_words.txt
@@ -0,0 +1,91 @@
+Agemo
+agemo
+br
+build
+cargo
+cd
+CHARIOTT
+Chariott
+Chariott's
+chariott
+com
+config
+containerize
+containerized
+Containerization
+Ctrl
+dev
+digitaltwins
+dir
+Dockerfile
+dockerfile
+dockerfiles
+dotnet
+dst
+dt
+dtdl
+DTDL
+en
+env
+fontconfig
+gcc
+gcc's
+github
+hardcheese
+haudebourg
+https
+ibeji
+Ibeji
+Ibeji's
+intellectualproperty
+invehicle
+io
+iot
+js
+json
+JSON
+kbd
+ld
+LD
+libfontconfig
+libsdl
+localhost
+loopback
+md
+microsoft
+minimalistic
+mosquitto
+Mosquitto
+mqtt
+MQTT
+netns
+opendigitaltwins
+plugandplay
+Podman
+podman
+protobuf
+Protobuf
+ps
+repo
+Repo
+rm
+ro
+rustup
+sdk
+sdl
+SDL
+sdv
+slirp
+snapd
+src
+standalone
+sudo
+timothee
+toml
+Tonic
+toolchain
+uri
+URI
+www
+xargs
+yaml
diff --git a/container/README.md b/container/README.md
new file mode 100644
index 00000000..06882227
--- /dev/null
+++ b/container/README.md
@@ -0,0 +1,117 @@
+# Ibeji Containerization
+
+This document covers how to containerize the In-Vehicle Digital Twin Service. To run the samples as
+a container please refer to [Samples Containerization](../samples/container/README.md).
+
+## Running the In-Vehicle Digital Twin Service in a Container
+
+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.
+
+### Dockerfile
+
+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).
+
+### Docker
+
+#### Prerequisites
+
+[Install Docker](https://docs.docker.com/engine/install/)
+
+#### Running in Docker
+
+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:
+
+ Ctrl + p, Ctrl + q
+
+1. To stop the container, enter:
+
+ ```shell
+ docker stop invehicle_digital_twin
+ ```
+
+#### Running in Docker with overridden configuration
+
+Follow the steps in [Running in Docker](#running-in-docker) to build the container.
+
+1. To run the container with overridden configuration, create your config file and set an
+environment variable called IBEJI_HOME to the path to the config file:
+
+ ```shell
+ export IBEJI_HOME={path to directory containing config file}
+ ```
+
+1. Then run the container with the following command:
+
+ ```shell
+ docker run -v ${IBEJI_HOME}:/sdv/config --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
+ ```
+
+### Podman
+
+#### Prerequisites
+
+[Install Podman](https://podman.io/docs/installation)
+
+#### Running in Podman
+
+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
+ ```
+
+#### Running in Podman with overridden configuration
+
+Follow the steps in [Running in Podman](#running-in-podman) to build the container.
+
+1. To run the container with overridden configuration, create your config file and set an
+environment variable called IBEJI_HOME to the path to the config file:
+
+ ```shell
+ export IBEJI_HOME={path to directory containing config file}
+ ```
+
+1. Then run the container with the following command:
+
+ ```shell
+ podman run --mount=type=bind,src=${IBEJI_HOME},dst=/sdv/config,ro=true -p 5010:5010 --env-file=./container/config/podman.env --network=slirp4netns:allow_host_loopback=true localhost/invehicle_digital_twin:latest
+ ```
diff --git a/samples/Dockerfile.consumer b/samples/Dockerfile.consumer
new file mode 100644
index 00000000..dff34d74
--- /dev/null
+++ b/samples/Dockerfile.consumer
@@ -0,0 +1,85 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT license.
+# SPDX-License-Identifier: MIT
+
+# syntax=docker/dockerfile:1
+
+# Comments are provided throughout this file to help you get started.
+# If you need more help, visit the Dockerfile reference guide at
+# https://docs.docker.com/engine/reference/builder/
+
+################################################################################
+# Create a stage for building the application.
+
+ARG RUST_VERSION=1.72.1
+FROM docker.io/library/rust:${RUST_VERSION}-slim-bullseye AS build
+ARG APP_NAME=property-consumer
+WORKDIR /sdv
+
+COPY ./ .
+
+# Add Build dependencies.
+RUN apt update && apt upgrade -y && apt install -y \
+ cmake \
+ libsdl2-dev \
+ libssl-dev \
+ pkg-config \
+ protobuf-compiler
+
+# Check that APP_NAME argument is valid.
+RUN sanitized=$(echo "${APP_NAME}" | tr -dc '^[a-zA-Z_0-9-]+$'); \
+[ "$sanitized" = "${APP_NAME}" ] || { \
+ echo "ARG 'APP_NAME' is invalid. APP_NAME='${APP_NAME}' sanitized='${sanitized}'"; \
+ exit 1; \
+}
+
+# Build the application with the 'containerize' feature.
+RUN cargo build --release --bin "${APP_NAME}" --features "containerize"
+
+# Copy the built application to working directory.
+RUN cp ./target/release/"${APP_NAME}" /sdv/service
+
+################################################################################
+# Create a new stage for running the application that contains the minimal
+# runtime dependencies for the application. This often uses a different base
+# image from the build stage where the necessary files are copied from the build
+# stage.
+#
+# The example below uses the debian bullseye image as the foundation for running the app.
+# By specifying the "bullseye-slim" tag, it will also use whatever happens to be the
+# most recent version of that tag when you build your Dockerfile. If
+# reproducability is important, consider using a digest
+# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
+FROM docker.io/library/debian:bullseye-slim AS final
+
+RUN apt update && apt upgrade -y && apt install -y libsdl2-dev
+
+# Create a non-privileged user that the app will run under.
+# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
+ARG UID=10001
+RUN adduser \
+ --disabled-password \
+ --gecos "" \
+ --home "/nonexistent" \
+ --shell "/sbin/nologin" \
+ --no-create-home \
+ --uid "${UID}" \
+ appuser
+USER appuser
+
+WORKDIR /sdv
+
+# Set home environment variable.
+ENV IBEJI_HOME=/sdv/config
+
+# Copy the executable from the "build" stage.
+COPY --from=build /sdv/service /sdv/
+
+# Copy configuration for service.
+COPY --from=build /sdv/samples/container/config/consumer/ /sdv/config
+
+# Expose the port that the application listens on.
+EXPOSE 6010
+
+# What the container should run when it is started.
+CMD ["/sdv/service"]
diff --git a/samples/Dockerfile.provider b/samples/Dockerfile.provider
new file mode 100644
index 00000000..eb887b4b
--- /dev/null
+++ b/samples/Dockerfile.provider
@@ -0,0 +1,85 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT license.
+# SPDX-License-Identifier: MIT
+
+# syntax=docker/dockerfile:1
+
+# Comments are provided throughout this file to help you get started.
+# If you need more help, visit the Dockerfile reference guide at
+# https://docs.docker.com/engine/reference/builder/
+
+################################################################################
+# Create a stage for building the application.
+
+ARG RUST_VERSION=1.72.1
+FROM docker.io/library/rust:${RUST_VERSION}-slim-bullseye AS build
+ARG APP_NAME=property-provider
+WORKDIR /sdv
+
+COPY ./ .
+
+# Add Build dependencies.
+RUN apt update && apt upgrade -y && apt install -y \
+ cmake \
+ libsdl2-dev \
+ libssl-dev \
+ pkg-config \
+ protobuf-compiler
+
+# Check that APP_NAME argument is valid.
+RUN sanitized=$(echo "${APP_NAME}" | tr -dc '^[a-zA-Z_0-9-]+$'); \
+[ "$sanitized" = "${APP_NAME}" ] || { \
+ echo "ARG 'APP_NAME' is invalid. APP_NAME='${APP_NAME}' sanitized='${sanitized}'"; \
+ exit 1; \
+}
+
+# Build the application with the 'containerize' feature.
+RUN cargo build --release --bin "${APP_NAME}" --features "containerize"
+
+# Copy the built application to working directory.
+RUN cp ./target/release/"${APP_NAME}" /sdv/service
+
+################################################################################
+# Create a new stage for running the application that contains the minimal
+# runtime dependencies for the application. This often uses a different base
+# image from the build stage where the necessary files are copied from the build
+# stage.
+#
+# The example below uses the debian bullseye image as the foundation for running the app.
+# By specifying the "bullseye-slim" tag, it will also use whatever happens to be the
+# most recent version of that tag when you build your Dockerfile. If
+# reproducability is important, consider using a digest
+# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
+FROM docker.io/library/debian:bullseye-slim AS final
+
+RUN apt update && apt upgrade -y && apt install -y libsdl2-dev
+
+# Create a non-privileged user that the app will run under.
+# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
+ARG UID=10001
+RUN adduser \
+ --disabled-password \
+ --gecos "" \
+ --home "/nonexistent" \
+ --shell "/sbin/nologin" \
+ --no-create-home \
+ --uid "${UID}" \
+ appuser
+USER appuser
+
+WORKDIR /sdv
+
+# Set home environment variable.
+ENV IBEJI_HOME=/sdv/config
+
+# Copy the executable from the "build" stage.
+COPY --from=build /sdv/service /sdv/
+
+# Copy configuration for service.
+COPY --from=build /sdv/samples/container/config/provider/ /sdv/config
+
+# Expose the port that the application listens on.
+EXPOSE 4010
+
+# What the container should run when it is started.
+CMD ["/sdv/service"]
diff --git a/samples/common/Cargo.toml b/samples/common/Cargo.toml
index ac2b9ac2..dc5b7659 100644
--- a/samples/common/Cargo.toml
+++ b/samples/common/Cargo.toml
@@ -19,3 +19,6 @@ serde_derive = { workspace = true }
tokio = { workspace = true }
tonic = { workspace = true }
yaml-rust = { workspace = true }
+
+[features]
+containerize = []
diff --git a/samples/common/src/consumer_config.rs b/samples/common/src/consumer_config.rs
index dbe81230..5a18137d 100644
--- a/samples/common/src/consumer_config.rs
+++ b/samples/common/src/consumer_config.rs
@@ -2,7 +2,8 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT
-use config::{Config, File, FileFormat};
+use crate::utils;
+
use serde_derive::Deserialize;
const CONFIG_FILENAME: &str = "consumer_settings";
@@ -16,10 +17,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()
}
diff --git a/samples/common/src/provider_config.rs b/samples/common/src/provider_config.rs
index c223f105..109a5873 100644
--- a/samples/common/src/provider_config.rs
+++ b/samples/common/src/provider_config.rs
@@ -2,7 +2,8 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT
-use config::{Config, File, FileFormat};
+use crate::utils;
+
use serde_derive::Deserialize;
const CONFIG_FILENAME: &str = "provider_settings";
@@ -16,10 +17,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()
}
diff --git a/samples/common/src/utils.rs b/samples/common/src/utils.rs
index 2f9ad18e..839c768e 100644
--- a/samples/common/src/utils.rs
+++ b/samples/common/src/utils.rs
@@ -4,6 +4,7 @@
use crate::constants;
+use config::{Config, ConfigError, File, FileFormat};
use constants::chariott::{
INVEHICLE_DIGITAL_TWIN_SERVICE_COMMUNICATION_KIND,
INVEHICLE_DIGITAL_TWIN_SERVICE_COMMUNICATION_REFERENCE, INVEHICLE_DIGITAL_TWIN_SERVICE_NAME,
@@ -18,6 +19,28 @@ use std::future::Future;
use tokio::time::{sleep, Duration};
use tonic::{Code, Request, Status};
+const IBEJI_HOME_VAR_NAME: &str = "IBEJI_HOME";
+
+/// Load the settings.
+///
+/// # Arguments
+/// * `config_filename` - Name of the config file to load settings from.
+pub fn load_settings(config_filename: &str) -> Result
+where
+ T: for<'de> serde::Deserialize<'de>,
+{
+ 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()
+}
+
/// Is the provided subset a subset of the provided superset?
///
/// # Arguments
@@ -106,11 +129,14 @@ pub async fn discover_digital_twin_provider_using_ibeji(
})
.cloned()
{
- Some(result) => {
+ Some(mut result) => {
info!(
"Found a matching endpoint for entity id {entity_id} that has URI {}",
result.uri
);
+
+ result.uri = get_uri(&result.uri).map_err(|err| format!("Failed to get provider URI due to error: {err}").to_string())?;
+
Ok(result)
}
None => Err("Did not find an endpoint that met our requirements".to_string()),
@@ -134,7 +160,9 @@ pub async fn discover_service_using_chariott(
communication_kind: &str,
communication_reference: &str,
) -> Result {
- let mut client = ServiceRegistryClient::connect(chariott_uri.to_string())
+ let uri = get_uri(chariott_uri)?;
+
+ let mut client = ServiceRegistryClient::connect(uri)
.await
.map_err(|e| Status::internal(e.to_string()))?;
@@ -205,7 +233,37 @@ pub async fn retrieve_invehicle_digital_twin_uri(
}
};
- Ok(result)
+ get_uri(&result).map_err(|err| format!("Failed to retrieve the in-vehicle digital twin service's URI due to error: {err}").to_string())
+}
+
+/// If feature 'containerize' is set, will modify a localhost uri to point to container's localhost
+/// DNS alias. Otherwise, returns the uri as a String.
+///
+/// # Arguments
+/// * `uri` - The uri to potentially modify.
+pub fn get_uri(uri: &str) -> Result {
+ #[cfg(feature = "containerize")]
+ let uri = {
+ // Container env variable names.
+ let host_gateway_env_var: &str = "HOST_GATEWAY";
+ let host_alias_env_var: &str = "LOCALHOST_ALIAS";
+
+ // Return an error if container env variables are not set.
+ let host_gateway = std::env::var(host_gateway_env_var).map_err(|err| {
+ Status::failed_precondition(format!(
+ "Unable to get environment var '{host_gateway_env_var}' with error: {err}"
+ ))
+ })?;
+ let host_alias = std::env::var(host_alias_env_var).map_err(|err| {
+ Status::failed_precondition(format!(
+ "Unable to get environment var '{host_alias_env_var}' with error: {err}"
+ ))
+ })?;
+
+ uri.replace(&host_alias, &host_gateway)
+ };
+
+ Ok(uri.to_string())
}
#[cfg(test)]
diff --git a/samples/container/.accepted_words.txt b/samples/container/.accepted_words.txt
new file mode 100644
index 00000000..49d4301f
--- /dev/null
+++ b/samples/container/.accepted_words.txt
@@ -0,0 +1,93 @@
+Agemo
+agemo
+APP
+arg
+br
+build
+cargo
+cd
+CHARIOTT
+Chariott
+Chariott's
+chariott
+com
+config
+containerize
+containerized
+Containerization
+Ctrl
+dev
+digitaltwins
+dir
+Dockerfile
+dockerfile
+dockerfiles
+dotnet
+dst
+dt
+dtdl
+DTDL
+en
+env
+fontconfig
+gcc
+gcc's
+github
+hardcheese
+haudebourg
+https
+ibeji
+Ibeji
+Ibeji's
+intellectualproperty
+invehicle
+io
+iot
+js
+json
+JSON
+kbd
+ld
+LD
+libfontconfig
+libsdl
+localhost
+loopback
+md
+microsoft
+minimalistic
+mosquitto
+Mosquitto
+mqtt
+MQTT
+netns
+opendigitaltwins
+plugandplay
+Podman
+podman
+protobuf
+Protobuf
+ps
+repo
+Repo
+rm
+ro
+rustup
+sdk
+sdl
+SDL
+sdv
+slirp
+snapd
+src
+standalone
+sudo
+timothee
+toml
+Tonic
+toolchain
+uri
+URI
+www
+xargs
+yaml
diff --git a/samples/container/README.md b/samples/container/README.md
new file mode 100644
index 00000000..05b7ab3d
--- /dev/null
+++ b/samples/container/README.md
@@ -0,0 +1,153 @@
+# Samples Containerization
+
+This document covers how to containerize the samples for Ibeji. To run the in-vehicle digital twin
+service as a container or to get more in depth instruction for building and running a container
+please refer to [Ibeji Containerization](../../container/README.md).
+
+## Running the Samples in a Container
+
+Below are the steps for running the sample providers and consumers in a container. Note that the
+configuration files used by the containerized sample are cloned from
+[/samples/container/config](./samples/container/config/) defined in the project's root.
+
+### Provider
+
+Provider containers utilize the dockerfile [Dockerfile.provider](../Dockerfile.provider).
+
+#### Build
+
+By default, the sample provider built in the Dockerfile is the
+[property-provider](./samples/property/provider/). To change the provider the container builds, use
+the following command:
+
+ Docker
+
+ ```shell
+ --build-arg APP_NAME={name of the provider}
+ ```
+
+ For example:
+
+ ```shell
+ docker build -t provider -f ./samples/Dockerfile.provider . --build-arg APP_NAME=managed-subscribe-provider
+ ```
+
+ Podman
+
+ ```shell
+ --build-arg=APP_NAME={name of the provider}
+ ```
+
+ For example:
+
+ ```shell
+ podman build -t provider:latest -f ./samples/Dockerfile.provider . --build-arg=APP_NAME=managed-subscribe-provider
+ ```
+
+#### Run
+
+If you selected a different provider than the default provider built in the dockerfile, you may
+need to override the configuration file [provider_settings.yaml](./config/provider/provider_settings.yaml).
+To override the configuration of a provider container, follow the below steps after you have built
+the container:
+
+ Docker
+
+ 1. To run the container with overridden configuration, create your config file and set an
+ environment variable called IBEJI_HOME to the path to the config file:
+
+ ```shell
+ export IBEJI_HOME={path to directory containing config file}
+ ```
+
+ 1. Then run the container from the project's root with the following command:
+
+ ```shell
+ docker run -v ${IBEJI_HOME}:/sdv/config --name provider -p 5010:5010 --env-file=./samples/container/config/docker.env --add-host=host.docker.internal:host-gateway -it --rm invehicle_digital_twin
+ ```
+
+ Podman
+
+ 1. To run the container with overridden configuration, create your config file and set an
+ environment variable called IBEJI_HOME to the path to the config file:
+
+ ```shell
+ export IBEJI_HOME={path to directory containing config file}
+ ```
+
+ 1. Then run the container from the project's root with the following command:
+
+ ```shell
+ podman run --mount=type=bind,src=${IBEJI_HOME},dst=/sdv/config,ro=true -p 5010:5010 --env-file=./samples/container/config/podman.env --network=slirp4netns:allow_host_loopback=true localhost/provider:latest
+ ```
+
+### Consumer
+
+Consumer containers utilize the dockerfile [Dockerfile.consumer](../Dockerfile.consumer).
+
+#### Build
+
+By default, the sample consumer built in the Dockerfile is the
+[property-consumer](./samples/property/consumer/). To change the consumer the container builds, use
+the following command:
+
+ Docker
+
+ ```shell
+ --build-arg APP_NAME={name of the consumer}
+ ```
+
+ For example:
+
+ ```shell
+ docker build -t consumer -f ./samples/Dockerfile.consumer . --build-arg APP_NAME=managed-subscribe-consumer
+ ```
+
+ Podman
+
+ ```shell
+ --build-arg=APP_NAME={name of the consumer}
+ ```
+
+ For example:
+
+ ```shell
+ podman build -t consumer:latest -f ./samples/Dockerfile.consumer . --build-arg=APP_NAME=managed-subscribe-consumer
+ ```
+
+#### Run
+
+If you selected a different consumer than the default consumer built in the dockerfile, you may
+need to override the configuration file [consumer_settings.yaml](./config/consumer/consumer_settings.yaml).
+To override the configuration of a consumer container, follow the below steps after you have built
+the container:
+
+ Docker
+
+ 1. To run the container with overridden configuration, create your config file and set an
+ environment variable called IBEJI_HOME to the path to the config file:
+
+ ```shell
+ export IBEJI_HOME={path to directory containing config file}
+ ```
+
+ 1. Then run the container from the project's root with the following command:
+
+ ```shell
+ docker run -v ${IBEJI_HOME}:/sdv/config --name consumer -p 5010:5010 --env-file=./samples/container/config/docker.env --add-host=host.docker.internal:host-gateway -it --rm invehicle_digital_twin
+ ```
+
+ Podman
+
+ 1. To run the container with overridden configuration, create your config file and set an
+ environment variable called IBEJI_HOME to the path to the config file:
+
+ ```shell
+ export IBEJI_HOME={path to directory containing config file}
+ ```
+
+ 1. Then run the container from the project's root with the following command:
+
+ ```shell
+ podman run --mount=type=bind,src=${IBEJI_HOME},dst=/sdv/config,ro=true -p 5010:5010 --env-file=./samples/container/config/podman.env --network=slirp4netns:allow_host_loopback=true localhost/consumer:latest
+ ```
diff --git a/samples/container/config/consumer/consumer_settings.yaml b/samples/container/config/consumer/consumer_settings.yaml
new file mode 100644
index 00000000..48d27bdd
--- /dev/null
+++ b/samples/container/config/consumer/consumer_settings.yaml
@@ -0,0 +1,14 @@
+#
+# Consumer Settings
+#
+
+# The IP address and port number that the consumer listens on for consumer requests.
+# Example: "0.0.0.0:80"
+consumer_authority: "0.0.0.0:6010"
+
+# The URL that the in-vehicle digital twin service listens on for digital twin requests.
+invehicle_digital_twin_uri: "http://0.0.0.0:5010"
+
+# The URL that the Chariott service listens on for requests.
+# If you wish to use Chariott, then uncomment this setting and comment out the invehicle_digital_twin_url setting.
+#chariott_uri: "http://0.0.0.0:50000"
diff --git a/samples/container/config/docker.env b/samples/container/config/docker.env
new file mode 100644
index 00000000..56bafc6e
--- /dev/null
+++ b/samples/container/config/docker.env
@@ -0,0 +1,9 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT license.
+# SPDX-License-Identifier: MIT
+
+# DNS name used by the container to communicate with host.
+HOST_GATEWAY=host.docker.internal
+
+# Alias for localhost to be replaced by HOST_GATEWAY if run in a container.
+LOCALHOST_ALIAS=0.0.0.0
diff --git a/samples/container/config/podman.env b/samples/container/config/podman.env
new file mode 100644
index 00000000..1abc4a35
--- /dev/null
+++ b/samples/container/config/podman.env
@@ -0,0 +1,9 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT license.
+# SPDX-License-Identifier: MIT
+
+# DNS name used by the container to communicate with host.
+HOST_GATEWAY=host.containers.internal
+
+# Alias for localhost to be replaced by HOST_GATEWAY if run in a container.
+LOCALHOST_ALIAS=0.0.0.0
diff --git a/samples/container/config/provider/provider_settings.yaml b/samples/container/config/provider/provider_settings.yaml
new file mode 100644
index 00000000..bbe0a100
--- /dev/null
+++ b/samples/container/config/provider/provider_settings.yaml
@@ -0,0 +1,14 @@
+#
+# Provider Settings
+#
+
+# The IP address and port number that the provider listens on for provider requests.
+# Example: "0.0.0.0:80"
+provider_authority: "0.0.0.0:1883"
+
+# The URL that the in-vehicle digital twin service listens on for digital twin requests.
+invehicle_digital_twin_uri: "http://0.0.0.0:5010"
+
+# The URL that the Chariott service listens on for requests.
+# If you wish to use Chariott, then uncomment this setting and comment out the invehicle_digital_twin_url setting.
+# chariott_uri: "http://0.0.0.0:50000"
diff --git a/samples/managed_subscribe/Cargo.toml b/samples/managed_subscribe/Cargo.toml
index e901387f..f82adb36 100644
--- a/samples/managed_subscribe/Cargo.toml
+++ b/samples/managed_subscribe/Cargo.toml
@@ -38,3 +38,6 @@ path = "provider/src/main.rs"
[[bin]]
name = "managed-subscribe-consumer"
path = "consumer/src/main.rs"
+
+[features]
+containerize = ["samples-common/containerize"]
diff --git a/samples/managed_subscribe/consumer/src/main.rs b/samples/managed_subscribe/consumer/src/main.rs
index 44b467a5..5e9d90aa 100644
--- a/samples/managed_subscribe/consumer/src/main.rs
+++ b/samples/managed_subscribe/consumer/src/main.rs
@@ -11,7 +11,7 @@ use paho_mqtt as mqtt;
use samples_common::constants::{constraint_type, digital_twin_operation, digital_twin_protocol};
use samples_common::consumer_config;
use samples_common::utils::{
- discover_digital_twin_provider_using_ibeji, retrieve_invehicle_digital_twin_uri,
+ get_uri, discover_digital_twin_provider_using_ibeji, retrieve_invehicle_digital_twin_uri,
};
use samples_protobuf_data_access::module::managed_subscribe::v1::managed_subscribe_client::ManagedSubscribeClient;
use samples_protobuf_data_access::module::managed_subscribe::v1::{
@@ -180,7 +180,7 @@ async fn main() -> Result<(), Box> {
.await?;
// Deconstruct subscription information.
- let broker_uri = subscription_info.uri;
+ let broker_uri = get_uri(&subscription_info.uri)?;
let topic = subscription_info.context;
info!("The broker URI for the AmbientAirTemperature property's provider is {broker_uri}");
diff --git a/samples/managed_subscribe/provider/src/provider_impl.rs b/samples/managed_subscribe/provider/src/provider_impl.rs
index a0151042..9fe889a4 100644
--- a/samples/managed_subscribe/provider/src/provider_impl.rs
+++ b/samples/managed_subscribe/provider/src/provider_impl.rs
@@ -16,6 +16,7 @@ use log::{debug, info, warn};
use paho_mqtt as mqtt;
use parking_lot::RwLock;
use samples_common::constants::constraint_type;
+use samples_common::utils;
use serde_derive::{Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use tokio::sync::{mpsc, watch};
@@ -130,7 +131,9 @@ impl ProviderImpl {
let min_interval_ms = self.min_interval_ms;
// This should not be empty.
- let subscription_info = payload.subscription_info.unwrap();
+ let mut subscription_info = payload.subscription_info.unwrap();
+
+ subscription_info.uri = utils::get_uri(&subscription_info.uri).unwrap();
// Create stop publish channel.
let (sender, mut reciever) = mpsc::channel(10);
diff --git a/samples/property/Cargo.toml b/samples/property/Cargo.toml
index d8907f1f..e24508d1 100644
--- a/samples/property/Cargo.toml
+++ b/samples/property/Cargo.toml
@@ -36,3 +36,6 @@ path = "provider/src/main.rs"
[[bin]]
name = "property-consumer"
path = "consumer/src/main.rs"
+
+[features]
+containerize = ["samples-common/containerize"]
diff --git a/samples/property/consumer/src/main.rs b/samples/property/consumer/src/main.rs
index 17c057c7..b5e092d1 100644
--- a/samples/property/consumer/src/main.rs
+++ b/samples/property/consumer/src/main.rs
@@ -21,7 +21,7 @@ const MQTT_CLIENT_ID: &str = "property-consumer";
/// # Arguments
/// * `broker_uri` - The broker URI.
/// * `topic` - The topic.
-fn receive_ambient_air_tempterature_updates(broker_uri: &str, topic: &str) -> Result<(), String> {
+fn receive_ambient_air_temperature_updates(broker_uri: &str, topic: &str) -> Result<(), String> {
let create_opts = mqtt::CreateOptionsBuilder::new()
.server_uri(broker_uri)
.client_id(MQTT_CLIENT_ID.to_string())
@@ -101,7 +101,7 @@ async fn main() -> Result<(), Box> {
let topic = provider_endpoint_info.context;
info!("The Topic for the AmbientAirTemperature property's provider is {topic})");
- let _receive_result = receive_ambient_air_tempterature_updates(&broker_uri, &topic)
+ let _receive_result = receive_ambient_air_temperature_updates(&broker_uri, &topic)
.map_err(|err| Status::internal(format!("{err:?}")));
info!("The Consumer has completed.");
diff --git a/samples/property/provider/src/main.rs b/samples/property/provider/src/main.rs
index 21f9c052..b1dd8c5e 100644
--- a/samples/property/provider/src/main.rs
+++ b/samples/property/provider/src/main.rs
@@ -8,7 +8,7 @@ use log::{debug, info, warn, LevelFilter};
use paho_mqtt as mqtt;
use samples_common::constants::{digital_twin_operation, digital_twin_protocol};
use samples_common::provider_config;
-use samples_common::utils::{retrieve_invehicle_digital_twin_uri, retry_async_based_on_status};
+use samples_common::utils::{get_uri, retrieve_invehicle_digital_twin_uri, retry_async_based_on_status};
use samples_protobuf_data_access::invehicle_digital_twin::v1::invehicle_digital_twin_client::InvehicleDigitalTwinClient;
use samples_protobuf_data_access::invehicle_digital_twin::v1::{
EndpointInfo, EntityAccessInfo, RegisterRequest,
@@ -207,7 +207,9 @@ async fn main() -> Result<(), Box> {
})
.await?;
- start_ambient_air_temperature_data_stream(broker_uri, topic);
+ let stream_uri = get_uri(&broker_uri)?;
+
+ start_ambient_air_temperature_data_stream(stream_uri, topic);
signal::ctrl_c().await.expect("Failed to listen for control-c event");
From 4980009f6d722fdbda45c1ff2e8ebe3c91ddb96d Mon Sep 17 00:00:00 2001
From: Devin Kelley <105753233+devkelley@users.noreply.github.com>
Date: Fri, 3 Nov 2023 11:31:19 -0700
Subject: [PATCH 2/7] Fix fmt warnings
---
Dockerfile | 2 --
Dockerfile.integrated | 2 --
README.md | 3 ++-
samples/Dockerfile.consumer | 2 --
samples/Dockerfile.provider | 2 --
samples/common/src/utils.rs | 14 +++++++++-----
samples/container/README.md | 4 ++--
.../config/consumer/consumer_settings.yaml | 8 --------
.../config/provider/provider_settings.yaml | 4 ----
samples/managed_subscribe/consumer/src/main.rs | 2 +-
samples/property/provider/src/main.rs | 4 +++-
11 files changed, 17 insertions(+), 30 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index 0eaf11b7..41e3848c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,8 +2,6 @@
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT
-# syntax=docker/dockerfile:1
-
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
diff --git a/Dockerfile.integrated b/Dockerfile.integrated
index 859a57aa..05c335f3 100644
--- a/Dockerfile.integrated
+++ b/Dockerfile.integrated
@@ -2,8 +2,6 @@
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT
-# syntax=docker/dockerfile:1
-
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
diff --git a/README.md b/README.md
index f0c8c5c1..979f56e5 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,8 @@ sudo apt install -y protobuf-compiler
### Install SDL2 library
-You will need to install the libsdl2-dev library. This can be done by executing:
+You will need to install the libsdl2-dev library. This is used by the streaming sample to view
+images. Install the libsdl2-dev library by executing:
```shell
sudo apt install -y libsdl2-dev
diff --git a/samples/Dockerfile.consumer b/samples/Dockerfile.consumer
index dff34d74..425a1b30 100644
--- a/samples/Dockerfile.consumer
+++ b/samples/Dockerfile.consumer
@@ -2,8 +2,6 @@
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT
-# syntax=docker/dockerfile:1
-
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
diff --git a/samples/Dockerfile.provider b/samples/Dockerfile.provider
index eb887b4b..34cad0ca 100644
--- a/samples/Dockerfile.provider
+++ b/samples/Dockerfile.provider
@@ -2,8 +2,6 @@
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT
-# syntax=docker/dockerfile:1
-
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
diff --git a/samples/common/src/utils.rs b/samples/common/src/utils.rs
index 839c768e..2157fcf7 100644
--- a/samples/common/src/utils.rs
+++ b/samples/common/src/utils.rs
@@ -135,7 +135,9 @@ pub async fn discover_digital_twin_provider_using_ibeji(
result.uri
);
- result.uri = get_uri(&result.uri).map_err(|err| format!("Failed to get provider URI due to error: {err}").to_string())?;
+ result.uri = get_uri(&result.uri).map_err(|err| {
+ format!("Failed to get provider URI due to error: {err}").to_string()
+ })?;
Ok(result)
}
@@ -162,9 +164,8 @@ pub async fn discover_service_using_chariott(
) -> Result {
let uri = get_uri(chariott_uri)?;
- let mut client = ServiceRegistryClient::connect(uri)
- .await
- .map_err(|e| Status::internal(e.to_string()))?;
+ let mut client =
+ ServiceRegistryClient::connect(uri).await.map_err(|e| Status::internal(e.to_string()))?;
let request = Request::new(DiscoverRequest {
namespace: namespace.to_string(),
@@ -233,7 +234,10 @@ pub async fn retrieve_invehicle_digital_twin_uri(
}
};
- get_uri(&result).map_err(|err| format!("Failed to retrieve the in-vehicle digital twin service's URI due to error: {err}").to_string())
+ get_uri(&result).map_err(|err| {
+ format!("Failed to retrieve the in-vehicle digital twin service's URI due to error: {err}")
+ .to_string()
+ })
}
/// If feature 'containerize' is set, will modify a localhost uri to point to container's localhost
diff --git a/samples/container/README.md b/samples/container/README.md
index 05b7ab3d..41a71bd9 100644
--- a/samples/container/README.md
+++ b/samples/container/README.md
@@ -18,7 +18,7 @@ Provider containers utilize the dockerfile [Dockerfile.provider](../Dockerfile.p
By default, the sample provider built in the Dockerfile is the
[property-provider](./samples/property/provider/). To change the provider the container builds, use
-the following command:
+the following argument:
Docker
@@ -89,7 +89,7 @@ Consumer containers utilize the dockerfile [Dockerfile.consumer](../Dockerfile.c
By default, the sample consumer built in the Dockerfile is the
[property-consumer](./samples/property/consumer/). To change the consumer the container builds, use
-the following command:
+the following argument:
Docker
diff --git a/samples/container/config/consumer/consumer_settings.yaml b/samples/container/config/consumer/consumer_settings.yaml
index 48d27bdd..6275e5e4 100644
--- a/samples/container/config/consumer/consumer_settings.yaml
+++ b/samples/container/config/consumer/consumer_settings.yaml
@@ -2,13 +2,5 @@
# Consumer Settings
#
-# The IP address and port number that the consumer listens on for consumer requests.
-# Example: "0.0.0.0:80"
-consumer_authority: "0.0.0.0:6010"
-
# The URL that the in-vehicle digital twin service listens on for digital twin requests.
invehicle_digital_twin_uri: "http://0.0.0.0:5010"
-
-# The URL that the Chariott service listens on for requests.
-# If you wish to use Chariott, then uncomment this setting and comment out the invehicle_digital_twin_url setting.
-#chariott_uri: "http://0.0.0.0:50000"
diff --git a/samples/container/config/provider/provider_settings.yaml b/samples/container/config/provider/provider_settings.yaml
index bbe0a100..3bbbe415 100644
--- a/samples/container/config/provider/provider_settings.yaml
+++ b/samples/container/config/provider/provider_settings.yaml
@@ -8,7 +8,3 @@ provider_authority: "0.0.0.0:1883"
# The URL that the in-vehicle digital twin service listens on for digital twin requests.
invehicle_digital_twin_uri: "http://0.0.0.0:5010"
-
-# The URL that the Chariott service listens on for requests.
-# If you wish to use Chariott, then uncomment this setting and comment out the invehicle_digital_twin_url setting.
-# chariott_uri: "http://0.0.0.0:50000"
diff --git a/samples/managed_subscribe/consumer/src/main.rs b/samples/managed_subscribe/consumer/src/main.rs
index 5e9d90aa..e8ec255d 100644
--- a/samples/managed_subscribe/consumer/src/main.rs
+++ b/samples/managed_subscribe/consumer/src/main.rs
@@ -11,7 +11,7 @@ use paho_mqtt as mqtt;
use samples_common::constants::{constraint_type, digital_twin_operation, digital_twin_protocol};
use samples_common::consumer_config;
use samples_common::utils::{
- get_uri, discover_digital_twin_provider_using_ibeji, retrieve_invehicle_digital_twin_uri,
+ discover_digital_twin_provider_using_ibeji, get_uri, retrieve_invehicle_digital_twin_uri,
};
use samples_protobuf_data_access::module::managed_subscribe::v1::managed_subscribe_client::ManagedSubscribeClient;
use samples_protobuf_data_access::module::managed_subscribe::v1::{
diff --git a/samples/property/provider/src/main.rs b/samples/property/provider/src/main.rs
index b1dd8c5e..0808174a 100644
--- a/samples/property/provider/src/main.rs
+++ b/samples/property/provider/src/main.rs
@@ -8,7 +8,9 @@ use log::{debug, info, warn, LevelFilter};
use paho_mqtt as mqtt;
use samples_common::constants::{digital_twin_operation, digital_twin_protocol};
use samples_common::provider_config;
-use samples_common::utils::{get_uri, retrieve_invehicle_digital_twin_uri, retry_async_based_on_status};
+use samples_common::utils::{
+ get_uri, retrieve_invehicle_digital_twin_uri, retry_async_based_on_status,
+};
use samples_protobuf_data_access::invehicle_digital_twin::v1::invehicle_digital_twin_client::InvehicleDigitalTwinClient;
use samples_protobuf_data_access::invehicle_digital_twin::v1::{
EndpointInfo, EntityAccessInfo, RegisterRequest,
From c3e1e868929e4d218a3c9902c17d1dc876ca3c37 Mon Sep 17 00:00:00 2001
From: Devin Kelley <105753233+devkelley@users.noreply.github.com>
Date: Fri, 3 Nov 2023 11:40:08 -0700
Subject: [PATCH 3/7] fix linking issues
---
README.md | 3 ---
container/README.md | 2 +-
samples/container/README.md | 6 +++---
samples/container/config/consumer/consumer_settings.yaml | 2 +-
samples/container/config/provider/provider_settings.yaml | 2 +-
5 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index 979f56e5..8d786559 100644
--- a/README.md
+++ b/README.md
@@ -20,9 +20,6 @@
- [Streaming Sample](#streaming-sample)
- [Using Chariott](#using-chariott)
- [Running in a Container](#running-in-a-container)
- - [Dockerfile](#dockerfile)
- - [Docker](#docker)
- - [Podman](#podman)
- [Trademarks](#trademarks)
## Introduction
diff --git a/container/README.md b/container/README.md
index 06882227..72f3c386 100644
--- a/container/README.md
+++ b/container/README.md
@@ -6,7 +6,7 @@ a container please refer to [Samples Containerization](../samples/container/READ
## Running the In-Vehicle Digital Twin Service in a Container
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
+by the containerized service are cloned from [/container/config](./config/) defined in the
project's root.
### Dockerfile
diff --git a/samples/container/README.md b/samples/container/README.md
index 41a71bd9..4554a37d 100644
--- a/samples/container/README.md
+++ b/samples/container/README.md
@@ -8,7 +8,7 @@ please refer to [Ibeji Containerization](../../container/README.md).
Below are the steps for running the sample providers and consumers in a container. Note that the
configuration files used by the containerized sample are cloned from
-[/samples/container/config](./samples/container/config/) defined in the project's root.
+[/samples/container/config](./config/) defined in the project's root.
### Provider
@@ -17,7 +17,7 @@ Provider containers utilize the dockerfile [Dockerfile.provider](../Dockerfile.p
#### Build
By default, the sample provider built in the Dockerfile is the
-[property-provider](./samples/property/provider/). To change the provider the container builds, use
+[property-provider](../property/provider/). To change the provider the container builds, use
the following argument:
Docker
@@ -88,7 +88,7 @@ Consumer containers utilize the dockerfile [Dockerfile.consumer](../Dockerfile.c
#### Build
By default, the sample consumer built in the Dockerfile is the
-[property-consumer](./samples/property/consumer/). To change the consumer the container builds, use
+[property-consumer](../property/consumer/). To change the consumer the container builds, use
the following argument:
Docker
diff --git a/samples/container/config/consumer/consumer_settings.yaml b/samples/container/config/consumer/consumer_settings.yaml
index 6275e5e4..4ef54a6f 100644
--- a/samples/container/config/consumer/consumer_settings.yaml
+++ b/samples/container/config/consumer/consumer_settings.yaml
@@ -3,4 +3,4 @@
#
# The URL that the in-vehicle digital twin service listens on for digital twin requests.
-invehicle_digital_twin_uri: "http://0.0.0.0:5010"
+invehicle_digital_twin_uri: "http://0.0.0.0:5010" # DevSkim: ignore DS137138
diff --git a/samples/container/config/provider/provider_settings.yaml b/samples/container/config/provider/provider_settings.yaml
index 3bbbe415..41d84366 100644
--- a/samples/container/config/provider/provider_settings.yaml
+++ b/samples/container/config/provider/provider_settings.yaml
@@ -7,4 +7,4 @@
provider_authority: "0.0.0.0:1883"
# The URL that the in-vehicle digital twin service listens on for digital twin requests.
-invehicle_digital_twin_uri: "http://0.0.0.0:5010"
+invehicle_digital_twin_uri: "http://0.0.0.0:5010" # DevSkim: ignore DS137138
From 75e03edee5c1fc13464cb34886d91d225f3574ce Mon Sep 17 00:00:00 2001
From: Devin Kelley <105753233+devkelley@users.noreply.github.com>
Date: Fri, 3 Nov 2023 12:16:43 -0700
Subject: [PATCH 4/7] Remove unecessary .to_string
---
samples/common/src/utils.rs | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/samples/common/src/utils.rs b/samples/common/src/utils.rs
index 2157fcf7..a095de0b 100644
--- a/samples/common/src/utils.rs
+++ b/samples/common/src/utils.rs
@@ -135,9 +135,8 @@ pub async fn discover_digital_twin_provider_using_ibeji(
result.uri
);
- result.uri = get_uri(&result.uri).map_err(|err| {
- format!("Failed to get provider URI due to error: {err}").to_string()
- })?;
+ result.uri = get_uri(&result.uri)
+ .map_err(|err| format!("Failed to get provider URI due to error: {err}"))?;
Ok(result)
}
@@ -236,7 +235,6 @@ pub async fn retrieve_invehicle_digital_twin_uri(
get_uri(&result).map_err(|err| {
format!("Failed to retrieve the in-vehicle digital twin service's URI due to error: {err}")
- .to_string()
})
}
From 4ec774eb434cf69e8c6f1a00df9d78ddc04c50eb Mon Sep 17 00:00:00 2001
From: Devin Kelley <105753233+devkelley@users.noreply.github.com>
Date: Fri, 3 Nov 2023 12:25:29 -0700
Subject: [PATCH 5/7] updated comment and readme wording
---
container/README.md | 10 ++++++----
samples/common/src/utils.rs | 4 ++--
samples/container/README.md | 20 ++++++++++++--------
3 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/container/README.md b/container/README.md
index 72f3c386..06d9363e 100644
--- a/container/README.md
+++ b/container/README.md
@@ -57,10 +57,11 @@ command in the project's root directory:
Follow the steps in [Running in Docker](#running-in-docker) to build the container.
1. To run the container with overridden configuration, create your config file and set an
-environment variable called IBEJI_HOME to the path to the config file:
+environment variable called IBEJI_HOME to the absolute path of the directory containing the
+config file:
```shell
- export IBEJI_HOME={path to directory containing config file}
+ export IBEJI_HOME={absolute path of the directory containing the config file}
```
1. Then run the container with the following command:
@@ -104,10 +105,11 @@ project's root directory:
Follow the steps in [Running in Podman](#running-in-podman) to build the container.
1. To run the container with overridden configuration, create your config file and set an
-environment variable called IBEJI_HOME to the path to the config file:
+environment variable called IBEJI_HOME to the absolute path of the directory containing the
+config file:
```shell
- export IBEJI_HOME={path to directory containing config file}
+ export IBEJI_HOME={absolute path of the directory containing the config file}
```
1. Then run the container with the following command:
diff --git a/samples/common/src/utils.rs b/samples/common/src/utils.rs
index a095de0b..0b4ee2f5 100644
--- a/samples/common/src/utils.rs
+++ b/samples/common/src/utils.rs
@@ -238,8 +238,8 @@ pub async fn retrieve_invehicle_digital_twin_uri(
})
}
-/// If feature 'containerize' is set, will modify a localhost uri to point to container's localhost
-/// DNS alias. Otherwise, returns the uri as a String.
+/// If the 'containerize' feature is set, this function will modify the localhost URI to point to
+/// the container's localhost DNS alias. Otherwise, returns the URI as a string.
///
/// # Arguments
/// * `uri` - The uri to potentially modify.
diff --git a/samples/container/README.md b/samples/container/README.md
index 4554a37d..f3467046 100644
--- a/samples/container/README.md
+++ b/samples/container/README.md
@@ -54,10 +54,11 @@ the container:
Docker
1. To run the container with overridden configuration, create your config file and set an
- environment variable called IBEJI_HOME to the path to the config file:
+ environment variable called IBEJI_HOME to the absolute path of the directory containing the
+ config file:
```shell
- export IBEJI_HOME={path to directory containing config file}
+ export IBEJI_HOME={absolute path of the directory containing the config file}
```
1. Then run the container from the project's root with the following command:
@@ -69,10 +70,11 @@ the container:
Podman
1. To run the container with overridden configuration, create your config file and set an
- environment variable called IBEJI_HOME to the path to the config file:
+ environment variable called IBEJI_HOME to the absolute path of the directory containing the
+ config file:
```shell
- export IBEJI_HOME={path to directory containing config file}
+ export IBEJI_HOME={absolute path of the directory containing the config file}
```
1. Then run the container from the project's root with the following command:
@@ -125,10 +127,11 @@ the container:
Docker
1. To run the container with overridden configuration, create your config file and set an
- environment variable called IBEJI_HOME to the path to the config file:
+ environment variable called IBEJI_HOME to the absolute path of the directory containing the
+ config file:
```shell
- export IBEJI_HOME={path to directory containing config file}
+ export IBEJI_HOME={absolute path of the directory containing the config file}
```
1. Then run the container from the project's root with the following command:
@@ -140,10 +143,11 @@ the container:
Podman
1. To run the container with overridden configuration, create your config file and set an
- environment variable called IBEJI_HOME to the path to the config file:
+ environment variable called IBEJI_HOME to the absolute path of the directory containing the
+ config file:
```shell
- export IBEJI_HOME={path to directory containing config file}
+ export IBEJI_HOME={absolute path of the directory containing the config file}
```
1. Then run the container from the project's root with the following command:
From c235a448d929b8d2209e40767f05cf84ca92ad39 Mon Sep 17 00:00:00 2001
From: Devin Kelley <105753233+devkelley@users.noreply.github.com>
Date: Mon, 6 Nov 2023 13:09:47 -0800
Subject: [PATCH 6/7] Update rust ci
---
.github/workflows/rust-ci.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml
index 08e6c9b6..a9c2bc6b 100644
--- a/.github/workflows/rust-ci.yml
+++ b/.github/workflows/rust-ci.yml
@@ -20,7 +20,7 @@ jobs:
with:
submodules: recursive
- name: Install packages
- run: sudo apt-get install -y protobuf-compiler libsdl2-dev
+ run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libsdl2-dev
- name: Install .NET 7.0
uses: actions/setup-dotnet@v3
with:
@@ -54,7 +54,7 @@ jobs:
with:
submodules: recursive
- name: Install packages
- run: sudo apt-get install -y protobuf-compiler libsdl2-dev
+ run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libsdl2-dev
- name: Install .NET 7.0
uses: actions/setup-dotnet@v3
with:
From a00d3563be3fdc2fb92a8e12339a3e923c4db9c2 Mon Sep 17 00:00:00 2001
From: Devin Kelley <105753233+devkelley@users.noreply.github.com>
Date: Mon, 6 Nov 2023 13:43:09 -0800
Subject: [PATCH 7/7] Added -y
---
.github/workflows/rust-ci.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml
index a9c2bc6b..88c55cfa 100644
--- a/.github/workflows/rust-ci.yml
+++ b/.github/workflows/rust-ci.yml
@@ -20,7 +20,7 @@ jobs:
with:
submodules: recursive
- name: Install packages
- run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libsdl2-dev
+ run: sudo apt-get update -y && sudo apt-get install -y protobuf-compiler libsdl2-dev
- name: Install .NET 7.0
uses: actions/setup-dotnet@v3
with:
@@ -54,7 +54,7 @@ jobs:
with:
submodules: recursive
- name: Install packages
- run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libsdl2-dev
+ run: sudo apt-get update -y && sudo apt-get install -y protobuf-compiler libsdl2-dev
- name: Install .NET 7.0
uses: actions/setup-dotnet@v3
with: