feat: add rust cli
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
c62178ecbd
commit
70e5aaa107
124
cuddle-rust-cli/.drone.yml
Normal file
124
cuddle-rust-cli/.drone.yml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
kind: pipeline
|
||||||
|
name: default
|
||||||
|
type: docker
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: load_secret
|
||||||
|
image: debian:buster-slim
|
||||||
|
volumes:
|
||||||
|
- name: ssh
|
||||||
|
path: /root/.ssh/
|
||||||
|
environment:
|
||||||
|
SSH_KEY:
|
||||||
|
from_secret: gitea_id_ed25519
|
||||||
|
commands:
|
||||||
|
- mkdir -p $HOME/.ssh/
|
||||||
|
- echo "$SSH_KEY" | base64 -d > $HOME/.ssh/id_ed25519
|
||||||
|
- chmod -R 600 ~/.ssh
|
||||||
|
- |
|
||||||
|
cat >$HOME/.ssh/config <<EOL
|
||||||
|
Host git.front.kjuulh.io
|
||||||
|
IdentityFile $HOME/.ssh/id_ed25519
|
||||||
|
IdentitiesOnly yes
|
||||||
|
UserKnownHostsFile=/dev/null
|
||||||
|
StrictHostKeyChecking no
|
||||||
|
EOL
|
||||||
|
- chmod 700 ~/.ssh/config
|
||||||
|
|
||||||
|
- name: build pr
|
||||||
|
image: kasperhermansen/cuddle-rust-service-plan:main-1708174719
|
||||||
|
pull: always
|
||||||
|
volumes:
|
||||||
|
- name: ssh
|
||||||
|
path: /root/.ssh/
|
||||||
|
commands:
|
||||||
|
- eval `ssh-agent`
|
||||||
|
- ssh-add
|
||||||
|
- echo "$DOCKER_PASSWORD" | docker login --password-stdin --username="$DOCKER_USERNAME" docker.io
|
||||||
|
- export CLUSTER=clank-dev
|
||||||
|
- cuddle-rust-service-plan pr
|
||||||
|
environment:
|
||||||
|
REGISTRY_CACHE_USERNAME:
|
||||||
|
from_secret: registry_cache_username
|
||||||
|
REGISTRY_CACHE_PASSWORD:
|
||||||
|
from_secret: registry_cache_password
|
||||||
|
REGISTRY_CACHE_TOKEN:
|
||||||
|
from_secret: registry_cache_token
|
||||||
|
REGISTRY_CACHE_url:
|
||||||
|
from_secret: registry_cache_url
|
||||||
|
DOCKER_BUILDKIT: 1
|
||||||
|
DOCKER_PASSWORD:
|
||||||
|
from_secret: docker_password
|
||||||
|
DOCKER_USERNAME:
|
||||||
|
from_secret: docker_username
|
||||||
|
CUDDLE_SECRETS_PROVIDER: 1password
|
||||||
|
CUDDLE_ONE_PASSWORD_DOT_ENV: ".env.ci"
|
||||||
|
CUDDLE_SSH_AGENT: "true"
|
||||||
|
GIT_PASSWORD:
|
||||||
|
from_secret: git_password
|
||||||
|
CI_PREFIX: "/mnt/ci/ci"
|
||||||
|
DOCKER_HOST: "tcp://192.168.1.233:2376"
|
||||||
|
CUDDLE_PLEASE_TOKEN:
|
||||||
|
from_secret: cuddle_please_token
|
||||||
|
OP_SERVICE_ACCOUNT_TOKEN:
|
||||||
|
from_secret: op_service_account_token
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
|
exclude:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
depends_on:
|
||||||
|
- "load_secret"
|
||||||
|
|
||||||
|
- name: build main
|
||||||
|
image: kasperhermansen/cuddle-rust-service-plan:main-1708174719
|
||||||
|
pull: always
|
||||||
|
volumes:
|
||||||
|
- name: ssh
|
||||||
|
path: /root/.ssh/
|
||||||
|
commands:
|
||||||
|
- eval `ssh-agent`
|
||||||
|
- ssh-add
|
||||||
|
- echo "$DOCKER_PASSWORD" | docker login --password-stdin --username="$DOCKER_USERNAME" docker.io
|
||||||
|
- export CLUSTER=clank-prod
|
||||||
|
- cuddle-rust-service-plan main
|
||||||
|
environment:
|
||||||
|
REGISTRY_CACHE_USERNAME:
|
||||||
|
from_secret: registry_cache_username
|
||||||
|
REGISTRY_CACHE_PASSWORD:
|
||||||
|
from_secret: registry_cache_password
|
||||||
|
REGISTRY_CACHE_TOKEN:
|
||||||
|
from_secret: registry_cache_token
|
||||||
|
REGISTRY_CACHE_url:
|
||||||
|
from_secret: registry_cache_url
|
||||||
|
DOCKER_BUILDKIT: 1
|
||||||
|
DOCKER_PASSWORD:
|
||||||
|
from_secret: docker_password
|
||||||
|
DOCKER_USERNAME:
|
||||||
|
from_secret: docker_username
|
||||||
|
CUDDLE_SECRETS_PROVIDER: 1password
|
||||||
|
CUDDLE_ONE_PASSWORD_DOT_ENV: ".env.ci"
|
||||||
|
CUDDLE_SSH_AGENT: "true"
|
||||||
|
GIT_PASSWORD:
|
||||||
|
from_secret: git_password
|
||||||
|
CI_PREFIX: "/mnt/ci/ci"
|
||||||
|
DOCKER_HOST: "tcp://192.168.1.233:2376"
|
||||||
|
CUDDLE_PLEASE_TOKEN:
|
||||||
|
from_secret: cuddle_please_token
|
||||||
|
OP_SERVICE_ACCOUNT_TOKEN:
|
||||||
|
from_secret: op_service_account_token
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
branch:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
depends_on:
|
||||||
|
- "load_secret"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: ssh
|
||||||
|
temp: {}
|
2
cuddle-rust-cli/.gitignore
vendored
Normal file
2
cuddle-rust-cli/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
target/
|
||||||
|
.cuddle/
|
2276
cuddle-rust-cli/Cargo.lock
generated
Normal file
2276
cuddle-rust-cli/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
cuddle-rust-cli/Cargo.toml
Normal file
14
cuddle-rust-cli/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" }
|
7
cuddle-rust-cli/README.md
Normal file
7
cuddle-rust-cli/README.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Newsletter API
|
||||||
|
|
||||||
|
represents a newsletter service for handling subscriptins and whatnot for my own email newsletter
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
This services requires a postgresql compatible, instance, in this case cockroachdb is used. Simply pass a DATABASE_URL to the app and it should apply migrations by itself. Do note that because Cockroach is used with SQLX locking on the schema table is disabled, reason being that cockroachdb doesn't currently support advisory locks
|
1
cuddle-rust-cli/crates/%%name%%/.gitignore
vendored
Normal file
1
cuddle-rust-cli/crates/%%name%%/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
18
cuddle-rust-cli/crates/%%name%%/Cargo.toml
Normal file
18
cuddle-rust-cli/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
|
29
cuddle-rust-cli/crates/%%name%%/src/main.rs
Normal file
29
cuddle-rust-cli/crates/%%name%%/src/main.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
use anyhow::Context;
|
||||||
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
||||||
|
struct Command {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Option<Commands>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum Commands {
|
||||||
|
Hello {},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
dotenv::dotenv().ok();
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
|
let cli = Command::parse();
|
||||||
|
tracing::debug!("Starting cli");
|
||||||
|
|
||||||
|
if let Some(Commands::Hello { }) = cli.command {
|
||||||
|
println!("Hello!")
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
10
cuddle-rust-cli/cuddle-template.json
Normal file
10
cuddle-rust-cli/cuddle-template.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "cuddle-rust-cli",
|
||||||
|
"templating": "tera",
|
||||||
|
"delimiter": "[[]]",
|
||||||
|
"prompt": {
|
||||||
|
"name": {
|
||||||
|
"description": "Project name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
cuddle-rust-cli/cuddle.yaml
Normal file
21
cuddle-rust-cli/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-rust-cli-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-rust-cli/renovate.json
Normal file
3
cuddle-rust-cli/renovate.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||||
|
}
|
15
cuddle-rust-cli/templates/docker-compose.yaml
Normal file
15
cuddle-rust-cli/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'
|
@ -6,6 +6,7 @@
|
|||||||
"empty",
|
"empty",
|
||||||
"deployment",
|
"deployment",
|
||||||
"cuddle-infrastructure",
|
"cuddle-infrastructure",
|
||||||
"cuddle-rust-service"
|
"cuddle-rust-service",
|
||||||
|
"cuddle-rust-cli"
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user