Skip to content

Commit

Permalink
v0.2.2 and plugin-v2024083101
Browse files Browse the repository at this point in the history
  • Loading branch information
MXWXZ committed Aug 31, 2024
1 parent 3bd92dd commit 6903a2d
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 59 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 0.2.2
## Bug fix
1. Fix postgres backend bug.

# plugin-2024083101
## Components
- agent: 0.2.1 => 0.3.0
- skynet_api_agent: 0.2.1 => 0.3.0
- monitor: 0.2.1 => 0.2.2

## New features
1. `agent`: Support `restart` option.
2. `monitor`, `skynet_api_agent`: Version check will depend on `agent` version instead of `skynet_api_agent` version.

# 0.2.1
## Bug fix
1. Fix `no process-level CryptoProvider` for rustls 0.23.
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 47 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
SHELL = /bin/bash
OUTPUT_DIR = $$(pwd)/bin
TARGET_DIR = $$(pwd)/target
BUILD_TYPE = debug
TARGET_DIR = $$(pwd)/target/$(BUILD_TYPE)
PLUGIN_DIR = $$(pwd)/plugin
EXE_SUFFIX =
PLUGIN_SUFFIX =

ifeq ($(OS),Windows_NT)
EXE_SUFFIX = .exe
PLUGIN_SUFFIX = .dll
else
UNAME_S := $(shell uname -s)
Expand All @@ -17,7 +20,7 @@ else
endif

.ONESHELL:
.PHONY: check build run dev static clean help
.PHONY: check build build_release run dev static clean help

all: help

Expand All @@ -26,57 +29,69 @@ check:
@cargo clippy -- -D clippy::all
@cargo fmt --all -- --check

## build: Build skynet(dev).
## build: Build skynet(debug).
build:
@echo Building...
@cargo build

## build_release: Build skynet(release).
build_release:
@cargo build --locked --release

## output: Output build files from TARGET_DIR to OUTPUT_DIR (bin), not delete OUTPUT_DIR.
output:
@echo OUTPUT_DIR=$(OUTPUT_DIR)
@echo TARGET_DIR=$(TARGET_DIR)
@echo Output Skynet...
@mkdir -p $(OUTPUT_DIR)
@cp conf.dev.yml $(OUTPUT_DIR)/conf.yml
@cp conf.yml $(OUTPUT_DIR)
@cp conf.schema.json $(OUTPUT_DIR)
@cp default.webp $(OUTPUT_DIR)
@cp $(TARGET_DIR)/debug/skynet $(OUTPUT_DIR)
@mkdir -p $(OUTPUT_DIR)/plugin
@for d in `ls $(PLUGIN_DIR)`;do \
if [ -f $(PLUGIN_DIR)/$$d/config.yml ];then \
mkdir -p $(OUTPUT_DIR)/plugin/$$d; \
cp $(TARGET_DIR)/debug/lib$$d$(PLUGIN_SUFFIX) $(OUTPUT_DIR)/plugin/$$d; \
cp $(PLUGIN_DIR)/$$d/config.yml $(OUTPUT_DIR)/plugin/$$d; \
@cp $(TARGET_DIR)/skynet$(EXE_SUFFIX) $(OUTPUT_DIR)
@rm -rf $(OUTPUT_DIR)/plugin && mkdir -p $(OUTPUT_DIR)/plugin
@for d in `ls $(PLUGIN_DIR)`;do \
if [ -f $(PLUGIN_DIR)/$$d/config.yml ];then \
echo Output $$d...; \
o=$(OUTPUT_DIR)/plugin/$$d; \
rm -rf $$o && mkdir -p $$o; \
cp $(TARGET_DIR)/lib$$d$(PLUGIN_SUFFIX) $$o; \
cp $(PLUGIN_DIR)/$$d/config.yml $$o; \
if [ -f $(PLUGIN_DIR)/$$d/Makefile ];then \
t=$(TARGET_DIR); \
o=$(OUTPUT_DIR)/plugin/$$d; \
pushd . > /dev/null; \
pushd . > /dev/null; \
t=$(TARGET_DIR); \
cd $(PLUGIN_DIR)/$$d; \
make --no-print-directory build TARGET_DIR=$$t OUTPUT_DIR=$$o; \
popd > /dev/null; \
fi \
fi \
make --no-print-directory output TARGET_DIR=$$t OUTPUT_DIR=$$o; \
popd > /dev/null; \
fi \
fi \
done
@echo Success

## run: Run skynet (dev).
run: build
## run: Run skynet (debug).
run: build output
@cp conf.dev.yml $(OUTPUT_DIR)/conf.yml
@cd $(OUTPUT_DIR) && RUST_BACKTRACE=1 ./skynet run -v --persist-session --disable-csrf

## dev: Run dev server, auto reload on save.
dev:
@cargo watch -i frontend -- make run

