Skip to content

Commit

Permalink
fix(ctl): add RUN command
Browse files Browse the repository at this point in the history
  • Loading branch information
wqld committed Jan 31, 2025
1 parent 9c4fe80 commit 4911f02
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM --platform=$BUILDPLATFORM rust:1 AS builder

# export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc
# export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-linux-musl-gcc
# cargo build --release --target aarch64-unknown-linux-musl -p agent
# cargo build --release --target x86_64-unknown-linux-musl -p agent
# docker build --push --platform linux/amd64,linux/arm64 -t ghcr.io/wqld/pmz-agent:0.1.0 .
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,17 @@ A different method will be used for future releases:

- `tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.provenance'`

Next, let's start the `pmz` daemon.
### Usage

First, let's start the `pmz-daemon`.
Since `pmz` uses eBPF, you need to specify your local machine's network interface so it knows where to load the eBPF program:

```sh
./pmz --iface eth0
> pmzctl run --interface eth0
Running..
```

### Usage

First, deploy the `pmz-agent` to your Kubernetes cluster:
Next, open a new shell and deploy the `pmz-agent` to your Kubernetes cluster:

```sh
> pmzctl agent deploy
Expand Down
24 changes: 24 additions & 0 deletions ctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ struct Cli {

#[derive(Debug, Subcommand)]
enum Commands {
Run(RunArgs),
Agent(AgentArgs),
Connect,
Disconnect,
Dns(DnsArgs),
}

#[derive(Debug, Args, Serialize)]
struct RunArgs {
#[arg(short, long, default_value = "eth0")]
interface: String,
}

#[derive(Debug, Args)]
struct AgentArgs {
#[command(subcommand)]
Expand Down Expand Up @@ -80,6 +87,10 @@ async fn main() -> Result<()> {
let args = Cli::parse();

match args.command {
Commands::Run(args) => {
debug!("pmzctl run with {args:?}");
run_daemon(&args).await?;
}
Commands::Agent(agent) => match agent.command {
AgentCommands::Deploy(args) => {
debug!("pmzctl agent deploy");
Expand Down Expand Up @@ -120,6 +131,19 @@ async fn main() -> Result<()> {
Ok(())
}

async fn run_daemon(args: &RunArgs) -> Result<()> {
let mut daemon = tokio::process::Command::new("./pmz")
.args(&["--iface", &args.interface])
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.spawn()?;

println!("Running..");
let _ = daemon.wait().await;

Ok(())
}

async fn send_request_to_daemon(method: Method, uri: &str, body_opt: Option<String>) -> Result<()> {
let path = Path::new("/tmp/pmz.sock");
let stream = UnixStream::connect(path).await?;
Expand Down

0 comments on commit 4911f02

Please sign in to comment.