4 Commits

Author SHA1 Message Date
d4bd0ef1ca Use store instead of fetch_add for atomics
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 2m48s
2025-04-18 14:58:15 +02:00
95e47c708c Highlight port in red if tunnel failed to open 2025-04-18 14:57:31 +02:00
75bfd4d5cf Fixed version string
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 2m30s
2025-04-18 14:12:30 +02:00
7fb8cb9c60 Added dockerignore to improve caching 2025-04-18 12:01:20 +02:00
11 changed files with 61 additions and 21 deletions

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
*
!queries
!src
!Cargo.*

View File

@@ -17,12 +17,13 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Get Git commit timestamps - name: Set timestamp and release version
run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV run: |
echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
git fetch --prune --unshallow --tags --force
echo "RELEASE_VERSION=$(git describe --always --dirty='--modified')" >> $GITHUB_ENV
cat $GITHUB_ENV
- name: Login to registry - name: Login to registry
uses: docker/login-action@v3 uses: docker/login-action@v3
@@ -67,6 +68,8 @@ jobs:
annotations: ${{ steps.meta.outputs.annotations }} annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
build-args: |
"RELEASE_VERSION=${{ env.RELEASE_VERSION }}"
env: env:
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }} SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}

View File

@@ -14,6 +14,9 @@ ENV RUSTC_BOOTSTRAP=1
RUN cargo chef cook --release --recipe-path recipe.json RUN cargo chef cook --release --recipe-path recipe.json
COPY . . COPY . .
ARG RELEASE_VERSION
ENV RELEASE_VERSION=${RELEASE_VERSION}
# HACK: Enable the use of features on stable
ENV RUSTC_BOOTSTRAP=1 ENV RUSTC_BOOTSTRAP=1
RUN cargo auditable build --release RUN cargo auditable build --release

View File