## static: Make static files.
## static: Build static files, delete assets folders.
static:
@echo OUTPUT_DIR=$(OUTPUT_DIR)
@echo Building Skynet...
@cd ./skynet/frontend && yarn && yarn build
@mkdir -p $(OUTPUT_DIR)
@rm -rf $(OUTPUT_DIR)/assets
@cp -r ./skynet/frontend/dist/. $(OUTPUT_DIR)/assets && mkdir $(OUTPUT_DIR)/assets/_plugin
@for d in `ls $(PLUGIN_DIR)`;do \
if [ -d $(PLUGIN_DIR)/$$d/frontend ];then \
@for d in `ls $(PLUGIN_DIR)`;do \
if [[ -f $(PLUGIN_DIR)/$$d/Makefile && -f $(PLUGIN_DIR)/$$d/config.yml ]];then \
echo Building $$d...; \
id=`cat $(PLUGIN_DIR)/$$d/config.yml | head -n 1 | cut -d \" -f 2`; \
mkdir -p $(OUTPUT_DIR)/assets/_plugin/$$id; \
pushd . > /dev/null; \
cd $(PLUGIN_DIR)/$$d/frontend; \
yarn build; \
popd > /dev/null; \
cp -r $(PLUGIN_DIR)/$$d/frontend/dist/. $(OUTPUT_DIR)/assets/_plugin/$$id; \
fi \
o=$(OUTPUT_DIR)/assets/_plugin/$$id; \
pushd . > /dev/null; \
cd $(PLUGIN_DIR)/$$d; \
make --no-print-directory static OUTPUT_DIR=$$o; \
popd > /dev/null; \
fi \
done

## clean: Clean all build files.
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ We offer pre-built `x86_64` and `aarch64` docker images.
### Pre-built libraries
You can download pre-built libraries in our [release](https://github.com/MXWXZ/skynet/releases) page.

We offer linux-{x86_64,i686,aarch64}, darwin-{x86_64,aarch64} and windows-x86_64 binaries. You might build from source if your platform is not included.
We offer `linux-{x86_64,i686,aarch64}`, `darwin-{x86_64,aarch64}` and `windows-x86_64` binaries. You might build from source if your platform is not included.

```
make build_release
make output BUILD_TYPE=release
make static
```

You are ready to go with files in `bin` :)

### Create initial user

Expand Down
6 changes: 2 additions & 4 deletions plugin/agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[package]
name = "agent"
version = "0.2.1"
version = "0.3.0"
edition = "2021"
authors = ["MXWXZ <[email protected]>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.16", features = ["derive"] }
derivative = "2.2.0"
Expand All @@ -23,7 +21,7 @@ thiserror = "1.0.63"
aes-gcm = "0.10.3"

skynet_api_monitor = { version = "0.2.0", path = "../monitor_api" }
skynet_api_agent = { version = "0.2.0", path = "../agent_api" }
skynet_api_agent = { version = "0.3.0", path = "../agent_api" }
skynet_api = { path = "../../skynet_api" }

[lib]
Expand Down
4 changes: 2 additions & 2 deletions plugin/agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ else
endif
endif

build:
output:
@mkdir -p $(OUTPUT_DIR)/bin
@cp $(TARGET_DIR)/debug/agent $(OUTPUT_DIR)/bin/agent_$(PLATFORM)_$(MACHINE)$(SUFFIX);
@cp $(TARGET_DIR)/agent$(SUFFIX) $(OUTPUT_DIR)/bin/agent_$(PLATFORM)_$(MACHINE)$(SUFFIX);
21 changes: 15 additions & 6 deletions plugin/agent/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct ConnectionState {
disable_shell: bool,
ip: Option<IpAddr>,
output: Option<UnboundedSender<Data>>,
restart: bool,
}

