Skip to content

Commit

Permalink
feat: embed console panel to built binary (8xFF#318)
Browse files Browse the repository at this point in the history
* embed console and media to binary

* github action build release with console panel
  • Loading branch information
giangndm authored Jun 26, 2024
1 parent ec28ecf commit c459b13
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 6 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,45 @@ env:
OPENSSL_STATIC: true

jobs:
build-console:
name: build-frontend
runs-on: ubuntu-latest
env:
NEXT_PUBLIC_API_URL: /api/
steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: false

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build dashboard
run: |
VERSION=$(cat bin/CONSOLE_FRONTEND)
git clone https://github.com/8xFF/atm0s-media-server-console.git
cd atm0s-media-server-console
git checkout $VERSION
pnpm install
cd apps/console
pnpm build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: console-frontend
path: atm0s-media-server-console/apps/console/out

build-release:
name: build-release
needs: build-console
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: 1
Expand Down Expand Up @@ -153,6 +190,11 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y --no-install-recommends pkg-config musl-dev musl-tools

- uses: actions/download-artifact@v4
with:
name: console-frontend
path: bin/public/console

- name: Patch some libs
run: |
mv ./.cargo/config.toml.release-build .cargo/config.toml
Expand All @@ -162,7 +204,7 @@ jobs:
with:
use-cross: ${{ matrix.cross }}
command: build
args: --verbose --release --package ${{ env.APP_NAME }} --target ${{ matrix.target }}
args: --verbose --release --package ${{ env.APP_NAME }} --target ${{ matrix.target }} --features embed_static

- name: Rename file
if: ${{ matrix.build != 'windows gnu x64' && matrix.build != 'windows msvc x64' }}
Expand Down
119 changes: 119 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/CONSOLE_FRONTEND
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
78ec223b1560e6fe3334ef3d94da044ed7f78240
6 changes: 5 additions & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rand = { workspace = true }
prost = { workspace = true }
poem = { version = "3.0", features = ["static-files"] }
poem-openapi = { version = "5.0", features = ["swagger-ui"] }
rust-embed = { version = "8.0", features = ["compression"], optional = true }
tokio = { version = "1.37", features = ["full"] }
sans-io-runtime = { workspace = true }
atm0s-sdn = { workspace = true }
Expand All @@ -32,13 +33,16 @@ derive_more = { workspace = true }
rcgen = { version = "0.13", optional = true }
maxminddb = { version = "0.24", optional = true }
sysinfo = { version = "0.30", optional = true }
hex = { version = "0.4", optional = true }
mime_guess = { version = "2.0", optional = true }

[features]
default = ["console", "gateway", "media", "connector", "cert_utils"]
gateway = ["media-server-gateway", "media-server-connector", "quinn_vnet", "node_metrics", "maxminddb"]
gateway = ["media-server-gateway", "media-server-connector", "quinn_vnet", "node_metrics", "maxminddb", "rust-embed"]
media = ["media-server-runner", "quinn_vnet", "node_metrics"]
console = []
connector = ["quinn_vnet", "media-server-connector", "media-server-utils"]
cert_utils = ["rcgen", "rustls"]
quinn_vnet = ["rustls", "quinn"]
node_metrics = ["sysinfo"]
embed_static = ["rust-embed", "hex", "mime_guess"]
1 change: 1 addition & 0 deletions bin/public/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console
Empty file added bin/public/console/.gitignore
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 33 additions & 4 deletions bin/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use media_server_protocol::protobuf::cluster_connector::MediaConnectorServiceCli
use media_server_protocol::rpc::quinn::{QuinnClient, QuinnStream};
use media_server_protocol::transport::{RpcReq, RpcRes};
use media_server_secure::{MediaEdgeSecure, MediaGatewaySecure};
#[cfg(feature = "embed_static")]
use utils::EmbeddedFilesEndpoint;
#[cfg(not(feature = "embed_static"))]
use poem::endpoint::StaticFilesEndpoint;
use poem::{listener::TcpListener, middleware::Cors, EndpointExt, Route, Server};
use poem_openapi::types::{ToJSON, Type};
Expand All @@ -21,6 +24,16 @@ mod api_media;
mod api_token;
mod utils;

#[cfg(feature = "embed_static")]
#[derive(rust_embed::RustEmbed)]
#[folder = "public/media"]
pub struct PublicMediaFiles;

#[cfg(feature = "embed_static")]
#[derive(rust_embed::RustEmbed)]
#[folder = "public/console"]
pub struct PublicConsoleFiles;

#[derive(Debug, Default, Object)]
pub struct Response<T: ParseFromJSON + ToJSON + Type + Send + Sync> {
pub status: bool,
Expand Down Expand Up @@ -68,9 +81,13 @@ pub async fn run_console_http_server(

let ctx = api_console::ConsoleApisCtx { secure, storage, connector };

#[cfg(not(feature = "embed_static"))]
let console_panel = StaticFilesEndpoint::new("./public/console/").index_file("index.html");
#[cfg(feature = "embed_static")]
let console_panel = EmbeddedFilesEndpoint::<PublicConsoleFiles>::new();

let route = Route::new()
//TODO build UI and embed to here
.nest("/", StaticFilesEndpoint::new("./public").index_file("index.html"))
.nest("/", console_panel)
//user
.nest("/api/user/", user_service.data(ctx.clone()))
.nest("/api/user/ui", user_ui)
Expand Down Expand Up @@ -102,8 +119,14 @@ pub async fn run_gateway_http_server<ES: 'static + MediaEdgeSecure + Send + Sync
let media_service: OpenApiService<_, ()> = OpenApiService::new(api_media::MediaApis::<ES>::new(), "Media Gateway APIs", env!("CARGO_PKG_VERSION")).server("/media/");
let media_ui = media_service.swagger_ui();
let media_spec = media_service.spec();

#[cfg(not(feature = "embed_static"))]
let samples = StaticFilesEndpoint::new("./public/media/").index_file("index.html");
#[cfg(feature = "embed_static")]
let samples = EmbeddedFilesEndpoint::<PublicMediaFiles>::new();

let route = Route::new()
.nest("/samples", StaticFilesEndpoint::new("./public").index_file("index.html"))
.nest("/samples", samples)
.nest("/token/", token_service.data(api_token::TokenServerCtx { secure: gateway_secure }))
.nest("/token/ui", token_ui)
.at("/token/spec", poem::endpoint::make_sync(move |_| token_spec.clone()))
Expand Down Expand Up @@ -137,8 +160,14 @@ pub async fn run_media_http_server<ES: 'static + MediaEdgeSecure + Send + Sync,
let media_service: OpenApiService<_, ()> = OpenApiService::new(api_media::MediaApis::<ES>::new(), "Media Gateway APIs", env!("CARGO_PKG_VERSION")).server("/media/");
let media_ui = media_service.swagger_ui();
let media_spec = media_service.spec();

#[cfg(not(feature = "embed_static"))]
let samples = StaticFilesEndpoint::new("./public/media/").index_file("index.html");
#[cfg(feature = "embed_static")]
let samples = EmbeddedFilesEndpoint::<PublicMediaFiles>::new();

let route = route
.nest("/samples", StaticFilesEndpoint::new("./public").index_file("index.html"))
.nest("/samples", samples)
.nest("/", media_service.data(api_media::MediaServerCtx { sender, secure: edge_secure }))
.nest("/ui", media_ui)
.at("/spec", poem::endpoint::make_sync(move |_| media_spec.clone()))
Expand Down
Loading

0 comments on commit c459b13

Please sign in to comment.