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

chore: Add Dockerfile for Aries engine #550

Merged
merged 5 commits into from
Sep 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
1 change: 1 addition & 0 deletions aries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "aries"
version = "0.1.0"
edition = "2021"
build = "src/build.rs"

[[bin]]
name = "aries"
Expand Down
6 changes: 6 additions & 0 deletions aries/src/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
25 changes: 14 additions & 11 deletions aries/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use service::{
};
use std::{
env,
path::PathBuf,
thread::{self},
time::{self},
};
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions aries/src/service/relay_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct RelayOptions {

#[arg(long, default_value_t = false)]
pub only_agent: bool,

#[arg(long, short)]
pub config: Option<String>
}

#[derive(Clone)]
Expand Down
28 changes: 27 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,4 +56,27 @@ 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=https://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
69 changes: 69 additions & 0 deletions docker/aries-engine-dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 11 additions & 0 deletions docker/start-aries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

export MEGA_BASE_DIR="/opt/mega"
CONFIG_FILE="$MEGA_BASE_DIR/etc/config.toml"

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
Loading