Skip to content

Commit

Permalink
feat: add env param support
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaringe committed Mar 24, 2023
1 parent 2cb7f21 commit 23053bb
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Expand Up @@ -8,3 +8,4 @@ _esy
esy.lock
node_modules
public
target
20 changes: 20 additions & 0 deletions Dockerfile
@@ -0,0 +1,20 @@
FROM rust as base
RUN apt-get install libssl-dev openssl
WORKDIR /app

FROM base as chef
RUN cargo install cargo-chef

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS build
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build -p agent --release

FROM base as release
COPY --from=build /app/target/release/agent ./
ENTRYPOINT [ "./agent" ]
Empty file removed Dockerfile.agent
Empty file.
2 changes: 1 addition & 1 deletion crates/libagent/Cargo.toml
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
# chrono = "0.4.24"
clap = "4.1.11"
clap = { version = "4.1.11", features = ["env"] }
libawair = { path = "../libawair" }
tokio = { version = "1.26.0", features = ["full"] }
tokio-postgres = "0.7.7"
Expand Down
12 changes: 6 additions & 6 deletions crates/libagent/src/config.rs
Expand Up @@ -3,17 +3,17 @@ use clap::Parser;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Config {
#[arg(long)]
#[arg(long, env = "AWAIR_ENDPOINT")]
pub awair_endpoint: Vec<String>,
#[arg(long)]
#[arg(long, env = "DB_HOST")]
pub db_host: String,
#[arg(long)]
#[arg(long, env = "DB_PORT", default_value_t = 5432)]
pub db_port: u16,
#[arg(long, default_value = "fresh")]
#[arg(long, env = "DB_USER", default_value = "fresh")]
pub db_user: String,
#[arg(long, default_value = "fresh")]
#[arg(long, env = "DB_PASSWORD", default_value = "fresh")]
pub db_password: String,
#[arg(long, default_value_t = 60)]
#[arg(long, env = "POLL_DURATION_S", default_value_t = 60)]
pub poll_duration_s: u16,
}

Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Expand Up @@ -21,11 +21,12 @@ services:
delay: 300s
window: 120s
freshagent:
image: cdaringe/freshawair:agent
image: cdaringe/freshawair
networks:
- fresh
init: true
command: ./Agent.exe --poll-duration=60 --db-host=freshdb
command: |
./agent --db-host=freshdb --awair-endpoint=http://192.168.3.2/air-data/latest --awair-endpoint=http://192.168.3.3/air-data/latest
restart: "on-failure"
logging:
driver: json-file
Expand Down
2 changes: 1 addition & 1 deletion rad.ts
Expand Up @@ -3,7 +3,7 @@ import { tasks as dbTasks } from "./.rad/db.ts";
import { deploy } from "./.rad/deploy.ts";
import { format } from "./.rad/format.ts";

const build = `dune build`;
const build = `docker build -t cdaringe/freshawair .`;

const startAgent: Task = [
"cargo run -p agent --",
Expand Down
22 changes: 20 additions & 2 deletions readme.md
Expand Up @@ -19,10 +19,28 @@ Host and view your [Awair data](https://www.getawair.com/) locally.

## usage

At the current time, even though there are [docker images](https://hub.docker.com/repository/docker/cdaringe/freshawair) available, the only supported mechanism for building is following:
At the current time, even though there are [docker images](https://hub.docker.com/repository/docker/cdaringe/freshawair) available.

```sh
$ docker run --rm -it cdaringe/freshawair --help
Usage: agent [OPTIONS] --db-host <DB_HOST> --db-port <DB_PORT>

Options:
--awair-endpoint <AWAIR_ENDPOINT>
--db-host <DB_HOST>
--db-port <DB_PORT>
--db-user <DB_USER> [default: fresh]
--db-password <DB_PASSWORD> [default: fresh]
--poll-duration-s <POLL_DURATION_S> [default: 60]
-h, --help Print help
-V, --version Print version
```

You can also use the UPPER_CASE vars as ENV vars to set values

The only supported mechanism for building is following:

- install [rad](https://github.com/cdaringe/rad#install)
- `docker-compose build`
- `docker-compose -f docker-compose.yml -f docker-compose.dev.yml up`
- visit grafana@[localhost:3000](https://localhost:3000) and select the prebuilt dashboard

Expand Down

0 comments on commit 23053bb

Please sign in to comment.