Skip to content

Commit eeaba5d

Browse files
committed
run rmqtt and agent successfully, add github action for agent
1 parent 5957111 commit eeaba5d

File tree

15 files changed

+146
-160
lines changed

15 files changed

+146
-160
lines changed

.github/workflows/ci.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: CI
2+
on:
3+
# push:
4+
# tags:
5+
# - '*'
6+
workflow_dispatch:
7+
jobs:
8+
build_bin:
9+
strategy:
10+
max-parallel: 1
11+
fail-fast: true
12+
matrix:
13+
settings:
14+
- host: ubuntu-latest
15+
target: x86_64-unknown-linux-gnu
16+
build: make release-linux
17+
- host: macos-latest
18+
target: aarch64-apple-darwin
19+
build: make release-mac-aarch64
20+
- host: macos-12
21+
target: x86_64-apple-darwin
22+
build: make release-mac-x86_64
23+
# - host: macos-latest # This needs aarch64 OpenSSL, will wait github action support MacOS M1(https://github.com/github/roadmap/issues/528), then run this.
24+
# target: aarch64-apple-darwin
25+
# build: make release-mac-aarch64
26+
runs-on: ${{ matrix.settings.host }}
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
submodules: true
31+
- name: Install Rust
32+
uses: actions-rs/toolchain@v1
33+
with:
34+
toolchain: stable
35+
target: ${{ matrix.settings.target }}
36+
profile: minimal
37+
- name: Set up cargo cache
38+
uses: actions/cache@v3
39+
continue-on-error: false
40+
with:
41+
path: |
42+
~/.cargo/bin/
43+
~/.cargo/registry/index/
44+
~/.cargo/registry/cache/
45+
~/.cargo/git/db/
46+
client/target/
47+
key: ${{ matrix.settings.host }}-${{ matrix.settings.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
48+
restore-keys: ${{ matrix.settings.host }}-cargo-${{ matrix.settings.target }}
49+
# - name: Setup tmate session
50+
# uses: mxschmitt/action-tmate@v3
51+
- name: Build
52+
run: ${{ matrix.settings.build }}
53+
54+
- name: Upload artifact
55+
uses: actions/upload-artifact@v2
56+
with:
57+
name: mproxy-${{ matrix.settings.target }}
58+
path: release/*
59+
if-no-files-found: error

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.PHONY: release-mac-x86_64, release-mac-aarch64, release-linux, release-linux-aarch64
2+
3+
name = mproxy
4+
rust_path = agent
5+
release-mac-x86_64:
6+
mkdir -p release
7+
cd $(rust_path) && cargo build --release --target=x86_64-apple-darwin
8+
strip $(rust_path)/target/x86_64-apple-darwin/release/$(name)
9+
otool -L $(rust_path)/target/x86_64-apple-darwin/release/$(name)
10+
cp $(rust_path)/target/x86_64-apple-darwin/release/mproxy ./release/
11+
12+
# brew install wget
13+
release-mac-aarch64:
14+
mkdir -p release
15+
cd $(rust_path) && cargo build --release --target=aarch64-apple-darwin
16+
strip $(rust_path)/target/aarch64-apple-darwin/release/$(name)
17+
otool -L $(rust_path)/target/aarch64-apple-darwin/release/$(name)
18+
cp $(rust_path)/target/aarch64-apple-darwin/release/$(name) ./release/
19+
20+
release-linux-aarch64:
21+
sudo apt-get install -y build-essential
22+
mkdir release
23+
cd $(rust_path) && cargo build --release --target=aarch64-unknown-linux-gnu
24+
strip $(rust_path)/target/aarch64-unknown-linux-gnu/release/$(name)
25+
cp $(rust_path)/target/aarch64-unknown-linux-gnu/release/$(name) ./release/
26+
27+
28+
release-linux:
29+
sudo apt-get install -y build-essential
30+
mkdir release
31+
cd $(rust_path) && cargo build --release --target=x86_64-unknown-linux-gnu
32+
strip $(rust_path)/target/x86_64-unknown-linux-gnu/release/$(name)
33+
cp $(rust_path)/target/x86_64-unknown-linux-gnu/release/$(name) ./release

agent/Cargo.lock

Lines changed: 0 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ rumqttc = { version = "0.24", features = ["use-rustls", "url"] }
1313

1414
tokio-rustls = "0.26"
1515
clap = { version = "4.5", features = ["derive"] }
16-
auto-launch-extra = {version = "0.5", package = "auto-launch"}
17-
18-
#cmd_lib = "1.9" # this only support macro
19-
shell-candy = "0.4"
16+
#auto-launch-extra = {version = "0.5", package = "auto-launch"}
2017

2118
anyhow = "1"
2219

agent/config.toml

Whitespace-only changes.

agent/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server: 'mqtt://127.0.0.1:1883'
2+
client_id: test_client

agent/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,10 @@ mod test {
5555
pub fn get_default_config_path_test() {
5656
println!("{:?}", Config::get_default_config_path());
5757
}
58+
59+
#[test]
60+
pub fn test_config_serial() {
61+
let config = Config::new(Some("./config.yml".parse().unwrap())).unwrap();
62+
println!("{:?}", config)
63+
}
5864
}

agent/src/connection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub struct Connection {
1717

1818
impl Connection {
1919
pub async fn connect(config:Arc<Config>) -> anyhow::Result<(Self, EventLoop)>{
20-
21-
let mut options = MqttOptions::parse_url(&config.server).with_context(|| format!("parser mqtt url fail: {:?}", config.server))?;
20+
let mqtt_url = format!("{}?client_id={}", &config.server, &config.client_id);
21+
let mut options = MqttOptions::parse_url(&mqtt_url).with_context(|| format!("parser mqtt url fail: {:?}", &mqtt_url))?;
2222

2323
match (&config.password, &config.username) {
2424
(Some(pass), Some(user)) => {
@@ -36,7 +36,7 @@ impl Connection {
3636
}, eventloop))
3737
}
3838
pub async fn publish_response(&self, topic:&String, message:ResponseMessage) -> Result<(), ClientError> {
39-
self.client.publish(topic, QoS::ExactlyOnce, false, serde_json::to_vec(&message).unwrap())
39+
self.client.publish(topic, QoS::ExactlyOnce, false, serde_json::to_vec(&message).unwrap()).await
4040
}
4141

4242
pub async fn loop_event(mut event_loop: EventLoop, mut shutdown_rx:broadcast::Receiver<bool>, mqtt_tx: broadcast::Sender<(String, RequestMessage)>) {

agent/src/handler.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use std::io::{BufRead, BufReader};
22
use serde::{Deserialize, Serialize};
3-
use shell_candy::{ShellTask, ShellTaskBehavior};
43
use tokio::sync::broadcast;
5-
use tracing::{debug, info};
4+
use tracing::{info};
65
use crate::connection::Connection;
76
use std::process::Command;
8-
use std::sync::Arc;
9-
use crate::config::Config;
107

118

129
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -43,6 +40,7 @@ impl Handler {
4340
pub async fn run(&mut self, _shutdown_rx:broadcast::Receiver<bool>) {
4441

4542
while let Ok((_, cmd)) = self.cmd_rx.recv().await {
43+
info!("begin to handle cmd: {:?}",&cmd);
4644
match cmd {
4745
RequestMessage::Cmd { command,request_id } => {
4846
let mut seq:u32 = 1;
@@ -65,7 +63,6 @@ impl Handler {
6563
}
6664
}
6765
}
68-
info!("begin to handle cmd: {:?}",cmd);
6966
}
7067
}
7168
}
@@ -77,7 +74,7 @@ mod test {
7774
use std::time::Duration;
7875

7976
use super::RequestMessage;
80-
use shell_candy::{ShellTaskLog, ShellTaskBehavior, ShellTask};
77+
8178

8279
#[test]
8380
fn test_serde() {
@@ -100,17 +97,5 @@ mod test {
10097
child.kill().unwrap()
10198

10299
}
103-
#[test]
104-
pub fn parse2() {
105-
let task = ShellTask::new(r#"ls"#).unwrap();
106100

107-
let z = task.run(|line| {
108-
match line {
109-
ShellTaskLog::Stdout(message) | ShellTaskLog::Stderr(message) => eprintln!("{}", &message),
110-
}
111-
ShellTaskBehavior::<()>::Passthrough
112-
});
113-
println!("{z:?}");
114-
115-
}
116101
}

0 commit comments

Comments
 (0)