From ce6057afa59c473d952cb9ddf2dddbcec8d6e7c1 Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Fri, 30 Aug 2024 16:14:57 +0800 Subject: [PATCH 1/4] chore: Add Dockerfile for Aries engine don't implement star script yet. Signed-off-by: HouXiaoxuan --- docker/aries-engine-dockerfile | 69 ++++++++++++++++++++++++++++++++++ docker/start-aries.sh | 7 ++++ 2 files changed, 76 insertions(+) create mode 100644 docker/aries-engine-dockerfile create mode 100644 docker/start-aries.sh diff --git a/docker/aries-engine-dockerfile b/docker/aries-engine-dockerfile new file mode 100644 index 000000000..2d14d8c52 --- /dev/null +++ b/docker/aries-engine-dockerfile @@ -0,0 +1,69 @@ +FROM debian:bookworm-slim AS builder + +WORKDIR /opt/mega + +# build args, to specify the build type, release or debug +ARG BUILD_TYPE=release + +# check arg value +RUN if [ "$BUILD_TYPE" != "release" ] && [ "$BUILD_TYPE" != "debug" ]; then \ + echo "Invalid BUILD_TYPE: $BUILD_TYPE, must be release or debug"; \ + exit 1; \ + fi + +# set mirror for apt +# RUN echo "deb http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free" > /etc/apt/sources.list && \ +# echo "deb http://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list && \ +# echo "deb http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free" >> /etc/apt/sources.list + +RUN apt-get update && apt-get install -y \ + cmake \ + clang \ + build-essential + +RUN apt-get install -y \ + nodejs \ + npm + +RUN apt-get install -y \ + curl \ + wget \ + file \ + libssl-dev \ + libgtk-3-dev \ + libayatana-appindicator3-dev \ + librsvg2-dev \ + ca-certificates \ + && curl https://sh.rustup.rs -sSf | sh -s -- -y \ + && . $HOME/.cargo/env + +ENV PATH=/root/.cargo/bin:$PATH + +# copy the source code, the context must be the root of the project +COPY . . + +# build +RUN if [ "$BUILD_TYPE" = "release" ]; then \ + cargo build -p aries --release; \ + else \ + cargo build -p aries; \ + fi + +# final image +FROM debian:bookworm-slim + +RUN apt-get update && apt-get install -y libssl-dev ca-certificates + +ARG BUILD_TYPE=release + +COPY --from=builder /opt/mega/target/$BUILD_TYPE/aries /usr/local/bin/aries +COPY --from=builder /opt/mega/docker/start-aries.sh /usr/local/bin/start-aries.sh +RUN chmod +x /usr/local/bin/start-aries.sh +RUN chmod +x /usr/local/bin/aries +COPY --from=builder /opt/mega/target/$BUILD_TYPE/libpipy.so /usr/local/lib/libpipy.so +# refresh shared library cache +RUN ldconfig + +VOLUME /opt/mega + +CMD ["bash", "-c", "/usr/local/bin/start-aries.sh"] \ No newline at end of file diff --git a/docker/start-aries.sh b/docker/start-aries.sh new file mode 100644 index 000000000..ff70fc1e6 --- /dev/null +++ b/docker/start-aries.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +export MEGA_BASE_DIR="/opt/mega" +CONFIG_FILE="$MEGA_BASE_DIR/etc/config.toml" + +# Unimplemented +exec /usr/local/bin/aries -h # for test \ No newline at end of file From 0db70acd80a6d3163431e992966836f363cf91c4 Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Mon, 2 Sep 2024 18:05:05 +0800 Subject: [PATCH 2/4] chore: Add build.rs for Aries engine Signed-off-by: HouXiaoxuan --- aries/Cargo.toml | 1 + aries/src/build.rs | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 aries/src/build.rs diff --git a/aries/Cargo.toml b/aries/Cargo.toml index 4faf14c40..b19040284 100644 --- a/aries/Cargo.toml +++ b/aries/Cargo.toml @@ -2,6 +2,7 @@ name = "aries" version = "0.1.0" edition = "2021" +build = "src/build.rs" [[bin]] name = "aries" diff --git a/aries/src/build.rs b/aries/src/build.rs new file mode 100644 index 000000000..4c3e433a4 --- /dev/null +++ b/aries/src/build.rs @@ -0,0 +1,6 @@ +fn main() { + #[cfg(target_os = "linux")] + println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN"); + #[cfg(target_os = "macos")] + println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path"); +} \ No newline at end of file From fa55ec6a85a48e3b49f402e96cc856ec61cc2e72 Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Mon, 2 Sep 2024 18:05:36 +0800 Subject: [PATCH 3/4] feat: Add config options for aries Signed-off-by: HouXiaoxuan --- aries/src/main.rs | 25 ++++++++++++++----------- aries/src/service/relay_server.rs | 3 +++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/aries/src/main.rs b/aries/src/main.rs index 06fa3aca5..86bda0973 100644 --- a/aries/src/main.rs +++ b/aries/src/main.rs @@ -10,6 +10,7 @@ use service::{ }; use std::{ env, + path::PathBuf, thread::{self}, time::{self}, }; @@ -19,11 +20,20 @@ pub mod service; #[tokio::main] async fn main() { - // Get the current directory - let current_dir = env::current_dir().unwrap(); - // Get the path to the config file in the current directory - let config_path = current_dir.join("config.toml"); + ctrlc::set_handler(move || { + tracing::info!("Received Ctrl-C signal, exiting..."); + std::process::exit(0); + }) + .unwrap(); + + let option = RelayOptions::parse(); + let config_path = PathBuf::from( + option + .config + .to_owned() + .unwrap_or("config.toml".to_string()), + ); let config = if config_path.exists() { Config::new(config_path.to_str().unwrap()).unwrap() } else { @@ -33,13 +43,6 @@ async fn main() { init_log(&config.log); - ctrlc::set_handler(move || { - tracing::info!("Received Ctrl-C signal, exiting..."); - std::process::exit(0); - }) - .unwrap(); - - let option = RelayOptions::parse(); tracing::info!("{:?}", option); if option.only_agent { diff --git a/aries/src/service/relay_server.rs b/aries/src/service/relay_server.rs index 59f4dac92..ce5f220ff 100644 --- a/aries/src/service/relay_server.rs +++ b/aries/src/service/relay_server.rs @@ -44,6 +44,9 @@ pub struct RelayOptions { #[arg(long, default_value_t = false)] pub only_agent: bool, + + #[arg(long, short)] + pub config: Option } #[derive(Clone)] From 8c063966d89bdc31bdcb85e11adbed5e037eb9dc Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Mon, 2 Sep 2024 18:31:19 +0800 Subject: [PATCH 4/4] chore: Update readme and aries start script Signed-off-by: HouXiaoxuan --- docker/README.md | 27 +++++++++++++++++++++++++++ docker/start-aries.sh | 8 ++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docker/README.md b/docker/README.md index 472bb1309..913b7dfd3 100644 --- a/docker/README.md +++ b/docker/README.md @@ -14,6 +14,9 @@ docker buildx build -t mono-engine:0.1-pre-release -f ./docker/mono-engine-docke # build frontend mono ui image docker buildx build -t mono-ui:0.1-pre-release -f ./docker/mono-ui-dockerfile . + +# build aries engine image +docker buildx build -t aries-engine:0.1-pre-release -f ./docker/aries-engine-dockerfile . ``` ## Test Mono Engine @@ -53,4 +56,28 @@ docker network create mono-network docker run --rm -it -d --name mono-pg --network mono-network -v /mnt/data/mono/pg-data:/var/lib/postgresql/data -p 5432:5432 mono-pg:0.1-pre-release docker run --rm -it -d --name mono-engine --network mono-network -v /mnt/data/mono/mono-data:/opt/mega -p 8000:8000 -p 22:9000 mono-engine:0.1-pre-release docker run --rm -it -d --name mono-ui --network mono-network -e MEGA_INTERNAL_HOST=http://mono-engine:8000 -e MEGA_HOST=http://git.gitmono.com -e MOON_HOST=https://console.gitmono.com -p 3000:3000 mono-ui:0.1-pre-release +``` + +## Test aries engine + +[1] Initiate volume for aries and postgres data + +```bash +# Linux or MacOS +./init-volume.sh /mnt/data ./config.toml + +# Windows +# Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser +# .\init-volume.ps1 -baseDir "D:\" -configFile ".\config.toml" +``` + +[2] Start whole aries engine stack on local for testing + +```bash +# create network +docker network create mono-network + +# run postgres +docker run --rm -it -d --name mono-pg --network mono-network -v /tmp/data/mono/pg-data:/var/lib/postgresql/data -p 5432:5432 mono-pg:0.1-pre-release +docker run --rm -it -d --name aries-engine --network mono-network -v /tmp/data/mono/mono-data:/opt/mega -p 8001:8001 -p 8888:8888 aries-engine:0.1-pre-release ``` \ No newline at end of file diff --git a/docker/start-aries.sh b/docker/start-aries.sh index ff70fc1e6..389cb5553 100644 --- a/docker/start-aries.sh +++ b/docker/start-aries.sh @@ -3,5 +3,9 @@ export MEGA_BASE_DIR="/opt/mega" CONFIG_FILE="$MEGA_BASE_DIR/etc/config.toml" -# Unimplemented -exec /usr/local/bin/aries -h # for test \ No newline at end of file +if [ -f "$CONFIG_FILE" ]; then + echo "Using config file: $CONFIG_FILE" + exec /usr/local/bin/aries -c "$CONFIG_FILE" +else + exec /usr/local/bin/aries +fi \ No newline at end of file