diff --git a/.gitignore b/.gitignore index b41f4a4..fc1a014 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ output.cast .direnv /logs +/result* diff --git a/.woodpecker.yml b/.woodpecker.yml index f5fceac..0005089 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -9,3 +9,31 @@ pipeline: - rustup default $RUST - cargo check - cargo test + + build-docker-image: + image: nixos/nix + commands: + - ls -la + - pwd + - nix --extra-experimental-features "nix-command flakes" build -o /shared/image.tar.gz .#liveterm-docker + volumes: + - "liveterm-shared:/shared" + when: + # event: tag + branch: master + + deploy: + image: plugins/docker + commands: + - ls -la + - pwd + - docker load /shared/image.tar.gz + - export REPO=git.mzhang.io/michael/liveterm + - export TAG=$(docker images liveterm --format "{{.Tag}}") + - docker tag liveterm:$TAG $REPO:$TAG + - docker push $REPO:$TAG + volumes: + - "liveterm-shared:/shared" + when: + # event: tag + branch: master diff --git a/Cargo.toml b/Cargo.toml index 0552685..c6e7c1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" anyhow = { version = "1.0.68", features = ["backtrace"] } axum = { version = "0.6.4", features = ["ws", "http2", "macros", "headers"] } chrono = "0.4.23" -clap = { version = "4.0.32", features = ["derive"] } +clap = { version = "4.0.32", features = ["derive", "env"] } dashmap = "5.4.0" derive_builder = "0.12.0" futures = "0.3.25" diff --git a/default.nix b/default.nix index 3268989..ab39f3f 100644 --- a/default.nix +++ b/default.nix @@ -3,7 +3,7 @@ let rustPlatform = makeRustPlatform { inherit (toolchain) cargo rustc; }; in rustPlatform.buildRustPackage { - name = "asciinema"; + name = "liveterm"; src = ./.; cargoLock.lockFile = ./Cargo.lock; diff --git a/flake.nix b/flake.nix index 3a2e9dc..1dc36ff 100644 --- a/flake.nix +++ b/flake.nix @@ -11,15 +11,20 @@ toolchain = pkgs.fenix.default; - flakePkgs = { - asciinema = pkgs.callPackage ./. { inherit toolchain; }; + flakePkgs = rec { + liveterm = pkgs.callPackage ./. { inherit toolchain; }; + + liveterm-docker = pkgs.dockerTools.buildImage { + name = "liveterm"; + config = { Cmd = [ "${liveterm}/bin/liveterm" ]; }; + }; }; in rec { packages = flake-utils.lib.flattenTree flakePkgs; - defaultPackage = packages.asciinema; + defaultPackage = packages.liveterm; devShell = pkgs.mkShell { - inputsFrom = with packages; [ asciinema ]; + inputsFrom = with packages; [ liveterm ]; packages = (with pkgs; [ asciinema diff --git a/src/client/stream.rs b/src/client/stream.rs index 2b5816c..bd5c409 100644 --- a/src/client/stream.rs +++ b/src/client/stream.rs @@ -14,7 +14,11 @@ use crate::client::terminal::Terminal; use crate::message::Message; #[derive(Debug, Parser)] -pub struct StreamOpts {} +pub struct StreamOpts { + /// The broadcast websocket address of the server + #[clap(long = "broadcast-url", env = "LIVETERM_BROADCAST_URL")] + broadcast_url: Url, +} pub fn stream_main(opts: StreamOpts) -> Result<()> { let runtime = Runtime::new()?; @@ -26,9 +30,11 @@ async fn stream_async_main(opts: StreamOpts) -> Result<()> { println!("Hellosu {opts:?}"); // Open a new websocket connection to the server - let url = Url::parse(&"ws://localhost:8200/broadcast").unwrap(); + // let url = Url::parse(&"ws://localhost:8200/broadcast").unwrap(); - let (ws, _) = connect_async(url).await.context("Failed to connect")?; + let (ws, _) = connect_async(&opts.broadcast_url) + .await + .context("Failed to connect")?; println!("WebSocket handshake has been successfully completed"); let (mut write, mut read) = ws.split(); diff --git a/src/server/listen.rs b/src/server/listen.rs index 8504db8..42575b9 100644 --- a/src/server/listen.rs +++ b/src/server/listen.rs @@ -1,4 +1,4 @@ -use anyhow::{Result}; +use anyhow::Result; use axum::{ extract::{ ws::{Message as WsMessage, WebSocket},