Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor horust to its own crate #251

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ jobs:
with:
use-cross: true
command: build
args: --release --all --target ${{ matrix.target }}
# TODO: There should be a step to build horustctl.
args: --release --package horust --bin horust --target ${{ matrix.target }}

- name: Package
shell: bash
Expand Down
47 changes: 1 addition & 46 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,47 +1,2 @@
[package]
name = "horust"
version = "0.1.8"
authors = ["Federico Ponzi <[email protected]>"]
description = "A complete supervisor and init system, designed for running in containers."
edition = "2021"
license = "MIT"
repository = "https://github.com/FedericoPonzi/horust"
homepage = "https://github.com/FedericoPonzi/horust"
readme = "README.md"
keywords = ["init", "container", "supervisor"]
categories = ["command-line-utilities"]
include = ["src/**/*", "Cargo.*", "LICENSE.txt", "README.md", "/example_services/**/*"]

[dependencies]
clap = { version = "~4.5", features = ["derive"] }
crossbeam = "~0.8"
env_logger = "~0.11"
humantime-serde = "~1.1"
libc = "~0.2"
log = "~0.4"
nix = { version = "~0.29", features = ["process", "user", "signal", "fs"] }
reqwest = { version = "~0.12", features = ["blocking", "json"], optional = true, default-features = false }
serde = { version = "~1.0", features = ["derive"] }
shlex = "~1.3"
toml = "~0.8"
maplit = "~1.0"
shellexpand = "~3.1"
anyhow = "~1.0"
thiserror = "~1.0"
bytefmt = "0.1.7"

[features]
default = ["http-healthcheck"]
http-healthcheck = ["reqwest"]

[dev-dependencies]
assert_cmd = "~2.0"
predicates = "~3.1"
tempdir = "~0.3"
rand = "~0.8"

[profile.release]
strip = "symbols"

[workspace]
members = ["horustctl", "commands"]
members = ["commands", "horust", "horustctl"]
1 change: 0 additions & 1 deletion commands/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod proto;

use anyhow::{bail, Context, Result};
use proto::tutorial::*;
use std::path::{Path, PathBuf};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{UnixListener, UnixStream};
Expand All @@ -11,7 +10,7 @@
socket: UnixStream,
}
impl CommandsUdsConnectionHandler {
fn get_path(socket_folder: &Path, socket_name: u32) -> PathBuf {

Check warning on line 13 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

associated function `get_path` is never used

Check warning on line 13 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

associated function `get_path` is never used

Check warning on line 13 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

associated function `get_path` is never used

Check warning on line 13 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

associated function `get_path` is never used

Check warning on line 13 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

associated function `get_path` is never used

Check warning on line 13 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

associated function `get_path` is never used
socket_folder.join(format!("hourst-{socket_name}.sock"))
}
fn new(socket: UnixStream) -> Self {
Expand Down Expand Up @@ -79,7 +78,7 @@
loop {
self.accept().await?;
}
Ok(())

Check warning on line 81 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unreachable expression

Check warning on line 81 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unreachable expression

Check warning on line 81 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

unreachable expression

Check warning on line 81 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

unreachable expression

Check warning on line 81 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unreachable expression

Check warning on line 81 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unreachable expression
}
pub async fn accept(&mut self) -> Result<()> {
match self.unix_listener.accept().await {
Expand All @@ -100,9 +99,9 @@
}
}

fn create_uds() {}

Check warning on line 102 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

function `create_uds` is never used

Check warning on line 102 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

function `create_uds` is never used

Check warning on line 102 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

function `create_uds` is never used

Check warning on line 102 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

function `create_uds` is never used

Check warning on line 102 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

function `create_uds` is never used

Check warning on line 102 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

function `create_uds` is never used

fn listen_uds() {}

Check warning on line 104 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

function `listen_uds` is never used

Check warning on line 104 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

function `listen_uds` is never used

Check warning on line 104 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

function `listen_uds` is never used

Check warning on line 104 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

function `listen_uds` is never used

Check warning on line 104 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

function `listen_uds` is never used

fn send_message() {}

Check warning on line 106 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

function `send_message` is never used

Check warning on line 106 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

function `send_message` is never used

Check warning on line 106 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

function `send_message` is never used

Check warning on line 106 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

function `send_message` is never used

Check warning on line 106 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

function `send_message` is never used
fn receive_message() {}

Check warning on line 107 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

function `receive_message` is never used

Check warning on line 107 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

function `receive_message` is never used

Check warning on line 107 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

function `receive_message` is never used

Check warning on line 107 in commands/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

function `receive_message` is never used
2 changes: 1 addition & 1 deletion commands/src/proto/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod tutorial;

12 changes: 11 additions & 1 deletion commands/src/proto/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ pub mod person {
#[prost(enumeration = "PhoneType", tag = "2")]
pub r#type: i32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum PhoneType {
Mobile = 0,
Expand Down
44 changes: 44 additions & 0 deletions horust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "horust"
version = "0.1.8"
authors = ["Federico Ponzi <[email protected]>"]
description = "A complete supervisor and init system, designed for running in containers."
edition = "2021"
license = "MIT"
repository = "https://github.com/FedericoPonzi/horust"
homepage = "https://github.com/FedericoPonzi/horust"
readme = "README.md"
keywords = ["init", "container", "supervisor"]
categories = ["command-line-utilities"]
include = ["src/**/*", "Cargo.*", "LICENSE.txt", "README.md", "/example_services/**/*"]

[dependencies]
clap = { version = "~4.5", features = ["derive"] }
crossbeam = "~0.8"
env_logger = "~0.11"
humantime-serde = "~1.1"
libc = "~0.2"
log = "~0.4"
nix = { version = "~0.29", features = ["process", "user", "signal", "fs"] }
reqwest = { version = "~0.12", features = ["blocking", "json"], optional = true, default-features = false }
serde = { version = "~1.0", features = ["derive"] }
shlex = "~1.3"
toml = "~0.8"
maplit = "~1.0"
shellexpand = "~3.1"
anyhow = "~1.0"
thiserror = "~1.0"
bytefmt = "0.1.7"

[features]
default = ["http-healthcheck"]
http-healthcheck = ["reqwest"]

[dev-dependencies]
assert_cmd = "~2.0"
predicates = "~3.1"
tempdir = "~0.3"
rand = "~0.8"

[profile.release]
strip = "symbols"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{env, os::fd::RawFd};
use crate::horust::error::{ValidationError, ValidationErrors};

pub fn get_sample_service() -> &'static str {
include_str!("../../../example_services/sample_service.toml")
include_str!("../../../../example_services/sample_service.toml")
}

pub type ServiceName = String;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ mod tests {
#[test]
fn should_deserialize() {
// TODO: this shouldn't be an integration test, but rather a unit test.
// CARGO_MANIFEST_DIR points to the position of the innermost Cargo.toml
let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let services_path = base.join("example_services");
let services_path = base.join("../example_services");
println!("base: {base:?}");
let services = list_files(&services_path).unwrap().len();
let horust = Horust::from_services_dirs(&[services_path]).unwrap();
assert_eq!(horust.get_services().len(), services);
Expand Down
File renamed without changes.
Loading