From b8f79ae83a6470a17ac94314ecf4238bf45e557c Mon Sep 17 00:00:00 2001 From: lpgeiger <1364012+lpgeiger@users.noreply.github.com> Date: Wed, 5 May 2021 19:24:14 +0000 Subject: [PATCH] download web files, release workflow adds web static files --- .github/workflows/release.yaml | 2 +- Makefile | 2 +- ol/cli/src/commands/serve_cmd.rs | 16 ++++++++++++---- ol/cli/src/server.rs | 17 ++++++++++++++++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4e20ae3faa..cd7428ca21 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -32,7 +32,7 @@ jobs: tag: ${{ github.ref }} overwrite: true - name: Web - run: zip -r public.zip ol/cli/web-monitor + run: zip -r web-monitor.zip ol/cli/web-monitor - name: Upload Web Files uses: svenstaro/upload-release-action@v2 with: diff --git a/Makefile b/Makefile index 8a731ffc6b..9d10148ff7 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ download: web-files done web-files: - curl -L --progress-bar --create-dirs -o ${DATA_PATH}/web-monitor/public.zip https://github.com/OLSF/libra/releases/download/v4.3.0-rc.0/public.zip + curl -L --progress-bar --create-dirs -o ${DATA_PATH}/web-monitor/public.zip https://github.com/OLSF/libra/releases/latest/download/public.zip unzip ${DATA_PATH}/web-monitor/public.zip download-release: diff --git a/ol/cli/src/commands/serve_cmd.rs b/ol/cli/src/commands/serve_cmd.rs index 552de6bf50..ded989900f 100644 --- a/ol/cli/src/commands/serve_cmd.rs +++ b/ol/cli/src/commands/serve_cmd.rs @@ -3,15 +3,23 @@ use crate::{entrypoint, node::{client, node::Node}, prelude::app_config, server}; use abscissa_core::{Command, Options, Runnable}; #[derive(Command, Debug, Options)] -pub struct ServeCmd {} +pub struct ServeCmd { + /// Update the web files + #[options(no_short, help = "update web files for server")] + update: bool +} impl Runnable for ServeCmd { /// Start the application. fn run(&self) { let args = entrypoint::get_args(); let cfg = app_config().clone(); - let client = client::pick_client(args.swarm_path, &cfg).unwrap().0; - let node = Node::new(client, cfg); - server::start_server(node); + if self.update { + server::update_web(&cfg.workspace.node_home); + } else { + let client = client::pick_client(args.swarm_path, &cfg).unwrap().0; + let node = Node::new(client, cfg); + server::start_server(node); + } } } diff --git a/ol/cli/src/server.rs b/ol/cli/src/server.rs index 0e6fb041a4..d4f4900f8d 100644 --- a/ol/cli/src/server.rs +++ b/ol/cli/src/server.rs @@ -1,7 +1,7 @@ //! `server` web monitor http server use futures::StreamExt; use serde_json::json; -use std::{convert::Infallible, fs, path::PathBuf, thread, time::Duration}; +use std::{convert::Infallible, fs, path::PathBuf, process::Command, thread, time::Duration}; use tokio::time::interval; use warp::{sse::ServerSentEvent, Filter}; use ol_types::config::IS_PROD; @@ -68,3 +68,18 @@ pub async fn start_server(node: Node) { .run(([0, 0, 0, 0], 3030)) .await; } + +/// Fetch updated static web files from release, for web-monitor. +pub fn update_web(home_path: &PathBuf) { + let zip_path = home_path.join("web-monitor.zip").to_str().unwrap().to_owned(); + let args = vec!["-L", "--progress-bar", "--create-dirs", "-o", &zip_path, "https://github.com/OLSF/libra/releases/latest/download/public.zip"]; + + Command::new("curl") + .args(args.as_slice()) + .output() + .expect("failed to download web files"); + Command::new("unzip") + .arg(&zip_path) + .output() + .expect("failed to unzip web files"); +} \ No newline at end of file