Skip to content

Commit

Permalink
WIP - feat(docker): add docker field to disable modifying location to…
Browse files Browse the repository at this point in the history
… config.toml

Signed-off-by: Riccardo Gallo <riccardo.gallo@secomind.com>
  • Loading branch information
rgallor committed Dec 12, 2024
1 parent 07ea282 commit c574aa9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ toml = "0.8.12"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.0", features = ["env-filter"]}
uuid = { version = "1.10.0", features = ["v4", "serde"] }

[features]
docker = []
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ To run the container with your configuration file:
1. Ensure you have defined your astarte configuration file `config.toml`
2. Run the Docker container, mounting the configuration file:
```sh
docker run -v /path/to/your/config.toml:<MOUNT_TO_THIS_PATH> -e ASTARTE_CONFIG_PATH="<MOUNT_TO_THIS_PATH>" stream-rust-test:latest
docker run -v /path/to/your/config.toml:/etc/stream-rust-test/ stream-rust-test:latest
```

Replace `/path/to/your/config.toml` with the actual path to your configuration file.

Note: `MOUNT_TO_THIS_PATH` must be an absolute path.
Note: do not set the `ASTARTE_CONFIG_PATH` environment variable when running the docker container, since it should only
be used when running locally.

#### Run the container with environment variables

Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
use crate::math::MathFunction;
use clap::Parser;
use std::path::PathBuf;

/// Configuration for the values to be sent to Astarte
#[derive(Debug, Clone, Parser)]
#[clap(version, about)]
pub struct Config {
#[cfg(not(feature = "docker"))]
/// Path to the directory containing the Astarte configuration file config.toml
///
/// First, the Astarte configuration is taken from ENV vars, then from the config.toml if the
/// path has been specified
#[clap(short, long, env = "ASTARTE_CONFIG_PATH")]
pub astarte_config_path: Option<PathBuf>,
pub astarte_config_path: Option<std::path::PathBuf>,
/// Math function the device will use to send data to Astarte
#[clap(short, long, default_value = "default", env = "MATH_FUNCTION")]
pub math_function: MathFunction,
Expand Down
13 changes: 9 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ async fn main() -> eyre::Result<()> {
if let Err(err) = astarte_cfg_builder.try_from_env() {
warn!("failed to retrieve Astarte connection config from ENV: {err}");

if let Some(path) = &cli_cfg.astarte_config_path {
let path = path.join("config.toml");
info!("retrieve Astarte connection config from {}", path.display());

if cfg!(feature = "docker") {
let path = std::path::PathBuf::from("/etc/stream-rust-test/config.toml");
astarte_cfg_builder.from_toml(path).await;
} else {
if let Some(path) = &cli_cfg.astarte_config_path {
let path = path.join("config.toml");
info!("retrieve Astarte connection config from {}", path.display());

astarte_cfg_builder.from_toml(path).await;
}
}
};

Expand Down

0 comments on commit c574aa9

Please sign in to comment.