feat: add plan

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-04-06 23:22:37 +02:00
commit 2ec6ffdb56
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
13 changed files with 2527 additions and 0 deletions

150
.drone.yml Normal file
View File

@ -0,0 +1,150 @@
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 <<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:latest
pull: always
volumes:
- name: ssh
path: /root/.ssh/
- name: ci
path: /mnt/ci
commands:
- eval `ssh-agent`
- ssh-add
- echo "$DOCKER_PASSWORD" | docker login --password-stdin --username="$DOCKER_USERNAME" docker.io
- apk add git
- $CI_PREFIX pr
environment:
DAGGER_CLOUD_TOKEN:
from_secret: dagger_cloud_token
DRONE_HOST: "https://ci.i.kjuulh.io"
DRONE_USER: "kjuulh"
DRONE_TOKEN:
from_secret: drone_token
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"
CI_PREFIX: "/mnt/ci/ci"
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"
- "build ci"
- name: build main
image: kasperhermansen/cuddle:latest
pull: always
volumes:
- name: ssh
path: /root/.ssh/
- name: ci
path: /mnt/ci
commands:
- eval `ssh-agent`
- ssh-add
- echo "$DOCKER_PASSWORD" | docker login --password-stdin --username="$DOCKER_USERNAME" docker.io
- apk add git
- cuddle --version
- $CI_PREFIX main
environment:
DAGGER_CLOUD_TOKEN:
from_secret: dagger_cloud_token
DRONE_HOST: "https://ci.i.kjuulh.io"
DRONE_USER: "kjuulh"
DRONE_TOKEN:
from_secret: drone_token
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"
- "build ci"
volumes:
- name: ssh
temp: {}
- name: ci
temp: {}

2
.gitignore vendored Normal file
View File

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

2103
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[workspace]
members = ["crates/*", "ci"]
resolver = "2"
[workspace.dependencies]
anyhow = { version = "1.0.81" }
tokio = { version = "1", features = ["full"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3.18" }
clap = { version = "4.5.4", features = ["derive", "env"] }
dotenv = { version = "0.15.0" }

1
README.md Normal file
View File

@ -0,0 +1 @@
# Cuddle rust plan

14
ci/Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "ci"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio.workspace = true
dagger-sdk = "0.9.8"
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" }

48
ci/src/main.rs Normal file
View File

@ -0,0 +1,48 @@
use cuddle_ci::drone_templater::DroneTemplater;
use cuddle_ci::rust_service::architecture::{Architecture, Os};
use cuddle_ci::rust_service::{extensions::*, RustService};
use cuddle_ci::CuddleCI;
const BIN_NAME: &str = "cuddle-empty-plan";
#[tokio::main]
async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?;
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_workspace_crates()
.await
.with_mold("2.3.3")
.with_bin_name(BIN_NAME)
.with_deployment(false)
.with_dagger_bin("0.9.8")
.to_owned();
let drone_templater = &DroneTemplater::new(client, "templates/cuddle-empty-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(())
}

1
crates/cuddle-empty-plan/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

View File

@ -0,0 +1,15 @@
[package]
name = "cuddle-empty-plan"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio.workspace = true
dagger-sdk = "0.9.8"
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.79"

View File

@ -0,0 +1,34 @@
use cuddle_ci::cuddle_file::CuddleFile;
use cuddle_ci::rust_service::architecture::{Architecture, Os};
use cuddle_ci::rust_service::extensions::*;
use cuddle_ci::rust_service::RustService;
use cuddle_ci::{cuddle_please, CuddleCI};
#[tokio::main]
async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?;
let cuddle_file = CuddleFile::from_cuddle_file().await?;
let service = &RustService::from(client.clone())
.with_arch(Architecture::Amd64)
.with_os(Os::Linux)
.with_apt(&["libssl-dev", "libz-dev", "libpq-dev", "protobuf-compiler"])
.with_apt_release(&["libssl-dev", "libz-dev", "libpq-dev"])
.with_cuddle_file(&cuddle_file)
.with_apt_ca_certificates()
.with_workspace_crates()
.await
.with_mold("2.3.3")
.to_owned();
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(())
}

7
cuddle.yaml Normal file
View File

@ -0,0 +1,7 @@
# 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-empty-plan"
registry: kasperhermansen

3
renovate.json Normal file
View File

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

View File

@ -0,0 +1,137 @@
kind: pipeline
name: cuddle-empty-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 <<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/{{bin_name}}:{{image_tag}}
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 --version
- {{ bin_name }} pr
environment:
DAGGER_CLOUD_TOKEN:
from_secret: dagger_cloud_token
DRONE_HOST: "https://ci.i.kjuulh.io"
DRONE_USER: "kjuulh"
DRONE_TOKEN:
from_secret: drone_token
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/{{bin_name}}:{{image_tag}}
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 --version
- {{ bin_name }} main
environment:
DAGGER_CLOUD_TOKEN:
from_secret: dagger_cloud_token
DRONE_HOST: "https://ci.i.kjuulh.io"
DRONE_USER: "kjuulh"
DRONE_TOKEN:
from_secret: drone_token
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: {}