Improve configuration

This commit is contained in:
Tobias Reisinger 2024-04-29 04:19:02 +02:00
parent 71498256f6
commit ace4face5a
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
9 changed files with 66 additions and 51 deletions

View file

@ -1,3 +1,3 @@
#EMGAUWA_CONTROLLER_LOGGING_LEVEL=INFO
#EMGAUWA_CONTROLLER__LOGGING__LEVEL=DEBUG
#EMGAUWA_CORE_LOGGING_LEVEL=INFO
#EMGAUWA_CORE__LOGGING__LEVEL=DEBUG

2
.gitignore vendored
View file

@ -1,4 +1,5 @@
/target
/pkl-out
/.env
/api.http
@ -6,3 +7,4 @@
/emgauwa-*.sqlite
/emgauwa-*.sqlite-*
/emgauwa-*.json

View file

@ -1,11 +1,3 @@
ifneq (,$(wildcard ./.env))
include .env
export
endif
DATABASE_URL ?= sqlite://emgauwa-dev.sqlite
export DATABASE_URL
sqlx:
cargo sqlx database drop -y
cargo sqlx database create
@ -15,13 +7,16 @@ sqlx:
build-rpi:
cross build --target arm-unknown-linux-gnueabihf
emgauwa-%.json: config/emgauwa-%.pkl config/lib/%.pkl config/lib/common.pkl $(wildcard .env)
emgauwa-%.json: config/%.pkl config/lib/%.pkl
pkl eval -f json -o $@ $<
configs:
$(MAKE) emgauwa-core.json
$(MAKE) emgauwa-controller.json
pkl-package:
pkl project package config --output-path "./pkl-out"
clean:
rm -f emgauwa-controller.json
rm -f emgauwa-controller.sqlite

8
config/PklProject Normal file
View file

@ -0,0 +1,8 @@
amends "pkl:Project"
package {
name = "emgauwa"
baseUri = "package://emgauwa.app/pkl/\(name)"
version = "0.1.0"
packageZipUrl = "https://emgauwa.app/pkl/\(name)@\(version).zip"
}

View file

@ -0,0 +1,4 @@
{
"schemaVersion": 1,
"resolvedDependencies": {}
}

View file

@ -13,59 +13,61 @@ permissions {
}
logging {
level = read?("env:EMGAUWA_CONTROLLER_LOGGING_LEVEL") ?? "DEBUG"
level = "INFO"
file = "stdout"
}
relays {
new {
driver = "null"
pin = 24
inverted = true
}
new {
driver = "null"
pin = 23
inverted = true
}
new {
driver = "null"
pin = 22
inverted = true
}
new {
driver = "null"
pin = 27
inverted = true
}
new {
driver = "null"
pin = 18
inverted = true
}
new {
driver = "null"
pin = 17
inverted = true
}
new {
driver = "null"
pin = 15
inverted = true
}
new {
driver = "null"
pin = 14
pin = 0
inverted = true
}
new {
driver = "null"
pin = 1
inverted = true
}
new {
driver = "null"
pin = 2
inverted = true
}
new {
driver = "null"
pin = 3
inverted = true
}
new {
driver = "null"
pin = 4
inverted = true
}
new {
driver = "null"
pin = 5
inverted = true
}
new {
driver = "null"
pin = 10
inverted = true
pulse = 10
}
new {
driver = "null"
pin = 11
inverted = true
pulse = 10
}
new {
driver = "null"
pin = 20
inverted = false
}
new {
driver = "null"
pin = 0
pin = 21
inverted = false
}
}

View file

@ -13,6 +13,6 @@ permissions {
}
logging {
level = read?("env:EMGAUWA_CORE_LOGGING_LEVEL") ?? "DEBUG"
level = "INFO"
file = "stdout"
}

View file

@ -12,5 +12,6 @@ class RelayConfig {
driver: "null"|"gpio"|"piface"
pin: Number
inverted: Boolean
pulse: Number(this >= 0)|Null = null
}
relays: Listing<RelayConfig>

View file

@ -49,9 +49,12 @@ pub fn load<T>(config_name: &str, env_prefix: &str) -> Result<T, EmgauwaError>
where
for<'de> T: serde::Deserialize<'de>,
{
let etc_file =
config::File::with_name(&format!("/etc/emgauwa/{}", config_name)).required(false);
let local_file = config::File::with_name(&format!("./emgauwa-{}", config_name)).required(false);
config::Config::builder()
.add_source(etc_file)
.add_source(local_file)
.add_source(
config::Environment::with_prefix(&format!("EMGAUWA_{}", env_prefix))