From 528a90227c30d8be0d62209f94b23387462de9a4 Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:20:50 -0700 Subject: [PATCH 01/11] Add containerization for freyja_apps --- .freyja/config/grpc_proxy_config.json | 3 + Cargo.lock | 11 ++ Cargo.toml | 1 + Dockerfile.freyja_apps | 75 +++++++++++++ container/README.md | 29 +++++ container/config/docker.env | 9 ++ container/config/podman.env | 9 ++ .../digital_twin/ibeji_adapter/Cargo.toml | 5 +- .../digital_twin/ibeji_adapter/src/config.rs | 25 +++++ .../ibeji_adapter/src/ibeji_adapter.rs | 16 ++- freyja_apps/ibeji_adapter/Cargo.toml | 23 ++++ freyja_apps/ibeji_adapter/README.md | 102 ++++++++++++++++++ freyja_apps/ibeji_adapter/src/main.rs | 13 +++ freyja_apps/in_memory/Cargo.toml | 5 +- freyja_apps/in_memory/README.md | 70 ++++++++++++ 15 files changed, 390 insertions(+), 6 deletions(-) create mode 100644 .freyja/config/grpc_proxy_config.json create mode 100644 Dockerfile.freyja_apps create mode 100644 container/README.md create mode 100644 container/config/docker.env create mode 100644 container/config/podman.env create mode 100644 freyja_apps/ibeji_adapter/Cargo.toml create mode 100644 freyja_apps/ibeji_adapter/README.md create mode 100644 freyja_apps/ibeji_adapter/src/main.rs diff --git a/.freyja/config/grpc_proxy_config.json b/.freyja/config/grpc_proxy_config.json new file mode 100644 index 0000000..0d2f8a9 --- /dev/null +++ b/.freyja/config/grpc_proxy_config.json @@ -0,0 +1,3 @@ +{ + "consumer_address": "0.0.0.0:60010" +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index c2aca53..2a2bfe8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -595,6 +595,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "freyja-ibeji-adapter-app" +version = "0.1.0" +dependencies = [ + "freyja", + "ibeji-adapter", + "in-memory-mock-cloud-adapter", + "in-memory-mock-mapping-client", + "tokio", +] + [[package]] name = "freyja-in-memory-app" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index fe600b7..d93cbe1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "cloud_connectors/azure/proto-build", "freyja_adapters/cloud/azure_cloud_connector_adapter", "freyja_adapters/digital_twin/ibeji_adapter", + "freyja_apps/ibeji_adapter", "freyja_apps/in_memory", "freyja_apps/e2e", ] diff --git a/Dockerfile.freyja_apps b/Dockerfile.freyja_apps new file mode 100644 index 0000000..b3c7050 --- /dev/null +++ b/Dockerfile.freyja_apps @@ -0,0 +1,75 @@ +# 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=freyja-in-memory-app +WORKDIR /sdv + +COPY ./ . + +# Add Build dependencies. +RUN apt update && apt upgrade -y && apt install -y \ + 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 -p "${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 + +# 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 + +# Copy the executable from the "build" stage. +COPY --from=build /sdv/service /sdv/ +COPY --from=build /sdv/target/release/build/ /sdv/target/release/build/ + +ENV FREYJA_HOME=/sdv/.freyja + +# What the container should run when it is started. +CMD ["/sdv/service"] diff --git a/container/README.md b/container/README.md new file mode 100644 index 0000000..bcd77d3 --- /dev/null +++ b/container/README.md @@ -0,0 +1,29 @@ +# Container Examples + +This document describes how to utilize the provided Dockerfiles for containerization. + +## Dockerfile Selection + +### Freyja Apps + +To containerize the [Example Freyja Apps](./freyja_apps/), use +[Dockerfile.freyja_apps](../Dockerfile.freyja_apps). This dockerfile defaults to the +[In-Memory Example Application](../freyja_apps/in_memory/). + +Currently the following example applications can be containerized: +- [In-Memory Example Application](../freyja_apps/in_memory/) +- [Ibeji Adapter Example Application](../freyja_apps/ibeji_adapter) + +Each supported application has a README describing the steps to containerize the application. + +### Freyja Cloud Connectors + +Coming soon! + +### Env Files + +To run an application in Docker, ensure that the [docker.env](./config/docker.env) is passed in +when running the container. + +To run an application in Podman, ensure that the [podman.env](./config/podman.env) is passed in +when running the container. diff --git a/container/config/docker.env b/container/config/docker.env new file mode 100644 index 0000000..56bafc6 --- /dev/null +++ b/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/container/config/podman.env b/container/config/podman.env new file mode 100644 index 0000000..1abc4a3 --- /dev/null +++ b/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/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml b/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml index 4f97adc..fa7c2ef 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml +++ b/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml @@ -28,4 +28,7 @@ tonic = { workspace = true } tower = { workspace = true } [build-dependencies] -freyja-build-common = { workspace = true } \ No newline at end of file +freyja-build-common = { workspace = true } + +[features] +containerize = [] diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs index 7c476e0..c6d62e2 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs @@ -2,8 +2,33 @@ // Licensed under the MIT license. // SPDX-License-Identifier: MIT +#![allow(unused_imports)] + +use std::env; use serde::{Deserialize, Serialize}; +/// 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. + const HOST_GATEWAY_ENV_VAR: &str = "HOST_GATEWAY"; + const LOCALHOST_ALIAS_ENV_VAR: &str = "LOCALHOST_ALIAS"; + + // Return an error if container env variables are not set. + let host_gateway = env::var(HOST_GATEWAY_ENV_VAR)?; + let localhost_alias = env::var(LOCALHOST_ALIAS_ENV_VAR)?; // DevSkim: ignore DS162092 + + uri.replace(&localhost_alias, &host_gateway) // DevSkim: ignore DS162092 + }; + + Ok(uri.to_string()) +} + /// Configuration for the Ibeji Adapter. /// Supports two different schemas based on the service discovery method. #[derive(Clone, Serialize, Deserialize)] diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs index 4fb43b5..fc9ad84 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs @@ -23,7 +23,7 @@ use freyja_contracts::{ provider_proxy::OperationKind, }; -use crate::config::{ChariottDiscoverRequest, Config}; +use crate::config::{self, ChariottDiscoverRequest, Config}; const CONFIG_FILE_STEM: &str = "ibeji_adapter_config"; const GET_OPERATION: &str = "Get"; @@ -44,8 +44,10 @@ impl IbejiAdapter { chariott_service_discovery_uri: &str, chariott_discovery_request: ChariottDiscoverRequest, ) -> Result { + let chariott_uri = config::get_uri(chariott_service_discovery_uri).map_err(DigitalTwinAdapterError::io)?; + let mut service_registry_client = - ServiceRegistryClient::connect(String::from(chariott_service_discovery_uri)) + ServiceRegistryClient::connect(chariott_uri) .await .map_err(DigitalTwinAdapterError::communication)?; @@ -121,11 +123,14 @@ impl DigitalTwinAdapter for IbejiAdapter { } }; + let invehicle_digital_twin_uri = config::get_uri(&invehicle_digital_twin_service_uri) + .map_err(DigitalTwinAdapterError::io)?; + let client = futures::executor::block_on(async { execute_with_retry( max_retries, Duration::from_millis(retry_interval_ms), - || InvehicleDigitalTwinClient::connect(invehicle_digital_twin_service_uri.clone()), + || InvehicleDigitalTwinClient::connect(invehicle_digital_twin_uri.clone()), Some(String::from("Connection retry for connecting to Ibeji")), ) .await @@ -196,12 +201,15 @@ impl DigitalTwinAdapter for IbejiAdapter { let operation = OperationKind::from_str(&operation).map_err(DigitalTwinAdapterError::parse_error)?; + + let entity_uri = config::get_uri(&endpoint.uri).map_err(DigitalTwinAdapterError::io)?; + let entity = Entity { id: entity_id, description: Some(entity_access_info.description), name: Some(entity_access_info.name), operation, - uri: endpoint.uri, + uri: entity_uri, protocol: endpoint.protocol, }; diff --git a/freyja_apps/ibeji_adapter/Cargo.toml b/freyja_apps/ibeji_adapter/Cargo.toml new file mode 100644 index 0000000..79d25df --- /dev/null +++ b/freyja_apps/ibeji_adapter/Cargo.toml @@ -0,0 +1,23 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. +# SPDX-License-Identifier: MIT + +[package] +name = "freyja-ibeji-adapter-app" +version = "0.1.0" +edition = "2021" +license = "MIT" + +[dependencies] +# These two dependencies are required for anyone implementing a Freyja application +freyja = { workspace = true } +tokio = { workspace = true, features = ["macros"] } + +# Put any dependencies that you need for your adapters down here. +# This samples utilizes the in-memory mock adapters. +in-memory-mock-cloud-adapter = { workspace = true } +ibeji-adapter = { workspace = true } +in-memory-mock-mapping-client = { workspace = true } + +[features] +containerize = ["ibeji-adapter/containerize"] diff --git a/freyja_apps/ibeji_adapter/README.md b/freyja_apps/ibeji_adapter/README.md new file mode 100644 index 0000000..e7ebd57 --- /dev/null +++ b/freyja_apps/ibeji_adapter/README.md @@ -0,0 +1,102 @@ +# Ibeji Adapter Freyja Example Application + +This Freyja Example Application utilizes the [Ibeji Digital Twin Adapter](../../freyja_adapters/digital_twin/ibeji_adapter/) and an in-memory mock cloud connector adapter to show a minimal connected local example of how to retrieve data from the vehicle. + +## Build and Run + +To build and run the application, follow these steps: + +1. (Optional) If necessary, author configuration overrides for the [`InMemoryMockMappingClient`](https://github.com/eclipse-ibeji/freyja/tree/main/mapping_clients/in_memory_mock_mapping_client). Refer to the adapter README files for instructions on how to do this. This repository provides overrides in the [`.freyja`](../../.freyja/) directory that can be used with the [`mixed` sample provided by Ibeji](https://github.com/eclipse-ibeji/ibeji/tree/main/samples/mixed). + +1. Set the `$FREYJA_HOME` environment variable. If you are using the provided overrides, you can run the following command to set the variable: + + export FREYJA_HOME={path-to-repo-root}/.freyja + + Alternatively, you can set the variable in a [Cargo configuration file](https://doc.rust-lang.org/cargo/reference/config.html) to only enable the variable while running a Cargo command. + +1. Run the following from the repo root: + + cargo run -p freyja-ibeji-adapter-app + + This will rebuild the application as necessary and then run it. Note that running Cargo commands without specifying the `-p` argument might target every package in the workspace! When working with this repository it's recommended to use the `-p` argument with Cargo commands. + +## Containerize the Ibeji Adapter Freyja Example Application + +To build and run the application in a container, follow the steps under [Docker](#docker) or +[Podman](#podman). Ensure that the `$FREYJA_HOME` environment variable is set. + +### 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 freyja_ibeji_adapter --build-arg APP_NAME=freyja-ibeji-adapter-app -f Dockerfile.freyja_apps . + ``` + + The `APP_NAME` build arg needs to be set as `Dockerfile.freyja_apps` defaults to the + [in-memory](../in_memory/) example application. + +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 -v ${FREYJA_HOME}:/sdv/.freyja --name freyja_ibeji_adapter -p 60010:60010 --env-file=./container/config/docker.env --add-host=host.docker.internal:host-gateway -it --rm freyja_ibeji_adapter + ``` + + This command mounts the `$FREYJA_HOME` path set above in the container allowing the application + to use the provided overrides for the mixed sample in Ibeji. + +1. To detach from the container, enter: + + Ctrl + p, Ctrl + q + +1. To stop the container, enter: + + ```shell + docker stop freyja_ibeji_adapter + ``` + +### 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 freyja_ibeji_adapter --build-arg=APP_NAME=freyja-ibeji-adapter-app -f Dockerfile.freyja_apps . + ``` + + The `APP_NAME` build arg needs to be set as `Dockerfile.freyja_apps` defaults to the + [in-memory](../in_memory/) example application. + +1. Once the container has been built, start the container with the following command in the +project's root directory: + + ```shell + podman run --mount=type=bind,src=${FREYJA_HOME},dst=/sdv/.freyja,ro=true -p 60010:60010 --env-file=./container/config/podman.env --network=slirp4netns:allow_host_loopback=true localhost/freyja_ibeji_adapter + ``` + + This command mounts the `$FREYJA_HOME` path set above in the container allowing the application + to use the provided overrides for the mixed sample in Ibeji. + +1. To stop the container, run: + + ```shell + podman ps -f ancestor=localhost/freyja_ibeji_adapter:latest --format="{{.Names}}" | xargs podman stop + ``` diff --git a/freyja_apps/ibeji_adapter/src/main.rs b/freyja_apps/ibeji_adapter/src/main.rs new file mode 100644 index 0000000..d1e72ef --- /dev/null +++ b/freyja_apps/ibeji_adapter/src/main.rs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +// SPDX-License-Identifier: MIT + +use in_memory_mock_cloud_adapter::in_memory_mock_cloud_adapter::InMemoryMockCloudAdapter; +use ibeji_adapter::ibeji_adapter::IbejiAdapter; +use in_memory_mock_mapping_client::in_memory_mock_mapping_client::InMemoryMockMappingClient; + +freyja::freyja_main! { + IbejiAdapter, + InMemoryMockCloudAdapter, + InMemoryMockMappingClient +} diff --git a/freyja_apps/in_memory/Cargo.toml b/freyja_apps/in_memory/Cargo.toml index 68da7d5..0d16d1d 100644 --- a/freyja_apps/in_memory/Cargo.toml +++ b/freyja_apps/in_memory/Cargo.toml @@ -17,4 +17,7 @@ tokio = { workspace = true, features = ["macros"] } # This samples utilizes the in-memory mock adapters. in-memory-mock-cloud-adapter = { workspace = true } in-memory-mock-digital-twin-adapter = { workspace = true } -in-memory-mock-mapping-client = { workspace = true } \ No newline at end of file +in-memory-mock-mapping-client = { workspace = true } + +[features] +containerize = [] diff --git a/freyja_apps/in_memory/README.md b/freyja_apps/in_memory/README.md index d9098b5..d77da11 100644 --- a/freyja_apps/in_memory/README.md +++ b/freyja_apps/in_memory/README.md @@ -15,3 +15,73 @@ This will rebuild the application as necessary and then run it. Note that runnin ## Supported Versions This template is integrated with [revision `a07b033`](https://github.com/eclipse-ibeji/freyja/commit/a07b03349d23b14d0c215ace341e05d9e4e5195e) (authored 2023-11-09) of the Freyja main project. + +## Containerize the In Memory Freyja Example Application + +To build and run the application in a container, follow the steps under [Docker](#docker) or +[Podman](#podman). This is not a very useful example but shows how the application can be +containerized. + +### 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 freyja_in_memory -f Dockerfile.freyja_apps . + ``` + +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 freyja_in_memory -it --rm freyja_in_memory + ``` + +1. To detach from the container, enter: + + Ctrl + p, Ctrl + q + +1. To stop the container, enter: + + ```shell + docker stop freyja_in_memory + ``` + +### 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 freyja_in_memory -f Dockerfile.freyja_apps . + ``` + +1. Once the container has been built, start the container with the following command in the +project's root directory: + + ```shell + podman run localhost/freyja_in_memory + ``` + +1. To stop the container, run: + + ```shell + podman ps -f ancestor=localhost/freyja_in_memory:latest --format="{{.Names}}" | xargs podman stop + ``` From a07cf1c4e173180d813b4ea3d4f8598d267eea20 Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:52:45 -0700 Subject: [PATCH 02/11] Minor README changes --- container/README.md | 4 ++-- freyja_apps/ibeji_adapter/README.md | 12 ++++++------ freyja_apps/in_memory/README.md | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/container/README.md b/container/README.md index bcd77d3..8b0a898 100644 --- a/container/README.md +++ b/container/README.md @@ -8,10 +8,10 @@ This document describes how to utilize the provided Dockerfiles for containeriza To containerize the [Example Freyja Apps](./freyja_apps/), use [Dockerfile.freyja_apps](../Dockerfile.freyja_apps). This dockerfile defaults to the -[In-Memory Example Application](../freyja_apps/in_memory/). +[In Memory Example Application](../freyja_apps/in_memory/). Currently the following example applications can be containerized: -- [In-Memory Example Application](../freyja_apps/in_memory/) +- [In Memory Example Application](../freyja_apps/in_memory/) - [Ibeji Adapter Example Application](../freyja_apps/ibeji_adapter) Each supported application has a README describing the steps to containerize the application. diff --git a/freyja_apps/ibeji_adapter/README.md b/freyja_apps/ibeji_adapter/README.md index e7ebd57..c792ff6 100644 --- a/freyja_apps/ibeji_adapter/README.md +++ b/freyja_apps/ibeji_adapter/README.md @@ -43,7 +43,7 @@ Dockerfile: ``` The `APP_NAME` build arg needs to be set as `Dockerfile.freyja_apps` defaults to the - [in-memory](../in_memory/) example application. + [In Memory Example Application](../in_memory/). 1. Once the container has been built, start the container in interactive mode with the following command in the project's root directory: @@ -52,8 +52,8 @@ command in the project's root directory: docker run -v ${FREYJA_HOME}:/sdv/.freyja --name freyja_ibeji_adapter -p 60010:60010 --env-file=./container/config/docker.env --add-host=host.docker.internal:host-gateway -it --rm freyja_ibeji_adapter ``` - This command mounts the `$FREYJA_HOME` path set above in the container allowing the application - to use the provided overrides for the mixed sample in Ibeji. + `-v` mounts the `$FREYJA_HOME` path set above in the container allowing the application to use + the provided overrides for the mixed sample in Ibeji. 1. To detach from the container, enter: @@ -83,7 +83,7 @@ Dockerfile: ``` The `APP_NAME` build arg needs to be set as `Dockerfile.freyja_apps` defaults to the - [in-memory](../in_memory/) example application. + [In Memory Example Application](../in_memory/). 1. Once the container has been built, start the container with the following command in the project's root directory: @@ -92,8 +92,8 @@ project's root directory: podman run --mount=type=bind,src=${FREYJA_HOME},dst=/sdv/.freyja,ro=true -p 60010:60010 --env-file=./container/config/podman.env --network=slirp4netns:allow_host_loopback=true localhost/freyja_ibeji_adapter ``` - This command mounts the `$FREYJA_HOME` path set above in the container allowing the application - to use the provided overrides for the mixed sample in Ibeji. + `-v` mounts the `$FREYJA_HOME` path set above in the container allowing the application to use + the provided overrides for the mixed sample in Ibeji. 1. To stop the container, run: diff --git a/freyja_apps/in_memory/README.md b/freyja_apps/in_memory/README.md index d77da11..3068e09 100644 --- a/freyja_apps/in_memory/README.md +++ b/freyja_apps/in_memory/README.md @@ -43,7 +43,7 @@ Dockerfile: command in the project's root directory: ```shell - docker run --name freyja_in_memory -it --rm freyja_in_memory + docker run --name freyja_in_memory --env-file=./container/config/docker.env -it --rm freyja_in_memory ``` 1. To detach from the container, enter: @@ -77,7 +77,7 @@ Dockerfile: project's root directory: ```shell - podman run localhost/freyja_in_memory + podman run --env-file=./container/config/podman.env localhost/freyja_in_memory ``` 1. To stop the container, run: From 12a47c880cd90aec3133bfa069caa730a1c83f0f Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:57:15 -0700 Subject: [PATCH 03/11] update get_uri to use variables rather than consts --- .../digital_twin/ibeji_adapter/src/config.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs index c6d62e2..1375e83 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs @@ -16,14 +16,14 @@ pub fn get_uri(uri: &str) -> Result Date: Thu, 26 Oct 2023 19:08:16 -0700 Subject: [PATCH 04/11] Resolve fmt warnings --- .../digital_twin/ibeji_adapter/src/config.rs | 2 +- .../digital_twin/ibeji_adapter/src/ibeji_adapter.rs | 10 +++++----- freyja_apps/ibeji_adapter/src/main.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs index 1375e83..3db6161 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs @@ -4,8 +4,8 @@ #![allow(unused_imports)] -use std::env; use serde::{Deserialize, Serialize}; +use std::env; /// 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. diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs index fc9ad84..afef5f2 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs @@ -44,12 +44,12 @@ impl IbejiAdapter { chariott_service_discovery_uri: &str, chariott_discovery_request: ChariottDiscoverRequest, ) -> Result { - let chariott_uri = config::get_uri(chariott_service_discovery_uri).map_err(DigitalTwinAdapterError::io)?; + let chariott_uri = + config::get_uri(chariott_service_discovery_uri).map_err(DigitalTwinAdapterError::io)?; - let mut service_registry_client = - ServiceRegistryClient::connect(chariott_uri) - .await - .map_err(DigitalTwinAdapterError::communication)?; + let mut service_registry_client = ServiceRegistryClient::connect(chariott_uri) + .await + .map_err(DigitalTwinAdapterError::communication)?; let discover_request = Request::new(DiscoverRequest { namespace: chariott_discovery_request.namespace, diff --git a/freyja_apps/ibeji_adapter/src/main.rs b/freyja_apps/ibeji_adapter/src/main.rs index d1e72ef..595df94 100644 --- a/freyja_apps/ibeji_adapter/src/main.rs +++ b/freyja_apps/ibeji_adapter/src/main.rs @@ -2,8 +2,8 @@ // Licensed under the MIT license. // SPDX-License-Identifier: MIT -use in_memory_mock_cloud_adapter::in_memory_mock_cloud_adapter::InMemoryMockCloudAdapter; use ibeji_adapter::ibeji_adapter::IbejiAdapter; +use in_memory_mock_cloud_adapter::in_memory_mock_cloud_adapter::InMemoryMockCloudAdapter; use in_memory_mock_mapping_client::in_memory_mock_mapping_client::InMemoryMockMappingClient; freyja::freyja_main! { From 3bbca954258765117596538e07a37325ba8b6d34 Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:07:08 -0700 Subject: [PATCH 05/11] Fix grammar error in comment --- freyja_adapters/digital_twin/ibeji_adapter/src/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs index 3db6161..b6613e3 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/config.rs @@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize}; use std::env; -/// 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 feature 'containerize' is set, it 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. From 0a2052e34260f281217bfc100486e3c3af391fb5 Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:37:57 -0700 Subject: [PATCH 06/11] removed syntax ref in Dockerfile --- Dockerfile.freyja_apps | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile.freyja_apps b/Dockerfile.freyja_apps index b3c7050..e70c8c8 100644 --- a/Dockerfile.freyja_apps +++ b/Dockerfile.freyja_apps @@ -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/ From 0befb99de2eb2336260660c1bf741125f363eff6 Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:17:15 -0700 Subject: [PATCH 07/11] Updated readme's to be more concise --- freyja_apps/e2e/README.md | 2 +- freyja_apps/ibeji_adapter/README.md | 2 +- freyja_apps/in_memory/README.md | 2 +- freyja_apps/template/README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/freyja_apps/e2e/README.md b/freyja_apps/e2e/README.md index dc8bfbc..a9952c7 100644 --- a/freyja_apps/e2e/README.md +++ b/freyja_apps/e2e/README.md @@ -18,4 +18,4 @@ To build and run the application, follow these steps: cargo run -p freyja-e2e-app - This will rebuild the application as necessary and then run it. Note that running Cargo commands without specifying the `-p` argument might target every package in the workspace! When working with this repository it's recommended to use the `-p` argument with Cargo commands. + This will rebuild the `freyja-e2e-app` application as necessary and then run it. diff --git a/freyja_apps/ibeji_adapter/README.md b/freyja_apps/ibeji_adapter/README.md index c792ff6..dd6380b 100644 --- a/freyja_apps/ibeji_adapter/README.md +++ b/freyja_apps/ibeji_adapter/README.md @@ -18,7 +18,7 @@ To build and run the application, follow these steps: cargo run -p freyja-ibeji-adapter-app - This will rebuild the application as necessary and then run it. Note that running Cargo commands without specifying the `-p` argument might target every package in the workspace! When working with this repository it's recommended to use the `-p` argument with Cargo commands. + This will rebuild the `freyja-ibeji-adapter-app` application as necessary and then run it. ## Containerize the Ibeji Adapter Freyja Example Application diff --git a/freyja_apps/in_memory/README.md b/freyja_apps/in_memory/README.md index 3068e09..9162fb5 100644 --- a/freyja_apps/in_memory/README.md +++ b/freyja_apps/in_memory/README.md @@ -10,7 +10,7 @@ To build and run the application, run the following from the repo root: cargo run -p freyja-in-memory-app ``` -This will rebuild the application as necessary and then run it. Note that running Cargo commands without specifying the `-p` argument might target every package in the workspace! When working with this repository it's recommended to use the `-p` argument with Cargo commands. +This will rebuild the `freyja-in-memory-app` application as necessary and then run it. ## Supported Versions diff --git a/freyja_apps/template/README.md b/freyja_apps/template/README.md index 208399a..3583676 100644 --- a/freyja_apps/template/README.md +++ b/freyja_apps/template/README.md @@ -19,4 +19,4 @@ To create your own Freyja application, you can copy this template and make the f 1. Import your adapters with `use` statements. 1. Change the type names in the `freyja_main!` macro invocation to your imported types. Order matters here, so make sure you list your adapters in the same order as they are presented in the template. -To build and run your application, you can use Cargo commands such as `cargo run`. +To build and run your application, you can use Cargo commands such as `cargo run`. When working with this repository it's recommended to use the `-p` argument followed by the application package name with Cargo commands. Note that running Cargo commands without specifying the `-p` argument might target every package in the workspace! From c1f1523f50f30b9446540052d6e771550c811258 Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:23:05 -0700 Subject: [PATCH 08/11] updated toolchain to specific version --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 31578d3..82ccade 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "stable" \ No newline at end of file +channel = "1.72.1" \ No newline at end of file From 4d863b59afa2077e3834d415b0a073700eb43425 Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:36:11 -0700 Subject: [PATCH 09/11] Fix whitespace errors --- freyja_apps/ibeji_adapter/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freyja_apps/ibeji_adapter/README.md b/freyja_apps/ibeji_adapter/README.md index dd6380b..f43aa85 100644 --- a/freyja_apps/ibeji_adapter/README.md +++ b/freyja_apps/ibeji_adapter/README.md @@ -53,7 +53,7 @@ command in the project's root directory: ``` `-v` mounts the `$FREYJA_HOME` path set above in the container allowing the application to use - the provided overrides for the mixed sample in Ibeji. + the provided overrides for the mixed sample in Ibeji. 1. To detach from the container, enter: @@ -93,7 +93,7 @@ project's root directory: ``` `-v` mounts the `$FREYJA_HOME` path set above in the container allowing the application to use - the provided overrides for the mixed sample in Ibeji. + the provided overrides for the mixed sample in Ibeji. 1. To stop the container, run: From 5f7cbabeb139705e2acf95398f5877a22c30242c Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:37:58 -0700 Subject: [PATCH 10/11] fixed bad link --- container/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container/README.md b/container/README.md index 8b0a898..c104e08 100644 --- a/container/README.md +++ b/container/README.md @@ -6,7 +6,7 @@ This document describes how to utilize the provided Dockerfiles for containeriza ### Freyja Apps -To containerize the [Example Freyja Apps](./freyja_apps/), use +To containerize the [Example Freyja Apps](../freyja_apps/), use [Dockerfile.freyja_apps](../Dockerfile.freyja_apps). This dockerfile defaults to the [In Memory Example Application](../freyja_apps/in_memory/). From 50382f3509a572988e87c9c6f5b9ff084d0047f7 Mon Sep 17 00:00:00 2001 From: Devin Kelley <105753233+devkelley@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:42:47 -0700 Subject: [PATCH 11/11] fixed spacing issue --- container/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/container/README.md b/container/README.md index c104e08..4c42e89 100644 --- a/container/README.md +++ b/container/README.md @@ -11,6 +11,7 @@ To containerize the [Example Freyja Apps](../freyja_apps/), use [In Memory Example Application](../freyja_apps/in_memory/). Currently the following example applications can be containerized: + - [In Memory Example Application](../freyja_apps/in_memory/) - [Ibeji Adapter Example Application](../freyja_apps/ibeji_adapter)