feat: with updated dagger-sdk
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-10-21 12:45:33 +02:00
parent e2c7f46378
commit 52914e08e6
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
11 changed files with 311 additions and 332 deletions

480
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,8 @@ dagger-cuddle-please = { path = "crates/dagger-cuddle-please" }
dagger-rust = { path = "crates/dagger-rust" } dagger-rust = { path = "crates/dagger-rust" }
ci = { path = "ci" } ci = { path = "ci" }
dagger-sdk = "0.2.22" #dagger-sdk = "0.3.2"
dagger-sdk = {git = "https://github.com/kjuulh/dagger.git", branch = "feat/with-send-sync"}
eyre = "0.6.8" eyre = "0.6.8"
tokio = "1.31.0" tokio = "1.31.0"
dotenv = "0.15.0" dotenv = "0.15.0"

View File

@ -8,8 +8,8 @@ edition = "2021"
[dependencies] [dependencies]
dagger-cuddle-please.workspace = true dagger-cuddle-please.workspace = true
dagger-rust.workspace = true dagger-rust.workspace = true
dagger-sdk.workspace = true
dagger-sdk = "*"
eyre = "*" eyre = "*"
color-eyre = "*" color-eyre = "*"
tokio = "1" tokio = "1"

View File

@ -74,7 +74,7 @@ async fn main() -> eyre::Result<()> {
LocalCommands::PleaseRelease => todo!(), LocalCommands::PleaseRelease => todo!(),
}, },
Commands::PullRequest {} => { Commands::PullRequest {} => {
async fn test(client: Arc<dagger_sdk::Query>, cli: &Command) { async fn test(client: dagger_sdk::Query, cli: &Command) {
let args = &cli.global; let args = &cli.global;
test::execute(client.clone(), args).await.unwrap(); test::execute(client.clone(), args).await.unwrap();
@ -83,13 +83,13 @@ async fn main() -> eyre::Result<()> {
tokio::join!(test(client.clone(), &cli),); tokio::join!(test(client.clone(), &cli),);
} }
Commands::Main {} => { Commands::Main {} => {
async fn test(client: Arc<dagger_sdk::Query>, cli: &Command) { async fn test(client: dagger_sdk::Query, cli: &Command) {
let args = &cli.global; let args = &cli.global;
test::execute(client.clone(), args).await.unwrap(); test::execute(client.clone(), args).await.unwrap();
} }
async fn cuddle_please(client: Arc<dagger_sdk::Query>, cli: &Command) { async fn cuddle_please(client: dagger_sdk::Query, cli: &Command) {
run_release_please(client.clone(), &cli.global) run_release_please(client.clone(), &cli.global)
.await .await
.unwrap(); .unwrap();
@ -114,7 +114,7 @@ mod please_release {
use crate::GlobalArgs; use crate::GlobalArgs;
pub async fn run_release_please( pub async fn run_release_please(
client: Arc<dagger_sdk::Query>, client: dagger_sdk::Query,
args: &GlobalArgs, args: &GlobalArgs,
) -> eyre::Result<()> { ) -> eyre::Result<()> {
DaggerCuddlePleaseAction::dagger(client) DaggerCuddlePleaseAction::dagger(client)
@ -142,7 +142,7 @@ mod test {
use crate::GlobalArgs; use crate::GlobalArgs;
pub async fn execute(client: Arc<dagger_sdk::Query>, _args: &GlobalArgs) -> eyre::Result<()> { pub async fn execute(client: dagger_sdk::Query, _args: &GlobalArgs) -> eyre::Result<()> {
dagger_rust::test::RustTest::new(client) dagger_rust::test::RustTest::new(client)
.test( .test(
None::<PathBuf>, None::<PathBuf>,

View File

@ -1,4 +1,4 @@
use std::sync::Arc; use std::sync::{Arc, Mutex};
use models::{CuddlePleaseArgs, CuddlePleaseSrcArgs}; use models::{CuddlePleaseArgs, CuddlePleaseSrcArgs};
use traits::CuddlePlease; use traits::CuddlePlease;
@ -80,11 +80,11 @@ pub mod traits {
} }
} }
pub struct DaggerCuddlePleaseAction(Arc<dyn CuddlePlease + Send + Sync + 'static>); pub struct DaggerCuddlePleaseAction(Arc<dyn CuddlePlease>);
impl DaggerCuddlePleaseAction { impl DaggerCuddlePleaseAction {
/// Create a [`traits::CuddlePlease`] client based on dagger /// Create a [`traits::CuddlePlease`] client based on dagger
pub fn dagger(client: Arc<dagger_sdk::Query>) -> Self { pub fn dagger(client: dagger_sdk::Query) -> Self {
Self(Arc::new(DaggerCuddlePlease::new(client))) Self(Arc::new(DaggerCuddlePlease::new(client)))
} }
@ -104,31 +104,27 @@ impl DaggerCuddlePleaseAction {
#[derive(Clone)] #[derive(Clone)]
struct DaggerCuddlePlease { struct DaggerCuddlePlease {
client: Arc<dagger_sdk::Query>, client: dagger_sdk::Query,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl CuddlePlease for DaggerCuddlePlease { impl CuddlePlease for DaggerCuddlePlease {
async fn execute(&self, args: &CuddlePleaseArgs) -> eyre::Result<()> { async fn execute(&self, args: &CuddlePleaseArgs) -> eyre::Result<()> {
self.cuddle_please(self.client.clone(), args).await self.cuddle_please(args).await
} }
async fn execute_src(&self, args: &CuddlePleaseSrcArgs) -> eyre::Result<()> { async fn execute_src(&self, args: &CuddlePleaseSrcArgs) -> eyre::Result<()> {
self.cuddle_please_src(self.client.clone(), args).await self.cuddle_please_src(args).await
} }
} }
impl DaggerCuddlePlease { impl DaggerCuddlePlease {
pub fn new(client: Arc<dagger_sdk::Query>) -> Self { pub fn new(client: dagger_sdk::Query) -> Self {
Self { client } Self { client }
} }
pub async fn cuddle_please( pub async fn cuddle_please(&self, args: &CuddlePleaseArgs) -> eyre::Result<()> {
&self, let build_image = self.client.container().from(&args.cuddle_image);
client: Arc<dagger_sdk::Query>,
args: &CuddlePleaseArgs,
) -> eyre::Result<()> {
let build_image = client.container().from(&args.cuddle_image);
let repo_url = match &args.server { let repo_url = match &args.server {
Server::Gitea { Server::Gitea {
@ -182,11 +178,12 @@ impl DaggerCuddlePlease {
}; };
let src = if args.use_ssh_socket { let src = if args.use_ssh_socket {
let socket = client let socket = self
.client
.host() .host()
.unix_socket(std::env::var("SSH_AGENT").expect("SSH_AGENT to be set")); .unix_socket(std::env::var("SSH_AGENT").expect("SSH_AGENT to be set"));
client self.client
.git_opts( .git_opts(
&repo_url, &repo_url,
dagger_sdk::QueryGitOpts { dagger_sdk::QueryGitOpts {
@ -200,7 +197,7 @@ impl DaggerCuddlePlease {
ssh_known_hosts: None, ssh_known_hosts: None,
}) })
} else { } else {
client self.client
.git_opts( .git_opts(
&repo_url, &repo_url,
dagger_sdk::QueryGitOpts { dagger_sdk::QueryGitOpts {
@ -215,19 +212,16 @@ impl DaggerCuddlePlease {
let res = build_image let res = build_image
.with_secret_variable( .with_secret_variable(
"CUDDLE_PLEASE_TOKEN", "CUDDLE_PLEASE_TOKEN",
client self.client.set_secret(
.set_secret( "CUDDLE_PLEASE_TOKEN",
"CUDDLE_PLEASE_TOKEN", match &args.server {
match &args.server { Server::Gitea { token, .. } => token,
Server::Gitea { token, .. } => token, Server::GitHub { token } => token,
Server::GitHub { token } => token, },
}, ),
)
.id()
.await?,
) )
.with_workdir("/mnt/app") .with_workdir("/mnt/app")
.with_directory(".", src.id().await?) .with_directory(".", src)
.with_exec(vec!["git", "remote", "set-url", "origin", &repo_url]) .with_exec(vec!["git", "remote", "set-url", "origin", &repo_url])
.with_exec(vec![ .with_exec(vec![
"cuddle-please", "cuddle-please",
@ -257,10 +251,7 @@ impl DaggerCuddlePlease {
}, },
]); ]);
let exit_code = res.exit_code().await?; res.sync().await?;
if exit_code != 0 {
eyre::bail!("failed to run cuddle-please");
}
let please_out = res.stdout().await?; let please_out = res.stdout().await?;
println!("{please_out}"); println!("{please_out}");
@ -269,37 +260,26 @@ impl DaggerCuddlePlease {
Ok(()) Ok(())
} }
pub async fn cuddle_please_src( pub async fn cuddle_please_src(&self, args: &CuddlePleaseSrcArgs) -> eyre::Result<()> {
&self, let build_image = self.client.container().from(&args.cuddle_image);
client: Arc<dagger_sdk::Query>,
args: &CuddlePleaseSrcArgs,
) -> eyre::Result<()> {
let build_image = client.container().from(&args.cuddle_image);
let res = build_image let res = build_image
.with_secret_variable( .with_secret_variable(
"CUDDLE_PLEASE_TOKEN", "CUDDLE_PLEASE_TOKEN",
client self.client.set_secret(
.set_secret( "CUDDLE_PLEASE_TOKEN",
"CUDDLE_PLEASE_TOKEN", match &args.server {
match &args.server { SrcServer::Gitea { token, .. } => token,
SrcServer::Gitea { token, .. } => token, SrcServer::GitHub { token } => token,
SrcServer::GitHub { token } => token, },
}, ),
)
.id()
.await?,
) )
.with_workdir("/mnt/app") .with_workdir("/mnt/app")
.with_directory(".", client.host().directory(".").id().await?) .with_directory(".", self.client.host().directory("."))
.with_unix_socket( .with_unix_socket(
"/tmp/ssh.sock", "/tmp/ssh.sock",
client self.client.host().unix_socket(
.host() std::env::var("SSH_AUTH_SOCK").expect("expect SSH_AUTH_SOCK to be present"),
.unix_socket( ),
std::env::var("SSH_AUTH_SOCK").expect("expect SSH_AUTH_SOCK to be present"),
)
.id()
.await?,
) )
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh.sock") .with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh.sock")
.with_new_file_opts( .with_new_file_opts(
@ -357,10 +337,7 @@ Host *
}, },
]); ]);
let exit_code = res.exit_code().await?; res.sync().await?;
if exit_code != 0 {
eyre::bail!("failed to run cuddle-please");
}
let please_out = res.stdout().await?; let please_out = res.stdout().await?;
println!("{please_out}"); println!("{please_out}");

View File

@ -4,12 +4,12 @@ use crate::source::RustSource;
#[allow(dead_code)] #[allow(dead_code)]
pub struct RustBuild { pub struct RustBuild {
client: Arc<dagger_sdk::Query>, client: dagger_sdk::Query,
registry: Option<String>, registry: Option<String>,
} }
impl RustBuild { impl RustBuild {
pub fn new(client: Arc<dagger_sdk::Query>) -> Self { pub fn new(client: dagger_sdk::Query) -> Self {
Self { Self {
client, client,
registry: None, registry: None,
@ -60,9 +60,9 @@ impl RustBuild {
} }
let rust_prebuild = rust_build_image let rust_prebuild = rust_build_image
.with_workdir("/mnt/src") .with_workdir("/mnt/src")
.with_directory("/mnt/src", dep_src.id().await?) .with_directory("/mnt/src", dep_src)
.with_exec(build_options) .with_exec(build_options)
.with_mounted_cache("/mnt/src/target/", target_cache.id().await?); .with_mounted_cache("/mnt/src/target/", target_cache);
let incremental_dir = rust_source let incremental_dir = rust_source
.get_rust_target_src(&source, rust_prebuild.clone(), crates.to_vec()) .get_rust_target_src(&source, rust_prebuild.clone(), crates.to_vec())
@ -72,10 +72,10 @@ impl RustBuild {
.with_workdir("/mnt/src") .with_workdir("/mnt/src")
.with_directory( .with_directory(
"/usr/local/cargo", "/usr/local/cargo",
rust_prebuild.directory("/usr/local/cargo").id().await?, rust_prebuild.directory("/usr/local/cargo"),
) )
.with_directory("/mnt/src/target", incremental_dir.id().await?) .with_directory("/mnt/src/target", incremental_dir)
.with_directory("/mnt/src/", src.id().await?); .with_directory("/mnt/src/", src);
Ok(rust_with_src) Ok(rust_with_src)
} }
@ -210,10 +210,10 @@ impl RustBuild {
.with_exec(packages); .with_exec(packages);
let final_image = base_debian let final_image = base_debian
.with_file(format!("/usr/local/bin/{}", bin_name), bin.id().await?) .with_file(format!("/usr/local/bin/{}", bin_name), bin)
.with_exec(vec![bin_name, "--help"]); .with_exec(vec![bin_name, "--help"]);
final_image.exit_code().await?; final_image.sync().await?;
Ok(final_image) Ok(final_image)
} }
@ -238,8 +238,7 @@ impl RustBuild {
packages.extend_from_slice(production_deps); packages.extend_from_slice(production_deps);
let base_debian = base_debian.with_exec(packages); let base_debian = base_debian.with_exec(packages);
let final_image = let final_image = base_debian.with_file(format!("/usr/local/bin/{}", bin_name), bin);
base_debian.with_file(format!("/usr/local/bin/{}", bin_name), bin.id().await?);
Ok(final_image) Ok(final_image)
} }

View File

@ -28,6 +28,8 @@ impl RustPublish {
format!("{}:{}", image.into(), tag.into()), format!("{}:{}", image.into(), tag.into()),
dagger_sdk::ContainerPublishOpts { dagger_sdk::ContainerPublishOpts {
platform_variants: Some(ids), platform_variants: Some(ids),
forced_compression: None,
media_types: None,
}, },
) )
.await?; .await?;

View File

@ -6,13 +6,13 @@ use std::{
use eyre::Context; use eyre::Context;
pub struct RustSource { pub struct RustSource {
client: Arc<dagger_sdk::Query>, client: dagger_sdk::Query,
exclude: Vec<String>, exclude: Vec<String>,
} }
impl RustSource { impl RustSource {
pub fn new(client: Arc<dagger_sdk::Query>) -> Self { pub fn new(client: dagger_sdk::Query) -> Self {
Self { Self {
client, client,
exclude: vec!["node_modules/", ".git/", "target/", ".cuddle/"] exclude: vec!["node_modules/", ".git/", "target/", ".cuddle/"]
@ -63,7 +63,7 @@ impl RustSource {
let src = self.get_src(source.clone()).await?; let src = self.get_src(source.clone()).await?;
let rust_src = self.get_rust_dep_src(source).await?; let rust_src = self.get_rust_dep_src(source).await?;
let rust_src = rust_src.with_directory(".", skeleton_files.id().await?); let rust_src = rust_src.with_directory(".", skeleton_files);
Ok((src, rust_src)) Ok((src, rust_src))
} }
@ -119,7 +119,7 @@ impl RustSource {
let incremental_dir = self.client.directory().with_directory_opts( let incremental_dir = self.client.directory().with_directory_opts(
".", ".",
container.directory("target").id().await?, container.directory("target"),
dagger_sdk::DirectoryWithDirectoryOpts { dagger_sdk::DirectoryWithDirectoryOpts {
exclude: Some(exclude), exclude: Some(exclude),
include: None, include: None,

View File

@ -3,12 +3,12 @@ use std::{path::PathBuf, sync::Arc};
use crate::{build::RustVersion, source::RustSource}; use crate::{build::RustVersion, source::RustSource};
pub struct RustTest { pub struct RustTest {
client: Arc<dagger_sdk::Query>, client: dagger_sdk::Query,
registry: Option<String>, registry: Option<String>,
} }
impl RustTest { impl RustTest {
pub fn new(client: Arc<dagger_sdk::Query>) -> Self { pub fn new(client: dagger_sdk::Query) -> Self {
Self { Self {
client, client,
registry: None, registry: None,
@ -45,9 +45,9 @@ impl RustTest {
let build_options = vec!["cargo", "build", "--workspace"]; let build_options = vec!["cargo", "build", "--workspace"];
let rust_prebuild = rust_build_image let rust_prebuild = rust_build_image
.with_workdir("/mnt/src") .with_workdir("/mnt/src")
.with_directory("/mnt/src", dep_src.id().await?) .with_directory("/mnt/src", dep_src)
.with_exec(build_options) .with_exec(build_options)
.with_mounted_cache("/mnt/src/target/", target_cache.id().await?); .with_mounted_cache("/mnt/src/target/", target_cache);
let incremental_dir = rust_source let incremental_dir = rust_source
.get_rust_target_src(&source, rust_prebuild.clone(), crates.to_vec()) .get_rust_target_src(&source, rust_prebuild.clone(), crates.to_vec())
@ -57,10 +57,10 @@ impl RustTest {
.with_workdir("/mnt/src") .with_workdir("/mnt/src")
.with_directory( .with_directory(
"/usr/local/cargo", "/usr/local/cargo",
rust_prebuild.directory("/usr/local/cargo").id().await?, rust_prebuild.directory("/usr/local/cargo"),
) )
.with_directory("/mnt/src/target", incremental_dir.id().await?) .with_directory("/mnt/src/target", incremental_dir)
.with_directory("/mnt/src/", src.id().await?); .with_directory("/mnt/src/", src);
let test = rust_with_src.with_exec(vec!["cargo", "test"]); let test = rust_with_src.with_exec(vec!["cargo", "test"]);
@ -68,9 +68,7 @@ impl RustTest {
let stderr = test.stderr().await?; let stderr = test.stderr().await?;
println!("stdout: {}, stderr: {}", stdout, stderr); println!("stdout: {}, stderr: {}", stdout, stderr);
if 0 != test.exit_code().await? { test.sync().await?;
eyre::bail!("failed rust:test");
}
Ok(()) Ok(())
} }

View File

@ -4,7 +4,7 @@ use dagger_cuddle_please::{models::CuddlePleaseArgs, DaggerCuddlePleaseAction};
pub async fn main() -> eyre::Result<()> { pub async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?; let client = dagger_sdk::connect().await?;
DaggerCuddlePleaseAction::dagger(client.clone()) DaggerCuddlePleaseAction::dagger(client)
.execute(&CuddlePleaseArgs { .execute(&CuddlePleaseArgs {
repository: "dagger-components".into(), repository: "dagger-components".into(),
owner: "kjuulh".into(), owner: "kjuulh".into(),

View File

@ -22,7 +22,7 @@ pub async fn main() -> eyre::Result<()> {
.await?; .await?;
for container in containers { for container in containers {
container.exit_code().await?; container.sync().await?;
} }
Ok(()) Ok(())