Skip to content

Commit

Permalink
Merge pull request #46 from AssetsArt/fest-config
Browse files Browse the repository at this point in the history
Fest config
  • Loading branch information
Aitthi authored Mar 9, 2024
2 parents be05685 + 0afae76 commit 44f4737
Show file tree
Hide file tree
Showing 19 changed files with 1,140 additions and 533 deletions.
2 changes: 1 addition & 1 deletion .config/easy_proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pingora:
# https://github.com/cloudflare/pingora/blob/main/docs/user_guide/daemon.md
daemon: true
# https://github.com/cloudflare/pingora/blob/main/docs/user_guide/conf.md
threads: 4
threads: 6
# work_stealing: true
# error_log: /var/log/pingora/error.log
# pid_file: /run/pingora.pid
Expand Down
147 changes: 133 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
resolver = "2"

members = [
"runtime",
"easy-proxy",
"proxy",
"config"
]
Expand All @@ -22,7 +22,12 @@ fnv = "1"
http = "1"
notify = "6.1"
matchit = "0.7"
ahash = "0.8"
ahash = { version="0.8", features = ["serde"] }
lazy_static = "1.4"
once_cell = "1.19"
tokio = { version="1", features = ["rt-multi-thread"] }
clap = { version="4.5", features = ["derive"] }


[profile.release]
strip = true
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ENV TZ=Asia/Bangkok

WORKDIR /app
# copy app release
COPY --from=builder /app/target/release/runtime ./easy-proxy
COPY --from=builder /app/target/release/easy-proxy ./easy-proxy
COPY .config .config

# default run entrypoint
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ pingora:
# ca_file: /etc/ssl/certs/ca-certificates.crt
```

Can be tested and reloaded using the following commands:
```bash
$ easy-proxy -t # Test the configuration file
$ easy-proxy -r # Reload the configuration file
```

### Service and Route Configuration
```yaml
# Select the service to be proxied
Expand Down
7 changes: 6 additions & 1 deletion config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ fnv = { workspace = true }
notify = { workspace = true }
matchit = { workspace = true }
tracing = { workspace = true }
ahash = { workspace = true }
ahash = { workspace = true }
lazy_static = { workspace = true }
once_cell = { workspace = true }
anyhow = { workspace = true }
tokio = { workspace = true }
http = { workspace = true }
39 changes: 1 addition & 38 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,2 @@
pub mod models;
pub mod proxy;

// use
use std::sync::Once;
use std::{fs::File, io::BufReader};

// This is a global variable that is initialized once
static INIT_CONFIG: Once = Once::new();
static mut GLOBAL_CONFIG: *const models::AppConfig = std::ptr::null();

pub fn app_config() -> &'static models::AppConfig {
INIT_CONFIG.call_once(|| {
// FROM ENV
let conf_path = std::env::var("EASY_PROXY_CONF");
let conf_path = match conf_path {
Ok(val) => val,
Err(_e) => {
let conf_path = std::env::current_dir().expect("Unable to get current dir");
conf_path
.join(".config/easy_proxy.yaml")
.to_str()
.expect("Unable to convert path")
.to_string()
}
};

let open_conf = File::open(conf_path).expect("Unable to open file");
let read_conf = BufReader::new(open_conf);
let conf: models::AppConfig =
serde_yaml::from_reader(read_conf).expect("Unable to read conf file");

unsafe {
GLOBAL_CONFIG = Box::into_raw(Box::new(conf));
}
});

unsafe { &*GLOBAL_CONFIG }
}
pub mod runtime;
Loading

0 comments on commit 44f4737

Please sign in to comment.