@@ -1,6 +1,6 @@
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
@@ -14,25 +14,34 @@ pub struct Stats {
connections: AtomicUsize, connections: AtomicUsize,
rx: AtomicUsize, rx: AtomicUsize,
tx: AtomicUsize, tx: AtomicUsize,
failed: AtomicBool,
} }
impl Stats { impl Stats {
pub fn add_connection(&self) { pub fn add_connection(&self) {
self.connections.fetch_add(1, Ordering::Relaxed); self.connections.store(1, Ordering::Relaxed);
} }
pub fn add_rx_bytes(&self, n: usize) { pub fn add_rx_bytes(&self, n: usize) {
self.rx.fetch_add(n, Ordering::Relaxed); self.rx.store(n, Ordering::Relaxed);
} }
pub fn add_tx_bytes(&self, n: usize) { pub fn add_tx_bytes(&self, n: usize) {
self.tx.fetch_add(n, Ordering::Relaxed); self.tx.store(n, Ordering::Relaxed);
} }
pub fn connections(&self) -> usize { pub fn connections(&self) -> usize {
self.connections.load(Ordering::Relaxed) self.connections.load(Ordering::Relaxed)
} }
pub fn failed(&self) -> bool {
self.failed.load(Ordering::Relaxed)
}
pub fn set_failed(&self, failed: bool) {
self.failed.store(failed, Ordering::Relaxed);
}
pub fn rx(&self) -> Unit { pub fn rx(&self) -> Unit {
Unit::new(self.rx.load(Ordering::Relaxed), "B") Unit::new(self.rx.load(Ordering::Relaxed), "B")
} }

View File

@@ -5,4 +5,7 @@ mod io;
pub mod ldap; pub mod ldap;
pub mod ssh; pub mod ssh;
pub mod tunnel; pub mod tunnel;
mod version;
pub mod web; pub mod web;
pub use version::VERSION;

View File

@@ -3,10 +3,10 @@ use std::path::Path;
use color_eyre::eyre::Context; use color_eyre::eyre::Context;
use dotenvy::dotenv; use dotenvy::dotenv;
use git_version::git_version;
use hyper::server::conn::http1::{self}; use hyper::server::conn::http1::{self};
use hyper_util::rt::TokioIo; use hyper_util::rt::TokioIo;
use rand::rngs::OsRng; use rand::rngs::OsRng;
use siranga::VERSION;
use siranga::ldap::Ldap; use siranga::ldap::Ldap;
use siranga::ssh::Server; use siranga::ssh::Server;
use siranga::tunnel::Registry; use siranga::tunnel::Registry;
@@ -38,11 +38,7 @@ async fn main() -> color_eyre::Result<()> {
.init(); .init();
} }
info!( info!(version = VERSION, "Starting",);
"Starting {} ({})",
std::env!("CARGO_PKG_NAME"),
git_version!(),
);
let key = if let Ok(path) = std::env::var("PRIVATE_KEY_FILE") { let key = if let Ok(path) = std::env::var("PRIVATE_KEY_FILE") {
russh::keys::PrivateKey::read_openssh_file(Path::new(&path)) russh::keys::PrivateKey::read_openssh_file(Path::new(&path))

View File

@@ -2,7 +2,6 @@ use std::cmp::min;
use std::iter::once; use std::iter::once;
use clap::Parser; use clap::Parser;
use git_version::git_version;
use ratatui::layout::Rect; use ratatui::layout::Rect;
use ratatui::prelude::CrosstermBackend; use ratatui::prelude::CrosstermBackend;
use ratatui::{Terminal, TerminalOptions, Viewport}; use ratatui::{Terminal, TerminalOptions, Viewport};
@@ -11,13 +10,14 @@ use russh::keys::ssh_key::PublicKey;
use russh::server::{Auth, Msg, Session}; use russh::server::{Auth, Msg, Session};
use tracing::{debug, trace, warn}; use tracing::{debug, trace, warn};
use crate::VERSION;
use crate::io::{Input, TerminalHandle}; use crate::io::{Input, TerminalHandle};
use crate::ldap::{Ldap, LdapError}; use crate::ldap::{Ldap, LdapError};
use crate::tunnel::{Registry, Tunnel, TunnelAccess}; use crate::tunnel::{Registry, Tunnel, TunnelAccess};
/// Quickly create http tunnels for development /// Quickly create http tunnels for development
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version = git_version!(), about, long_about = None)] #[command(version = VERSION, about, long_about = None)]
pub struct Args { pub struct Args {
/// Make all tunnels public by default instead of private /// Make all tunnels public by default instead of private
#[arg(long, group = "access")] #[arg(long, group = "access")]

View File

@@ -4,7 +4,6 @@ use std::iter::once;
use std::time::Duration; use std::time::Duration;
use futures::StreamExt; use futures::StreamExt;
use git_version::git_version;
use ratatui::layout::{Constraint, Flex, Layout, Position, Rect}; use ratatui::layout::{Constraint, Flex, Layout, Position, Rect};
use ratatui::prelude::CrosstermBackend; use ratatui::prelude::CrosstermBackend;
use ratatui::style::{Style, Stylize as _}; use ratatui::style::{Style, Stylize as _};
@@ -18,6 +17,7 @@ use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel};
use tracing::error; use tracing::error;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use crate::VERSION;
use crate::io::TerminalHandle; use crate::io::TerminalHandle;
use crate::tunnel::{Tunnel, TunnelRow}; use crate::tunnel::{Tunnel, TunnelRow};
@@ -165,7 +165,7 @@ impl RendererInner {
} }
fn render_title(&self, frame: &mut Frame, rect: Rect) { fn render_title(&self, frame: &mut Frame, rect: Rect) {
let title = format!("{} ({})", std::env!("CARGO_PKG_NAME"), git_version!()).bold(); let title = format!("{} ({})", std::env!("CARGO_PKG_NAME"), VERSION).bold();
let title = Line::from(title).centered(); let title = Line::from(title).centered();
frame.render_widget(title, rect); frame.render_widget(title, rect);
} }

View File

@@ -40,7 +40,12 @@ impl TunnelInner {
&self.internal_address, &self.internal_address,
self.port, self.port,
) )
.await?; .await
.inspect_err(|_| {
self.stats.set_failed(true);
})?;
self.stats.set_failed(false);
Ok(TrackStats::new(channel.into_stream(), self.stats.clone())) Ok(TrackStats::new(channel.into_stream(), self.stats.clone()))
} }

View File

@@ -17,9 +17,15 @@ pub struct TunnelRow {
impl From<&TunnelRow> for Vec<Span<'static>> { impl From<&TunnelRow> for Vec<Span<'static>> {
fn from(row: &TunnelRow) -> Self { fn from(row: &TunnelRow) -> Self {
let port = if row.stats.failed() {
row.port.clone().red()
} else {
row.port.clone()
};
vec![ vec![
row.name.clone(), row.name.clone(),
row.port.clone(), port,
row.access.clone(), row.access.clone(),
row.address.clone(), row.address.clone(),
row.stats.connections().to_string().into(), row.stats.connections().to_string().into(),

11
src/version.rs Normal file
View File

@@ -0,0 +1,11 @@
pub const VERSION: &str = get_version();
const fn get_version() -> &'static str {
if let Some(version) = std::option_env!("RELEASE_VERSION")
&& !version.is_empty()
{
version
} else {
git_version::git_version!(fallback = "unknown")
}
}