feat: add node plan
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
9bb1d9f908
commit
d6bbb91031
2
cuddle-node-service/.drone.yml
Normal file
2
cuddle-node-service/.drone.yml
Normal file
@ -0,0 +1,2 @@
|
||||
kind: template
|
||||
load: cuddle-node-service-plan.yaml
|
2
cuddle-node-service/.gitignore
vendored
Normal file
2
cuddle-node-service/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
target/
|
||||
.cuddle/
|
2276
cuddle-node-service/Cargo.lock
generated
Normal file
2276
cuddle-node-service/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
cuddle-node-service/Cargo.toml
Normal file
14
cuddle-node-service/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[workspace]
|
||||
members = ["crates/*"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.dependencies]
|
||||
%%name%% = { path = "crates/%%name%%" }
|
||||
|
||||
anyhow = { version = "1" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tracing = { version = "0.1", features = ["log"] }
|
||||
tracing-subscriber = { version = "0.3.18" }
|
||||
clap = { version = "4", features = ["derive", "env"] }
|
||||
dotenv = { version = "0.15" }
|
||||
axum = { version = "0.7" }
|
1
cuddle-node-service/README.md
Normal file
1
cuddle-node-service/README.md
Normal file
@ -0,0 +1 @@
|
||||
# %%name%%
|
1
cuddle-node-service/crates/%%name%%/.gitignore
vendored
Normal file
1
cuddle-node-service/crates/%%name%%/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
18
cuddle-node-service/crates/%%name%%/Cargo.toml
Normal file
18
cuddle-node-service/crates/%%name%%/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "%%name%%"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
clap.workspace = true
|
||||
dotenv.workspace = true
|
||||
axum.workspace = true
|
||||
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
sqlx = { version = "0.7.3", features = ["runtime-tokio", "tls-rustls", "postgres", "uuid", "time"] }
|
||||
uuid = { version = "1.7.0", features = ["v4"] }
|
||||
tower-http = { version = "0.5.2", features = ["cors", "trace"] }
|
@ -0,0 +1 @@
|
||||
-- Add migration script here
|
106
cuddle-node-service/crates/%%name%%/src/main.rs
Normal file
106
cuddle-node-service/crates/%%name%%/src/main.rs
Normal file
@ -0,0 +1,106 @@
|
||||
use std::{net::SocketAddr, ops::Deref, sync::Arc};
|
||||
|
||||
use anyhow::Context;
|
||||
use axum::extract::MatchedPath;
|
||||
use axum::http::Request;
|
||||
use axum::Router;
|
||||
use axum::routing::get;
|
||||
use clap::{Parser, Subcommand};
|
||||
use sqlx::{Pool, Postgres};
|
||||
use tower_http::trace::TraceLayer;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
||||
struct Command {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Serve {
|
||||
#[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")]
|
||||
host: SocketAddr,
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
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::<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 {}", host);
|
||||
let listener = tokio::net::TcpListener::bind(host).await.unwrap();
|
||||
axum::serve(listener, app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn root() -> &'static str {
|
||||
"Hello, %%name%%!"
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SharedState(Arc<State>);
|
||||
|
||||
impl Deref for SharedState {
|
||||
type Target = Arc<State>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
pub db: Pool<Postgres>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub async fn new() -> anyhow::Result<Self> {
|
||||
let db = sqlx::PgPool::connect(
|
||||
&std::env::var("DATABASE_URL").context("DATABASE_URL is not set")?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
sqlx::migrate!("migrations/crdb")
|
||||
.set_locking(false)
|
||||
.run(&db)
|
||||
.await?;
|
||||
|
||||
let _ = sqlx::query("SELECT 1;").fetch_one(&db).await?;
|
||||
|
||||
Ok(Self { db })
|
||||
}
|
||||
}
|
||||
|
10
cuddle-node-service/cuddle-template.json
Normal file
10
cuddle-node-service/cuddle-template.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "cuddle-node-service",
|
||||
"templating": "tera",
|
||||
"delimiter": "[[]]",
|
||||
"prompt": {
|
||||
"name": {
|
||||
"description": "Project name"
|
||||
}
|
||||
}
|
||||
}
|
21
cuddle-node-service/cuddle.yaml
Normal file
21
cuddle-node-service/cuddle.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json
|
||||
|
||||
base: "git@git.front.kjuulh.io:kjuulh/cuddle-node-service-plan.git"
|
||||
|
||||
vars:
|
||||
service: "%%name%%"
|
||||
registry: kasperhermansen
|
||||
|
||||
clusters:
|
||||
clank-prod:
|
||||
replicas: "3"
|
||||
namespace: prod
|
||||
|
||||
|
||||
deployment:
|
||||
registry: git@git.front.kjuulh.io:kjuulh/clank-clusters
|
||||
env:
|
||||
prod:
|
||||
clusters:
|
||||
- clank-prod
|
||||
|
3
cuddle-node-service/renovate.json
Normal file
3
cuddle-node-service/renovate.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||
}
|
15
cuddle-node-service/templates/docker-compose.yaml
Normal file
15
cuddle-node-service/templates/docker-compose.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
version: "3"
|
||||
services:
|
||||
crdb:
|
||||
restart: 'always'
|
||||
image: 'cockroachdb/cockroach:v23.1.14'
|
||||
command: 'start-single-node --advertise-addr 0.0.0.0 --insecure'
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8080/health?ready=1"]
|
||||
interval: '10s'
|
||||
timeout: '30s'
|
||||
retries: 5
|
||||
start_period: '20s'
|
||||
ports:
|
||||
- 8080:8080
|
||||
- '26257:26257'
|
@ -7,6 +7,7 @@
|
||||
"deployment",
|
||||
"cuddle-infrastructure",
|
||||
"cuddle-rust-service",
|
||||
"cuddle-rust-cli"
|
||||
"cuddle-rust-cli",
|
||||
"cuddle-node-service"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user