commit 86167c56140187d2aba1d009885f6c4a7a3f5d4e Author: kjuulh Date: Mon Jul 21 16:57:50 2025 +0200 feat: create base go lib plan diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..3896c3f --- /dev/null +++ b/.drone.yml @@ -0,0 +1,152 @@ +kind: pipeline +name: default +type: docker + +steps: + - name: build ci + image: rustlang/rust:nightly + volumes: + - name: ci + path: /mnt/ci + environment: + PKG_CONFIG_SYSROOT_DIR: "/" + CI_PREFIX: "/mnt/ci" + commands: + - set -e + - apt update + - apt install musl-tools pkg-config libssl-dev openssl build-essential musl-dev -y + - rustup target add x86_64-unknown-linux-musl + - cargo build --target=x86_64-unknown-linux-musl -p ci --bin ci + - mv target/x86_64-unknown-linux-musl/debug/ci "$CI_PREFIX/ci" + + - 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 < eyre::Result<()> { + tracing_subscriber::fmt::init(); + + dagger_sdk::connect(|client| async move { + let service = &RustService::from(client.clone()) + .with_arch(Architecture::Amd64) + .with_os(Os::Linux) + .with_apt(&[ + "clang", + "libssl-dev", + "libz-dev", + "libgit2-dev", + "git", + "openssh-client", + ]) + .with_apt_release(&["git", "openssh-client"]) + .with_docker_cli() + .with_cuddle_cli() + .with_kubectl() + .with_apt_ca_certificates() + .with_crates(["ci", "crates/*"]) + .with_mold("2.3.3") + .with_bin_name(BIN_NAME) + .with_deployment(false) + .to_owned(); + + let drone_templater = &DroneTemplater::new(client, "templates/cuddle-go-lib-plan.yaml") + .with_variable("bin_name", BIN_NAME) + .to_owned(); + + CuddleCI::default() + .with_pull_request(service) + .with_main(service) + .with_main(drone_templater) + .execute(std::env::args()) + .await?; + Ok(()) + }) + .await?; + + Ok(()) +} diff --git a/crates/cuddle-go-lib-plan/.gitignore b/crates/cuddle-go-lib-plan/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/crates/cuddle-go-lib-plan/.gitignore @@ -0,0 +1 @@ +/target diff --git a/crates/cuddle-go-lib-plan/Cargo.toml b/crates/cuddle-go-lib-plan/Cargo.toml new file mode 100644 index 0000000..4d68b08 --- /dev/null +++ b/crates/cuddle-go-lib-plan/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cuddle-go-lib-plan" +version = "0.1.0" +edition = "2021" + +[dependencies] +tokio.workspace = true + +dagger-sdk = "0.17.1" +eyre = { version = "0.6.12" } + +dagger-components = { git = "https://git.front.kjuulh.io/kjuulh/dagger-components", branch = "main" } +dagger-rust = { git = "https://git.front.kjuulh.io/kjuulh/dagger-components", branch = "main" } +cuddle-ci = { git = "https://git.front.kjuulh.io/kjuulh/dagger-components", branch = "main" } +async-trait = "0.1.80" diff --git a/crates/cuddle-go-lib-plan/src/main.rs b/crates/cuddle-go-lib-plan/src/main.rs new file mode 100644 index 0000000..28730b1 --- /dev/null +++ b/crates/cuddle-go-lib-plan/src/main.rs @@ -0,0 +1,79 @@ +use async_trait::async_trait; +use cuddle_ci::{cuddle_please, Context, CuddleCI, MainAction, PullRequestAction}; +use dagger_sdk::HostDirectoryOptsBuilder; + +#[tokio::main] +async fn main() -> eyre::Result<()> { + dagger_sdk::connect(|client| async move { + let service = &GoLib { + client: client.clone(), + }; + let cuddle_please = &cuddle_please::CuddlePlease::new(client.clone()); + + CuddleCI::default() + .with_pull_request(service) + .with_main(service) + .with_main(cuddle_please) + .execute(std::env::args()) + .await?; + + Ok(()) + }) + .await?; + Ok(()) +} + +#[derive(Clone)] +struct GoLib { + client: dagger_sdk::Query, +} + +impl GoLib { + pub async fn test(&self) -> eyre::Result<()> { + let base = self.client.container().from("golang"); + + base.with_workdir("/app") + .with_directory( + ".", + self.client.host().directory_opts( + ".", + HostDirectoryOptsBuilder::default() + .include(vec!["**/go.mod", "**/go.sum"]) + .build()?, + ), + ) + .with_exec(vec!["go", "mod", "download"]) + .with_directory( + ".", + self.client.host().directory_opts( + ".", + HostDirectoryOptsBuilder::default() + .include(vec!["**/go.mod", "**/go.sum"]) + .build()?, + ), + ) + .with_exec(vec!["go", "test", "./..."]) + .sync() + .await?; + + Ok(()) + } +} + +#[async_trait] +impl PullRequestAction for GoLib { + async fn execute_pull_request(&self, _ctx: &mut Context) -> eyre::Result<()> { + self.test().await?; + + Ok(()) + } +} + +#[async_trait] +impl MainAction for GoLib { + async fn execute_main(&self, _ctx: &mut Context) -> eyre::Result<()> { + self.test().await?; + + Ok(()) + } +} diff --git a/cuddle.yaml b/cuddle.yaml new file mode 100644 index 0000000..f0649fb --- /dev/null +++ b/cuddle.yaml @@ -0,0 +1,24 @@ +# 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-base.git" + +vars: + service: "cuddle-go-lib-plan" + registry: kasperhermansen + + clusters: + clank-prod: + replicas: "3" + namespace: prod + +scripts: + render: + type: shell + args: + cluster: + name: cluster + type: flag + image_tag: + name: image_tag + type: flag + diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..7190a60 --- /dev/null +++ b/renovate.json @@ -0,0 +1,3 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json" +} diff --git a/templates/cuddle-go-lib-plan.yaml b/templates/cuddle-go-lib-plan.yaml new file mode 100644 index 0000000..fe98250 --- /dev/null +++ b/templates/cuddle-go-lib-plan.yaml @@ -0,0 +1,110 @@ +kind: pipeline +name: cuddle-go-lib-plan +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 <