feat: add initial

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2026-02-03 20:58:24 +01:00
commit fcb04af9b8
14 changed files with 1531 additions and 0 deletions

2
.drone.yml Normal file
View File

@@ -0,0 +1,2 @@
kind: template
load: cuddle-rust-service-plan.yaml

1
.env Normal file
View File

@@ -0,0 +1 @@

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
target/
.cuddle/

1358
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

18
Cargo.toml Normal file
View File

@@ -0,0 +1,18 @@
[workspace]
members = ["crates/*"]
resolver = "2"
[workspace.dependencies]
forge-enforce = { path = "crates/forge-enforce" }
anyhow = { version = "1" }
tokio = { version = "1", features = ["full"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3" }
clap = { version = "4", features = ["derive", "env"] }
dotenv = { version = "0.15" }
axum = { version = "0.8" }
serde = { version = "1", features = ["derive"] }
uuid = { version = "1", features = ["v4"] }
tower-http = { version = "0.6", features = ["cors", "trace"] }
notmad = "0.8"

1
README.md Normal file
View File

@@ -0,0 +1 @@
# forge-enforce

1
crates/forge-enforce/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

View File

@@ -0,0 +1,17 @@
[package]
name = "forge-enforce"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
clap.workspace = true
dotenv.workspace = true
axum.workspace = true
serde.workspace = true
uuid.workspace = true
tower-http.workspace = true
notmad.workspace = true

View File

@@ -0,0 +1,30 @@
use clap::{Parser, Subcommand};
use crate::{Config, State, cli::serve::ServeCommand};
mod serve;
#[derive(Parser)]
#[command(author, version, about, long_about = None, subcommand_required = true)]
struct Command {
#[command(subcommand)]
command: Option<Commands>,
#[command(flatten)]
config: Config,
}
#[derive(Subcommand)]
enum Commands {
Serve(ServeCommand),
}
pub async fn execute() -> anyhow::Result<()> {
let cli = Command::parse();
let state = State::new(cli.config).await?;
match cli.command.expect("a subcommand") {
Commands::Serve(cmd) => cmd.execute(&state).await,
}
}

View File

@@ -0,0 +1,49 @@
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::<MatchedPath>()
.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!"
}

View File

@@ -0,0 +1,14 @@
mod state;
pub use state::*;
pub mod cli;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
tracing_subscriber::fmt::init();
cli::execute().await?;
Ok(())
}

View File

@@ -0,0 +1,13 @@
#[derive(clap::Parser, Clone)]
pub struct Config {}
#[derive(Clone)]
pub struct State {
pub config: Config,
}
impl State {
pub async fn new(config: Config) -> anyhow::Result<Self> {
Ok(Self { config })
}
}

22
cuddle.yaml Normal file
View File

@@ -0,0 +1,22 @@
# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json
base: "git@git.kjuulh.io:kjuulh/cuddle-rust-service-plan.git"
vars:
service: "forge-enforce"
registry: kasperhermansen
database:
crdb: "false"
ingress:
- external: "true"
- internal: "true"
cuddle/clusters:
dev:
env:
service.host: "0.0.0.0:3000"
prod:
env:
service.host: "0.0.0.0:3000"

3
renovate.json Normal file
View File

@@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}