From 8cccc82fc23783851501387f510d865060288142 Mon Sep 17 00:00:00 2001 From: plazmoid Date: Sat, 26 Jun 2021 16:46:16 +0500 Subject: [PATCH] static linking tests --- .cargo/config.toml | 8 +++++++- bin/u_agent/Cargo.toml | 2 +- bin/u_agent/src/lib.rs | 2 +- bin/u_panel/Cargo.toml | 2 +- bin/u_server/Cargo.toml | 1 + bin/u_server/src/db.rs | 2 +- bin/u_server/src/main.rs | 4 ++++ integration/docker-compose.yml | 12 +++++------- integration/utils.py | 4 ++-- lib/u_lib/Cargo.toml | 2 +- lib/u_lib/src/api.rs | 4 ++-- lib/u_lib/src/config.rs | 5 ++--- lib/u_lib/src/lib.rs | 1 + scripts/cargo_musl.sh | 11 +++++++++++ 14 files changed, 40 insertions(+), 20 deletions(-) create mode 100755 scripts/cargo_musl.sh diff --git a/.cargo/config.toml b/.cargo/config.toml index f4c53ee..3b6d0f8 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,9 @@ [build] target = "x86_64-unknown-linux-musl" -rustflags = ["-C", "target-feature=+crt-static"] + +[target.x86_64-unknown-linux-musl] +rustflags = [ + "-Ctarget-feature=+crt-static", + "-Clink-args=-Istatic/include", + "-L", "static/lib", +] diff --git a/bin/u_agent/Cargo.toml b/bin/u_agent/Cargo.toml index 6b8d8f2..85cc2d9 100644 --- a/bin/u_agent/Cargo.toml +++ b/bin/u_agent/Cargo.toml @@ -13,7 +13,7 @@ log = "^0.4" env_logger = "0.8.3" uuid = "0.6.5" reqwest = { version = "0.11", features = ["json"] } -openssl = { version = "0.10.32", features = ["vendored"] } +openssl = "*" u_lib = { version = "*", path = "../../lib/u_lib" } [[test]] diff --git a/bin/u_agent/src/lib.rs b/bin/u_agent/src/lib.rs index 6138b36..74bb353 100644 --- a/bin/u_agent/src/lib.rs +++ b/bin/u_agent/src/lib.rs @@ -73,7 +73,7 @@ pub async fn run_forever() { //daemonize(); env_logger::init(); let arg_ip = env::args().nth(1); - let instance = ClientHandler::new(arg_ip); + let instance = ClientHandler::new(arg_ip.as_deref()); info!("Connecting to the server"); loop { let job_requests: Vec = diff --git a/bin/u_panel/Cargo.toml b/bin/u_panel/Cargo.toml index 66bb469..d712325 100644 --- a/bin/u_panel/Cargo.toml +++ b/bin/u_panel/Cargo.toml @@ -13,5 +13,5 @@ log = "^0.4" env_logger = "0.7.1" uuid = "0.6.5" reqwest = { version = "0.11", features = ["json"] } -openssl = { version = "0.10.32", features = ["vendored"] } +openssl = "*" u_lib = { version = "*", path = "../../lib/u_lib" } diff --git a/bin/u_server/Cargo.toml b/bin/u_server/Cargo.toml index 0b0ccd6..2b53483 100644 --- a/bin/u_server/Cargo.toml +++ b/bin/u_server/Cargo.toml @@ -15,6 +15,7 @@ once_cell = "1.7.2" hyper = "0.13.10" mockall = "0.9.1" mockall_double = "0.2" +openssl = "*" [dependencies.diesel] features = ["postgres", "uuid"] diff --git a/bin/u_server/src/db.rs b/bin/u_server/src/db.rs index e06b48e..9fa0d0c 100644 --- a/bin/u_server/src/db.rs +++ b/bin/u_server/src/db.rs @@ -21,7 +21,7 @@ static DB: OnceCell>> = OnceCell::new(); impl UDB { pub fn lock_db() -> MutexGuard<'static, UDB> { DB.get_or_init(|| { - dotenv().unwrap(); + dotenv().ok(); let db_path = env::var("DATABASE_URL").unwrap(); let conn = PgConnection::establish(&db_path).unwrap(); let instance = UDB { conn }; diff --git a/bin/u_server/src/main.rs b/bin/u_server/src/main.rs index b15a418..a6ac83b 100644 --- a/bin/u_server/src/main.rs +++ b/bin/u_server/src/main.rs @@ -1,3 +1,7 @@ +extern crate openssl; +#[macro_use] +extern crate diesel; + use u_server::serve; #[tokio::main] diff --git a/integration/docker-compose.yml b/integration/docker-compose.yml index e72acdc..c4c3ec6 100644 --- a/integration/docker-compose.yml +++ b/integration/docker-compose.yml @@ -2,17 +2,13 @@ version: "2.1" networks: u_net: - ipam: - config: - - subnet: 10.16.0.0/24 services: u_server: image: unki/u_server networks: - u_net: - ipv4_address: 10.16.0.200 + - u_net volumes: - ../target/x86_64-unknown-linux-musl/release/u_server:/u_server - ./.env:/.env @@ -29,6 +25,8 @@ services: image: postgres:13.3 networks: - u_net + volumes: + - ../data:/var/lib/postgresql/data expose: - '5432' environment: @@ -40,7 +38,7 @@ services: - u_net volumes: - ../target/x86_64-unknown-linux-musl/release/u_agent:/u_agent - command: /u_agent 10.16.0.200 + command: /u_agent u_server depends_on: u_server: condition: service_started @@ -51,7 +49,7 @@ services: - u_net volumes: - ../target/x86_64-unknown-linux-musl/release/u_agent:/u_agent - command: /u_agent 10.16.0.200 + command: /u_agent u_server depends_on: u_server: condition: service_started diff --git a/integration/utils.py b/integration/utils.py index 6fc8019..0015df2 100644 --- a/integration/utils.py +++ b/integration/utils.py @@ -8,9 +8,9 @@ class TestsError(Exception): COLORS = { - 'question': colored('[?]', 'yellow'), + 'question': colored('[?]', 'magenta'), 'info': colored('[~]', 'green'), - 'warning': colored('[!]', 'magenta'), + 'warning': colored('[!]', 'yellow'), 'error': colored('[X]', 'red'), } diff --git a/lib/u_lib/Cargo.toml b/lib/u_lib/Cargo.toml index 5351c4c..70b0743 100644 --- a/lib/u_lib/Cargo.toml +++ b/lib/u_lib/Cargo.toml @@ -14,7 +14,7 @@ libc = "^0.2" lazy_static = "1.4.0" tokio = { version = "1.2.0", features = ["rt-multi-thread", "sync", "macros", "process", "time"] } reqwest = { version = "0.11", features = ["json"] } -openssl = { version = "0.10.32", features = ["vendored"] } +openssl = "*" futures = "0.3.5" guess_host_triple = "0.1.2" thiserror = "*" diff --git a/lib/u_lib/src/api.rs b/lib/u_lib/src/api.rs index 5e0cd3c..13e6d4e 100644 --- a/lib/u_lib/src/api.rs +++ b/lib/u_lib/src/api.rs @@ -18,9 +18,9 @@ pub struct ClientHandler { } impl ClientHandler { - pub fn new(server: Option) -> Self { + pub fn new(server: Option<&str>) -> Self { let master_server = server - .map(|s| Ipv4Addr::from_str(&s).unwrap()) + //.map(|s| Ipv4Addr::from_str(&s).unwrap()) .unwrap_or(MASTER_SERVER); Self { client: Client::new(), diff --git a/lib/u_lib/src/config.rs b/lib/u_lib/src/config.rs index 7db464c..88fc795 100644 --- a/lib/u_lib/src/config.rs +++ b/lib/u_lib/src/config.rs @@ -1,9 +1,8 @@ -use std::net::Ipv4Addr; use uuid::Uuid; -pub const MASTER_SERVER: Ipv4Addr = Ipv4Addr::LOCALHOST; //Ipv4Addr::new(3,9,16,40) +pub const MASTER_SERVER: &str = "127.0.0.1"; //Ipv4Addr::new(3,9,16,40) pub const MASTER_PORT: u16 = 63714; lazy_static! { pub static ref UID: Uuid = Uuid::new_v4(); -} \ No newline at end of file +} diff --git a/lib/u_lib/src/lib.rs b/lib/u_lib/src/lib.rs index 00d1c18..a5be8b0 100644 --- a/lib/u_lib/src/lib.rs +++ b/lib/u_lib/src/lib.rs @@ -20,6 +20,7 @@ pub mod schema_exports { #[macro_use] extern crate lazy_static; +extern crate openssl; #[macro_use] extern crate diesel; diff --git a/scripts/cargo_musl.sh b/scripts/cargo_musl.sh new file mode 100755 index 0000000..b2c6abf --- /dev/null +++ b/scripts/cargo_musl.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e +source $(dirname $0)/rootdir.sh #set ROOTDIR +docker run \ + -v $ROOTDIR:/volume \ + -v cargo-cache:/root/.cargo/registry \ + -w /volume \ + -it \ + test/musllibs \ + cargo $@ +