diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml new file mode 100644 index 000000000..d8d0ad660 --- /dev/null +++ b/.github/workflows/builds.yml @@ -0,0 +1,96 @@ +name: ⚃ Builds + +on: + workflow_dispatch: + inputs: + force-builds: + required: true + type: boolean + description: Publish Builds at Anytime + + pull_request: + branches: [ '**' ] + + release: + types: [published] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + +jobs: + builds: + strategy: + fail-fast: false + matrix: + include: + - target: aarch64-unknown-linux-gnu + - target: aarch64-unknown-linux-musl + - target: aarch64-apple-darwin + os: macos-latest + - target: x86_64-unknown-linux-gnu + - target: x86_64-unknown-linux-musl + - target: x86_64-apple-darwin + os: macos-latest + - target: x86_64-pc-windows-msvc + os: windows-latest + - target: x86_64-unknown-freebsd + + timeout-minutes: 60 + runs-on: ${{ matrix.os || 'ubuntu-latest' }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install OpenSSL + if: startsWith(matrix.os, 'ubuntu') + run: sudo apt update && sudo apt install -y libssl-dev + + - name: Install musl-tools + run: sudo apt update && sudo apt install -y musl-dev musl-tools + if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl' + + - name: Cache Project + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + shared-key: check-${{ matrix.platform.target }}-${{ matrix.platform.os }} + save-if: ${{ github.event_name == 'push' }} + + - name: Install Rust Toolchain + id: toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Override rust-toolchain.toml + run: rustup override set ${{steps.toolchain.outputs.name}} + + - name: cross-build + uses: taiki-e/setup-cross-toolchain-action@v1 + with: + target: ${{ matrix.target }} + + - name: crt-static + run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >>"${GITHUB_ENV}" + if: endsWith(matrix.target, 'windows-msvc') + + - name: Build Binary + run: cargo build -p homestar-runtime --target ${{ matrix.target }} --locked --release + + - name: Publish Release Artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.target }} + path: target/${{ matrix.target }}/release/homestar* + if-no-files-found: error + + - uses: taiki-e/upload-rust-binary-action@v1 + with: + bin: homestar + target: ${{ matrix.target }} + tar: all + zip: windows + include: LICENSE,README.md + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 000000000..96f2da9ca --- /dev/null +++ b/Cross.toml @@ -0,0 +1,19 @@ +[build.env] +passthrough = [ + "CARGO_INCREMENTAL", + "RUST_BACKTRACE", + "CARGO_TERM_COLOR", + "RUSTFLAGS", +] + +[target.x86_64-unknown-linux-musl] +image = "messense/rust-musl-cross:x86_64-musl" + +[target.aarch64-unknown-linux-musl] +image = "messense/rust-musl-cross:aarch64-musl" + +[target.x86_64-apple-darwin] +image = "freeznet/x86_64-apple-darwin-cross:11.3" + +[target.aarch64-apple-darwin] +image = "freeznet/aarch64-apple-darwin-cross:11.3" diff --git a/flake.lock b/flake.lock index 0514ad768..edcb403fd 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1696267196, - "narHash": "sha256-AAQ/2sD+0D18bb8hKuEEVpHUYD1GmO2Uh/taFamn6XQ=", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", "owner": "edolstra", "repo": "flake-compat", - "rev": "4f910c9827911b1ec2bf26b5a062cd09f8d89f85", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { @@ -36,11 +36,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1696234590, - "narHash": "sha256-mgOzQYTvaTT4bFopVOadlndy2RPwLy60rDjIWOGujwo=", + "lastModified": 1696577711, + "narHash": "sha256-94VRjvClIKDym1QRqPkX5LTQoAwZ1E6QE/3dWtOXSIQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f902cb49892d300ff15cb237e48aa1cad79d68c3", + "rev": "a2eb207f45e4a14a1e3019d9e3863d1e208e2295", "type": "github" }, "original": { @@ -68,11 +68,11 @@ ] }, "locked": { - "lastModified": 1696212720, - "narHash": "sha256-kuI/n1LpXv9S1wXfIzvYJudBfQeF0YGS4G8xJQQxM/M=", + "lastModified": 1696558324, + "narHash": "sha256-TnnP4LGwDB8ZGE7h2n4nA9Faee8xPkMdNcyrzJ57cbw=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "1aaa2dc3e7367f2014f939c927e9e768a0cc2f08", + "rev": "fdb37574a04df04aaa8cf7708f94a9309caebe2b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 0069f766e..bbffa9607 100644 --- a/flake.nix +++ b/flake.nix @@ -32,7 +32,14 @@ rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { extensions = ["cargo" "clippy" "rustfmt" "rust-src" "rust-std"]; - targets = ["wasm32-unknown-unknown" "wasm32-wasi"]; + targets = [ + "wasm32-unknown-unknown" + "wasm32-wasi" + "x86_64-apple-darwin" + "aarch64-apple-darwin" + "x86_64-unknown-linux-musl" + "aarch64-unknown-linux-musl" + ]; }; nightly-rustfmt = pkgs.rust-bin.nightly.latest.rustfmt; @@ -45,6 +52,7 @@ cargo-installs = with pkgs; [ cargo-deny + cargo-cross cargo-expand cargo-nextest cargo-outdated @@ -53,6 +61,7 @@ cargo-unused-features cargo-udeps cargo-watch + rustup twiggy wasm-tools ]; diff --git a/homestar-runtime/Cargo.toml b/homestar-runtime/Cargo.toml index 775eafda0..21783eacb 100644 --- a/homestar-runtime/Cargo.toml +++ b/homestar-runtime/Cargo.toml @@ -23,7 +23,6 @@ autotests = false path = "src/lib.rs" bench = false doctest = true -crate-type = ["cdylib", "rlib"] [[bin]] name = "homestar" diff --git a/homestar-runtime/src/network/swarm.rs b/homestar-runtime/src/network/swarm.rs index 72837161a..0ec8ed136 100644 --- a/homestar-runtime/src/network/swarm.rs +++ b/homestar-runtime/src/network/swarm.rs @@ -120,7 +120,7 @@ pub(crate) fn init( swarm.listen_on(settings.listen_address.to_string().parse()?)?; // add external addresses from settings - if settings.announce_addresses.is_empty() { + if !settings.announce_addresses.is_empty() { for addr in settings.announce_addresses.iter() { swarm.add_external_address(addr.clone()); } diff --git a/homestar-runtime/tests/cli.rs b/homestar-runtime/tests/cli.rs index dc0c6c6be..0657e0e55 100644 --- a/homestar-runtime/tests/cli.rs +++ b/homestar-runtime/tests/cli.rs @@ -5,7 +5,7 @@ use anyhow::Result; use assert_cmd::prelude::*; use once_cell::sync::Lazy; use predicates::prelude::*; -use retry::{delay::Fixed, retry}; +use retry::{delay::Exponential, retry}; use serial_test::file_serial; use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr, TcpStream}, @@ -143,8 +143,8 @@ fn test_server_serial() -> Result<()> { .spawn() .unwrap(); - let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 9998); - let result = retry(Fixed::from_millis(1000).take(10), || { + let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 9991); + let result = retry(Exponential::from_millis(1000).take(10), || { TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both)) }); @@ -158,7 +158,7 @@ fn test_server_serial() -> Result<()> { .arg("--host") .arg("::1") .arg("-p") - .arg("9998") + .arg("9991") .assert() .success() .stdout(predicate::str::contains("::1")) @@ -205,14 +205,16 @@ fn test_workflow_run_serial() -> Result<()> { let mut homestar_proc = Command::new(BIN.as_os_str()) .arg("start") + .arg("-c") + .arg("tests/fixtures/test_workflow.toml") .arg("--db") .arg("homestar.db") .stdout(Stdio::piped()) .spawn() .unwrap(); - let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 3030); - let result = retry(Fixed::from_millis(1000).take(30), || { + let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 9888); + let result = retry(Exponential::from_millis(1000).take(20), || { TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both)) }); @@ -223,6 +225,8 @@ fn test_workflow_run_serial() -> Result<()> { Command::new(BIN.as_os_str()) .arg("run") + .arg("-p") + .arg("9888") .arg("-w") .arg("tests/fixtures/test-workflow-add-one.json") .assert() @@ -239,6 +243,8 @@ fn test_workflow_run_serial() -> Result<()> { // run another one of the same! Command::new(BIN.as_os_str()) .arg("run") + .arg("-p") + .arg("9888") .arg("-w") .arg("tests/fixtures/test-workflow-add-one.json") .assert() @@ -289,7 +295,7 @@ fn test_daemon_serial() -> Result<()> { .success(); let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9997); - let result = retry(Fixed::from_millis(1000).take(10), || { + let result = retry(Exponential::from_millis(1000).take(10), || { TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both)) }); @@ -332,7 +338,7 @@ fn test_signal_kill_serial() -> Result<()> { .unwrap(); let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 3030); - let result = retry(Fixed::from_millis(1000).take(10), || { + let result = retry(Exponential::from_millis(1000).take(10), || { TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both)) }); @@ -386,7 +392,7 @@ fn test_server_v4_serial() -> Result<()> { .unwrap(); let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9999); - let result = retry(Fixed::from_millis(1000).take(30), || { + let result = retry(Exponential::from_millis(1000).take(20), || { TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both)) }); @@ -443,7 +449,7 @@ fn test_daemon_v4_serial() -> Result<()> { .success(); let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9999); - let result = retry(Fixed::from_millis(1000).take(30), || { + let result = retry(Exponential::from_millis(1000).take(20), || { TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both)) }); diff --git a/homestar-runtime/tests/fixtures/test_v4.toml b/homestar-runtime/tests/fixtures/test_v4.toml index 37bdce126..f4536b6cd 100644 --- a/homestar-runtime/tests/fixtures/test_v4.toml +++ b/homestar-runtime/tests/fixtures/test_v4.toml @@ -1,3 +1,7 @@ +[monitoring] +process_collector_interval = 500 +metrics_port = 4010 + [node] [node.network] diff --git a/homestar-runtime/tests/fixtures/test_v6.toml b/homestar-runtime/tests/fixtures/test_v6.toml index 2e35703f4..938a30b2c 100644 --- a/homestar-runtime/tests/fixtures/test_v6.toml +++ b/homestar-runtime/tests/fixtures/test_v6.toml @@ -6,5 +6,5 @@ metrics_port = 4006 [node.network] events_buffer_len = 1000 -rpc_port = 9998 +rpc_port = 9991 rpc_host = "::1" diff --git a/homestar-runtime/tests/metrics.rs b/homestar-runtime/tests/metrics.rs index 889b5dc11..1eb1463cc 100644 --- a/homestar-runtime/tests/metrics.rs +++ b/homestar-runtime/tests/metrics.rs @@ -2,7 +2,7 @@ use crate::utils::{stop_homestar, BIN_NAME}; use anyhow::Result; use once_cell::sync::Lazy; use reqwest::StatusCode; -use retry::{delay::Fixed, retry, OperationResult}; +use retry::{delay::Exponential, retry, OperationResult}; use serial_test::file_serial; use std::{ net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpStream}, @@ -20,7 +20,7 @@ const METRICS_URL: &str = "http://localhost:4004"; fn test_metrics_serial() -> Result<()> { fn sample_metrics() -> prometheus_parse::Value { let body = retry( - Fixed::from_millis(1000).take(10), + Exponential::from_millis(1000).take(10), || match reqwest::blocking::get(METRICS_URL) { Ok(response) => match response.status() { StatusCode::OK => OperationResult::Ok(response.text()), @@ -57,7 +57,7 @@ fn test_metrics_serial() -> Result<()> { .unwrap(); let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 4004); - let result = retry(Fixed::from_millis(1000).take(10), || { + let result = retry(Exponential::from_millis(1000).take(10), || { TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both)) }); @@ -68,7 +68,7 @@ fn test_metrics_serial() -> Result<()> { let sample1 = sample_metrics(); - let sample2 = retry(Fixed::from_millis(500).take(3), || { + let sample2 = retry(Exponential::from_millis(500).take(3), || { let sample2 = sample_metrics(); if sample1 != sample2 { OperationResult::Ok(sample2)