impl ConnectionState {
Expand All @@ -71,6 +72,7 @@ impl ConnectionState {
disable_shell: bool,
disk: Vec<String>,
interface: Vec<String>,
restart: bool,
) -> Self {
Self {
client_seq: 0,
Expand All @@ -87,6 +89,7 @@ impl ConnectionState {
report_rate,
disable_shell,
ip,
restart,
}
}

Expand Down Expand Up @@ -162,7 +165,7 @@ fn input_handler(

async fn update_handler(
frame: &mut Frame,
_state: &mut ConnectionState,
state: &mut ConnectionState,
data: UpdateMessage,
) -> Result<Option<Result<()>>> {
let exe = env::current_exe()?;
Expand All @@ -175,11 +178,15 @@ async fn update_handler(
fs::remove_file(new_path)?;
let _ = frame.close().await;
info!(crc32 = crc, "Trigger update");
return Command::new(exe)
.args(env::args().skip(1))
.spawn()
.map_err(Into::into)
.and(Ok(Some(Ok(()))));
if state.restart {
return Command::new(exe)
.args(env::args().skip(1))
.spawn()
.map_err(Into::into)
.and(Ok(Some(Ok(()))));
} else {
return Ok(Some(Ok(())));
}
}
bail!("Update: CRC32 mismatch");
}
Expand Down Expand Up @@ -408,6 +415,7 @@ pub async fn run(args: RunArgs, pubkey: PublicKey) {
args.disable_shell,
disk,
interface,
args.restart,
);
info!("Connection received {addr}");
if let Err(e) = connect(stream, addr, &pubkey, state).await {
Expand Down Expand Up @@ -440,6 +448,7 @@ pub async fn run(args: RunArgs, pubkey: PublicKey) {
args.disable_shell,
args.disk.clone(),
args.interface.clone(),
args.restart,
);
if let Err(e) = active(&args.addr, &pubkey, state).await {
if e.to_string() == SocketError::Reconnect.to_string() {
Expand Down
5 changes: 4 additions & 1 deletion plugin/agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ impl Plugin for Agent {
mut skynet: Skynet,
state: GlobalState,
) -> (Skynet, GlobalState, Result<()>) {
let _ = SERVICE.set(Arc::new(Service::new(path)));
let _ = SERVICE.set(Arc::new(Service::new(
path,
env!("CARGO_PKG_VERSION").to_owned(),
)));
skynet
.shared_api
.set(&ID, VERSION, Box::new(SERVICE.get().unwrap().to_owned()));
Expand Down
4 changes: 4 additions & 0 deletions plugin/agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ pub struct RunArgs {
/// Interface name, sum all specified.
#[arg(short, long, required = true)]
interface: Vec<String>,

/// Whether to restart on update.
#[arg(long, default_value = "false")]
restart: bool,
}

#[derive(Subcommand, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion plugin/agent_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "skynet_api_agent"
version = "0.2.1"
version = "0.3.0"
edition = "2021"
authors = ["MXWXZ <[email protected]>"]
description = "API for Skynet agent plugin."
Expand Down
9 changes: 5 additions & 4 deletions plugin/agent_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,18 @@ impl Display for Arch {
#[derive(Debug)]
pub struct Service {
path: PathBuf,
version: String,
}

impl Service {
#[must_use]
pub const fn new(path: PathBuf) -> Self {
Self { path }
pub const fn new(path: PathBuf, version: String) -> Self {
Self { path, version }
}

#[must_use]
pub fn check_version(v: &str) -> bool {
compare(VERSION, v) == Ok(Cmp::Gt)
pub fn check_version(&self, v: &str) -> bool {
compare(&self.version, v) == Ok(Cmp::Gt)
}

#[must_use]
Expand Down
4 changes: 2 additions & 2 deletions plugin/monitor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "monitor"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
authors = ["MXWXZ <[email protected]>"]

Expand All @@ -20,7 +20,7 @@ crc32fast = "1.4.2"
miniz_oxide = "0.8.0"

skynet_api_monitor = { version = "0.2.0", path = "../monitor_api" }
skynet_api_agent = { version = "0.2.0", path = "../agent_api" }
skynet_api_agent = { version = "0.3.0", path = "../agent_api" }
skynet_api = { path = "../../skynet_api" }
skynet_macro = { path = "../../skynet_macro" }
sea-orm-migration = { version = "1.0.1", features = [
Expand Down
6 changes: 6 additions & 0 deletions plugin/monitor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SHELL = /bin/bash

static:
@rm -rf $(OUTPUT_DIR) && mkdir -p $(OUTPUT_DIR)
@cd frontend && yarn && yarn build
@cp -r frontend/dist/. $(OUTPUT_DIR)
2 changes: 1 addition & 1 deletion plugin/monitor/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl Handler {
.await?;
tx.commit().await?;
if let Some(x) = AGENT_API.get() {
if skynet_api_agent::Service::check_version(&version) {
if AGENT_API.get().unwrap().check_version(&version) {
let sys = skynet_api_agent::System::parse(&sys);
let arch = skynet_api_agent::Arch::parse(&arch);
if sys.is_none() || arch.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion skynet/src/handler/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn transformer(mut item: LogItem) -> LogItem {
}
thread::spawn(move || {
runtime::Builder::new_current_thread()
.enable_time()
.enable_all()
.build()
.unwrap()
.block_on(async {
Expand Down
2 changes: 1 addition & 1 deletion skynet_api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl APIManager {
///
/// `ver` follows typical semver comparators, we strongly suggest only accept these two types:
/// - `1.0.0`: exact match
/// - `~1.0.0`: >=1.0.0 and <=1.1.0
/// - `~1.0.0`: >=1.0.0 and <1.1.0
///
/// # Panics
///
Expand Down

0 comments on commit 6903a2d

Please sign in to comment.