feat: upload of data
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-25 23:43:19 +02:00
parent 90928d08ff
commit c1d71df0e5
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
7 changed files with 2441 additions and 58 deletions

2372
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,7 @@ tokio.workspace = true
dagger-sdk = "0.9.8"
eyre = { version = "0.6.12" }
tracing.workspace = true
tracing-subscriber.workspace = true
dagger-components = { git = "https://git.front.kjuulh.io/kjuulh/dagger-components", branch = "main" }

View File

@ -1,10 +1,18 @@
use std::collections::HashMap;
use std::path::PathBuf;
use async_trait::async_trait;
use cuddle_ci::cuddle_file::CuddleFile;
use cuddle_ci::cuddle_file::{self, CuddleFile};
use cuddle_ci::cuddle_releaser::CuddleReleaser;
use cuddle_ci::rust_service::architecture::{Architecture, Os};
use cuddle_ci::rust_service::RustService;
use cuddle_ci::rust_service::{extensions::*, RustServiceContext};
use cuddle_ci::{Context, CuddleCI, MainAction, PullRequestAction};
use cuddle_clusters::catalog::cluster_vars::ClusterVars;
use cuddle_clusters::catalog::cuddle_vars::CuddleVars;
use cuddle_clusters::catalog::vault_secret::VaultSecret;
use cuddle_clusters::releaser::Releaser;
use cuddle_clusters::IntoComponent;
#[tokio::main]
async fn main() -> eyre::Result<()> {
@ -25,12 +33,15 @@ async fn main() -> eyre::Result<()> {
.with_mold("2.3.3")
.to_owned();
let render = &RustServiceRender::default();
let render = &RustServiceRender {
service: cuddle_file.vars.service,
registry: "http://localhost:7900".into(),
};
let deployment = &CuddleReleaser::new(client).await?;
CuddleCI::default()
.with_pull_request(service)
//.with_pull_request(render.clone())
.with_pull_request(render)
//.with_pull_request(deployment.clone())
.with_main(service)
.with_main(render)
@ -42,13 +53,43 @@ async fn main() -> eyre::Result<()> {
}
#[derive(Default, Clone)]
struct RustServiceRender {}
struct RustServiceRender {
service: String,
registry: String,
}
impl RustServiceRender {
async fn render_templates(&self) -> eyre::Result<()> {
cuddle_clusters::process()
async fn render_templates(&self, image_tag: &str) -> eyre::Result<()> {
let mut releaser = Releaser::default();
releaser
.with_service(&self.service)
.with_registry(&self.registry);
match cuddle_clusters::process_opts(
vec![
CuddleVars::new(&std::env::current_dir()?)
.await
.map_err(|e| eyre::anyhow!("failed to process templates: {}", e.to_string()))?;
.map_err(|e| eyre::anyhow!("failed to get cuddle vars: {}", e.to_string()))?
.into_component(),
ClusterVars::default().into_component(),
VaultSecret::default().into_component(),
],
cuddle_clusters::process::ProcessOpts {
path: std::env::current_dir()?,
output: PathBuf::from(".cuddle/tmp/cuddle-clusters"),
variables: HashMap::from([("image_tag".into(), image_tag.into())]),
},
Some(releaser),
)
.await
.map_err(|e| eyre::anyhow!("failed to process templates: {}", e.to_string()))
{
Ok(_) => {}
Err(e) => {
tracing::error!("failed to process templates: {}", e);
}
}
Ok(())
}
@ -57,12 +98,12 @@ impl RustServiceRender {
#[async_trait]
impl MainAction for RustServiceRender {
async fn execute_main(&self, ctx: &mut Context) -> eyre::Result<()> {
self.render_templates().await?;
let image_tag = ctx
.get_image_tag()?
.ok_or(eyre::anyhow!("failed to find image_tag"))?;
self.render_templates(&image_tag).await?;
cuddle_ci::cuddle_x::well_known::render(vec![
"--cluster",
"clank-prod",
@ -78,19 +119,11 @@ impl MainAction for RustServiceRender {
#[async_trait]
impl PullRequestAction for RustServiceRender {
async fn execute_pull_request(&self, ctx: &mut Context) -> eyre::Result<()> {
self.render_templates().await?;
let image_tag = ctx
.get_image_tag()?
.ok_or(eyre::anyhow!("failed to find image_tag"))?;
cuddle_ci::cuddle_x::well_known::render(vec![
"--cluster",
"clank-prod",
"--image_tag",
&image_tag,
])
.await?;
self.render_templates(&image_tag).await?;
Ok(())
}

View File

View File

@ -15,6 +15,9 @@ vars:
secrets:
something.else: something
cuddle/clusters:
dev:
scripts:
render:
type: shell

View File

@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ vars.cuddle_vars.service }}-config
data:
{%- if (vars.cluster_vars.env | items | length) > 0 %}
environment:
{%- for (name, value) in vars.cluster_vars.env | dictsort %}
{{name | upper | replace(".", "_") | replace("-", "_") }}: {{value}}
{%- endfor %}
{%- endif %}

View File

@ -0,0 +1,41 @@
{%- set service_name = vars.cuddle_vars.service -%}
{%- set cluster_name = vars.cluster_vars.name -%}
{%- set cluster_namespace = vars.cluster_vars.namespace -%}
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: {{ service_name }}
cluster: {{ cluster_name }}
name: {{ service_name }}
namespace: {{ cluster_namespace }}
spec:
replicas: 3
selector:
matchLabels:
app: {{ service_name }}
cluster: {{ cluster_name }}
template:
metadata:
labels:
app: {{ service_name }}
cluster: {{ cluster_name }}
spec:
containers:
- args:
- serve
command:
- {{ service_name }}
image: kasperhermansen/{{ service_name }}:{{ vars.user_vars.image_tag }}
name: {{ service_name }}
envFrom:
- configMapRef:
name: {{service_name}}-config
ports:
- containerPort: 3000
name: external-http
- containerPort: 3001
name: internal-http
- containerPort: 3002
name: internal-grpc