diff --git a/cuddle-empty/cuddle.yaml b/cuddle-empty/cuddle.yaml index f0417f2..597a66a 100644 --- a/cuddle-empty/cuddle.yaml +++ b/cuddle-empty/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-empty-plan.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-empty-plan.git" vars: service: "%%name%%" @@ -12,5 +12,5 @@ please: repository: "%%name%%" branch: main settings: - api_url: https://git.front.kjuulh.io + api_url: https://git.kjuulh.io diff --git a/cuddle-infrastructure/cuddle.yaml b/cuddle-infrastructure/cuddle.yaml index c8f85a5..d7cda26 100644 --- a/cuddle-infrastructure/cuddle.yaml +++ b/cuddle-infrastructure/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-infrastructure-plan.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-infrastructure-plan.git" vars: service: "%%name%%" @@ -13,7 +13,7 @@ vars: deployment: - registry: git@git.front.kjuulh.io:kjuulh/clank-clusters + registry: git@git.kjuulh.io:kjuulh/clank-clusters env: prod: clusters: diff --git a/cuddle-leptos/cuddle.yaml b/cuddle-leptos/cuddle.yaml index 9e91afa..974743d 100644 --- a/cuddle-leptos/cuddle.yaml +++ b/cuddle-leptos/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-rust-leptos-plan.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-rust-leptos-plan.git" vars: service: "%%name%%" diff --git a/cuddle-node-service/cuddle.yaml b/cuddle-node-service/cuddle.yaml index 16e0a66..c1b7aca 100644 --- a/cuddle-node-service/cuddle.yaml +++ b/cuddle-node-service/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-node-service-plan.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-node-service-plan.git" vars: service: "%%name%%" @@ -13,7 +13,7 @@ vars: deployment: - registry: git@git.front.kjuulh.io:kjuulh/clank-clusters + registry: git@git.kjuulh.io:kjuulh/clank-clusters env: prod: clusters: diff --git a/cuddle-rust-cli/cuddle.yaml b/cuddle-rust-cli/cuddle.yaml index f3f41e4..500e175 100644 --- a/cuddle-rust-cli/cuddle.yaml +++ b/cuddle-rust-cli/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-rust-cli-plan.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-rust-cli-plan.git" vars: service: "%%name%%" @@ -12,6 +12,6 @@ please: repository: "%%name%%" branch: "main" settings: - api_url: "https://git.front.kjuulh.io" + api_url: "https://git.kjuulh.io" actions: rust: diff --git a/cuddle-rust-lib/cuddle.yaml b/cuddle-rust-lib/cuddle.yaml index c777a1b..6d0b061 100644 --- a/cuddle-rust-lib/cuddle.yaml +++ b/cuddle-rust-lib/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-rust-lib-plan.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-rust-lib-plan.git" vars: service: "%%name%%" @@ -12,6 +12,6 @@ please: repository: "%%name%%" branch: main settings: - api_url: "https://git.front.kjuulh.io" + api_url: "https://git.kjuulh.io" actions: rust: diff --git a/cuddle-rust-service/crates/%%name%%/src/main.rs b/cuddle-rust-service/crates/%%name%%/src/main.rs index c1d4c36..59431da 100644 --- a/cuddle-rust-service/crates/%%name%%/src/main.rs +++ b/cuddle-rust-service/crates/%%name%%/src/main.rs @@ -1,26 +1,93 @@ -use std::{net::SocketAddr, ops::Deref, sync::Arc}; +mod state { + #[derive(Clone)] + pub struct State {} -use anyhow::Context; -use axum::extract::MatchedPath; -use axum::http::Request; -use axum::Router; -use axum::routing::get; -use clap::{Parser, Subcommand}; -use tower_http::trace::TraceLayer; - -#[derive(Parser)] -#[command(author, version, about, long_about = None, subcommand_required = true)] -struct Command { - #[command(subcommand)] - command: Option, + impl State { + pub async fn new() -> anyhow::Result { + Ok(Self {}) + } + } } +pub use state::*; -#[derive(Subcommand)] -enum Commands { - Serve { - #[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")] - host: SocketAddr, - }, +pub mod cli { + use clap::{Parser, Subcommand}; + + use crate::{State, cli::serve::ServeCommand}; + + mod serve { + use std::net::SocketAddr; + + use axum::{Router, extract::MatchedPath, http::Request, routing::get}; + use tower_http::trace::TraceLayer; + + use crate::State; + + #[derive(clap::Parser)] + pub struct ServeCommand { + #[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")] + host: SocketAddr, + } + + impl ServeCommand { + pub async fn execute(&self, state: &State) -> anyhow::Result<()> { + let app = Router::new() + .route("/", get(root)) + .with_state(state.clone()) + .layer( + TraceLayer::new_for_http().make_span_with(|request: &Request<_>| { + // Log the matched route's path (with placeholders not filled in). + // Use request.uri() or OriginalUri if you want the real path. + let matched_path = request + .extensions() + .get::() + .map(MatchedPath::as_str); + + tracing::info_span!( + "http_request", + method = ?request.method(), + matched_path, + some_other_field = tracing::field::Empty, + ) + }), // ... + ); + + tracing::info!("listening on {}", self.host); + let listener = tokio::net::TcpListener::bind(self.host).await.unwrap(); + axum::serve(listener, app.into_make_service()) + .await + .unwrap(); + + Ok(()) + } + } + + async fn root() -> &'static str { + "Hello, nostore!" + } + } + + #[derive(Parser)] + #[command(author, version, about, long_about = None, subcommand_required = true)] + struct Command { + #[command(subcommand)] + command: Option, + } + + #[derive(Subcommand)] + enum Commands { + Serve(ServeCommand), + } + + pub async fn execute() -> anyhow::Result<()> { + let cli = Command::parse(); + + let state = State::new().await?; + + match cli.command.expect("a subcommand") { + Commands::Serve(cmd) => cmd.execute(&state).await, + } + } } #[tokio::main] @@ -28,64 +95,7 @@ async fn main() -> anyhow::Result<()> { dotenv::dotenv().ok(); tracing_subscriber::fmt::init(); - let cli = Command::parse(); - - if let Some(Commands::Serve { host }) = cli.command { - tracing::info!("Starting service"); - - let state = SharedState(Arc::new(State::new().await?)); - - let app = Router::new() - .route("/", get(root)) - .with_state(state.clone()) - .layer( - TraceLayer::new_for_http().make_span_with(|request: &Request<_>| { - // Log the matched route's path (with placeholders not filled in). - // Use request.uri() or OriginalUri if you want the real path. - let matched_path = request - .extensions() - .get::() - .map(MatchedPath::as_str); - - tracing::info_span!( - "http_request", - method = ?request.method(), - matched_path, - some_other_field = tracing::field::Empty, - ) - }), // ... - ); - - tracing::info!("listening on {}", host); - let listener = tokio::net::TcpListener::bind(host).await.unwrap(); - axum::serve(listener, app.into_make_service()) - .await - .unwrap(); - } + cli::execute().await?; Ok(()) } - -async fn root() -> &'static str { - "Hello, %%name%%!" -} - -#[derive(Clone)] -pub struct SharedState(Arc); - -impl Deref for SharedState { - type Target = Arc; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -pub struct State {} - -impl State { - pub async fn new() -> anyhow::Result { - Ok(Self {}) - } -} - diff --git a/cuddle-rust-service/cuddle.yaml b/cuddle-rust-service/cuddle.yaml index bf31d27..9ab0eb4 100644 --- a/cuddle-rust-service/cuddle.yaml +++ b/cuddle-rust-service/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-rust-service-plan.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-rust-service-plan.git" vars: service: "%%name%%" diff --git a/empty/cuddle.yaml b/empty/cuddle.yaml index ecf6641..4cc1f94 100644 --- a/empty/cuddle.yaml +++ b/empty/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-base.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-base.git" vars: service: "%%name%%" diff --git a/rust-cli/cuddle.yaml b/rust-cli/cuddle.yaml index 2aca508..20c1f59 100644 --- a/rust-cli/cuddle.yaml +++ b/rust-cli/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-base.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-base.git" vars: service: "%%name%%" @@ -12,4 +12,4 @@ please: repository: "%%name%%" branch: "main" settings: - api_url: "https://git.front.kjuulh.io" + api_url: "https://git.kjuulh.io" diff --git a/rust-lib/cuddle.yaml b/rust-lib/cuddle.yaml index 360725b..1e53046 100644 --- a/rust-lib/cuddle.yaml +++ b/rust-lib/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-base.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-base.git" vars: service: "%%name%%" @@ -12,4 +12,4 @@ please: repository: "%%name%%" branch: main settings: - api_url: "https://git.front.kjuulh.io" + api_url: "https://git.kjuulh.io" diff --git a/rust-service/cuddle.yaml b/rust-service/cuddle.yaml index ecf6641..4cc1f94 100644 --- a/rust-service/cuddle.yaml +++ b/rust-service/cuddle.yaml @@ -1,6 +1,6 @@ -# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json +# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json -base: "git@git.front.kjuulh.io:kjuulh/cuddle-base.git" +base: "git@git.kjuulh.io:kjuulh/cuddle-base.git" vars: service: "%%name%%"