feat: with updated dagger-sdk
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
e2c7f46378
commit
52914e08e6
480
Cargo.lock
generated
480
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,8 @@ dagger-cuddle-please = { path = "crates/dagger-cuddle-please" }
|
||||
dagger-rust = { path = "crates/dagger-rust" }
|
||||
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"
|
||||
tokio = "1.31.0"
|
||||
dotenv = "0.15.0"
|
||||
|
@ -8,8 +8,8 @@ edition = "2021"
|
||||
[dependencies]
|
||||
dagger-cuddle-please.workspace = true
|
||||
dagger-rust.workspace = true
|
||||
dagger-sdk.workspace = true
|
||||
|
||||
dagger-sdk = "*"
|
||||
eyre = "*"
|
||||
color-eyre = "*"
|
||||
tokio = "1"
|
||||
|
@ -74,7 +74,7 @@ async fn main() -> eyre::Result<()> {
|
||||
LocalCommands::PleaseRelease => todo!(),
|
||||
},
|
||||
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;
|
||||
|
||||
test::execute(client.clone(), args).await.unwrap();
|
||||
@ -83,13 +83,13 @@ async fn main() -> eyre::Result<()> {
|
||||
tokio::join!(test(client.clone(), &cli),);
|
||||
}
|
||||
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;
|
||||
|
||||
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)
|
||||
.await
|
||||
.unwrap();
|
||||
@ -114,7 +114,7 @@ mod please_release {
|
||||
use crate::GlobalArgs;
|
||||
|
||||
pub async fn run_release_please(
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
args: &GlobalArgs,
|
||||
) -> eyre::Result<()> {
|
||||
DaggerCuddlePleaseAction::dagger(client)
|
||||
@ -142,7 +142,7 @@ mod test {
|
||||
|
||||
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)
|
||||
.test(
|
||||
None::<PathBuf>,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use models::{CuddlePleaseArgs, CuddlePleaseSrcArgs};
|
||||
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 {
|
||||
/// 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)))
|
||||
}
|
||||
|
||||
@ -104,31 +104,27 @@ impl DaggerCuddlePleaseAction {
|
||||
|
||||
#[derive(Clone)]
|
||||
struct DaggerCuddlePlease {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl CuddlePlease for DaggerCuddlePlease {
|
||||
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<()> {
|
||||
self.cuddle_please_src(self.client.clone(), args).await
|
||||
self.cuddle_please_src(args).await
|
||||
}
|
||||
}
|
||||
|
||||
impl DaggerCuddlePlease {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self { client }
|
||||
}
|
||||
|
||||
pub async fn cuddle_please(
|
||||
&self,
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
args: &CuddlePleaseArgs,
|
||||
) -> eyre::Result<()> {
|
||||
let build_image = client.container().from(&args.cuddle_image);
|
||||
pub async fn cuddle_please(&self, args: &CuddlePleaseArgs) -> eyre::Result<()> {
|
||||
let build_image = self.client.container().from(&args.cuddle_image);
|
||||
|
||||
let repo_url = match &args.server {
|
||||
Server::Gitea {
|
||||
@ -182,11 +178,12 @@ impl DaggerCuddlePlease {
|
||||
};
|
||||
|
||||
let src = if args.use_ssh_socket {
|
||||
let socket = client
|
||||
let socket = self
|
||||
.client
|
||||
.host()
|
||||
.unix_socket(std::env::var("SSH_AGENT").expect("SSH_AGENT to be set"));
|
||||
|
||||
client
|
||||
self.client
|
||||
.git_opts(
|
||||
&repo_url,
|
||||
dagger_sdk::QueryGitOpts {
|
||||
@ -200,7 +197,7 @@ impl DaggerCuddlePlease {
|
||||
ssh_known_hosts: None,
|
||||
})
|
||||
} else {
|
||||
client
|
||||
self.client
|
||||
.git_opts(
|
||||
&repo_url,
|
||||
dagger_sdk::QueryGitOpts {
|
||||
@ -215,19 +212,16 @@ impl DaggerCuddlePlease {
|
||||
let res = build_image
|
||||
.with_secret_variable(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
client
|
||||
.set_secret(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
match &args.server {
|
||||
Server::Gitea { token, .. } => token,
|
||||
Server::GitHub { token } => token,
|
||||
},
|
||||
)
|
||||
.id()
|
||||
.await?,
|
||||
self.client.set_secret(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
match &args.server {
|
||||
Server::Gitea { token, .. } => token,
|
||||
Server::GitHub { token } => token,
|
||||
},
|
||||
),
|
||||
)
|
||||
.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![
|
||||
"cuddle-please",
|
||||
@ -257,10 +251,7 @@ impl DaggerCuddlePlease {
|
||||
},
|
||||
]);
|
||||
|
||||
let exit_code = res.exit_code().await?;
|
||||
if exit_code != 0 {
|
||||
eyre::bail!("failed to run cuddle-please");
|
||||
}
|
||||
res.sync().await?;
|
||||
|
||||
let please_out = res.stdout().await?;
|
||||
println!("{please_out}");
|
||||
@ -269,37 +260,26 @@ impl DaggerCuddlePlease {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
pub async fn cuddle_please_src(
|
||||
&self,
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
args: &CuddlePleaseSrcArgs,
|
||||
) -> eyre::Result<()> {
|
||||
let build_image = client.container().from(&args.cuddle_image);
|
||||
pub async fn cuddle_please_src(&self, args: &CuddlePleaseSrcArgs) -> eyre::Result<()> {
|
||||
let build_image = self.client.container().from(&args.cuddle_image);
|
||||
let res = build_image
|
||||
.with_secret_variable(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
client
|
||||
.set_secret(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
match &args.server {
|
||||
SrcServer::Gitea { token, .. } => token,
|
||||
SrcServer::GitHub { token } => token,
|
||||
},
|
||||
)
|
||||
.id()
|
||||
.await?,
|
||||
self.client.set_secret(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
match &args.server {
|
||||
SrcServer::Gitea { token, .. } => token,
|
||||
SrcServer::GitHub { token } => token,
|
||||
},
|
||||
),
|
||||
)
|
||||
.with_workdir("/mnt/app")
|
||||
.with_directory(".", client.host().directory(".").id().await?)
|
||||
.with_directory(".", self.client.host().directory("."))
|
||||
.with_unix_socket(
|
||||
"/tmp/ssh.sock",
|
||||
client
|
||||
.host()
|
||||
.unix_socket(
|
||||
std::env::var("SSH_AUTH_SOCK").expect("expect SSH_AUTH_SOCK to be present"),
|
||||
)
|
||||
.id()
|
||||
.await?,
|
||||
self.client.host().unix_socket(
|
||||
std::env::var("SSH_AUTH_SOCK").expect("expect SSH_AUTH_SOCK to be present"),
|
||||
),
|
||||
)
|
||||
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh.sock")
|
||||
.with_new_file_opts(
|
||||
@ -357,10 +337,7 @@ Host *
|
||||
},
|
||||
]);
|
||||
|
||||
let exit_code = res.exit_code().await?;
|
||||
if exit_code != 0 {
|
||||
eyre::bail!("failed to run cuddle-please");
|
||||
}
|
||||
res.sync().await?;
|
||||
|
||||
let please_out = res.stdout().await?;
|
||||
println!("{please_out}");
|
||||
|
@ -4,12 +4,12 @@ use crate::source::RustSource;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct RustBuild {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
registry: Option<String>,
|
||||
}
|
||||
|
||||
impl RustBuild {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self {
|
||||
client,
|
||||
registry: None,
|
||||
@ -60,9 +60,9 @@ impl RustBuild {
|
||||
}
|
||||
let rust_prebuild = rust_build_image
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory("/mnt/src", dep_src.id().await?)
|
||||
.with_directory("/mnt/src", dep_src)
|
||||
.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
|
||||
.get_rust_target_src(&source, rust_prebuild.clone(), crates.to_vec())
|
||||
@ -72,10 +72,10 @@ impl RustBuild {
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory(
|
||||
"/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/", src.id().await?);
|
||||
.with_directory("/mnt/src/target", incremental_dir)
|
||||
.with_directory("/mnt/src/", src);
|
||||
|
||||
Ok(rust_with_src)
|
||||
}
|
||||
@ -210,10 +210,10 @@ impl RustBuild {
|
||||
.with_exec(packages);
|
||||
|
||||
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"]);
|
||||
|
||||
final_image.exit_code().await?;
|
||||
final_image.sync().await?;
|
||||
|
||||
Ok(final_image)
|
||||
}
|
||||
@ -238,8 +238,7 @@ impl RustBuild {
|
||||
packages.extend_from_slice(production_deps);
|
||||
let base_debian = base_debian.with_exec(packages);
|
||||
|
||||
let final_image =
|
||||
base_debian.with_file(format!("/usr/local/bin/{}", bin_name), bin.id().await?);
|
||||
let final_image = base_debian.with_file(format!("/usr/local/bin/{}", bin_name), bin);
|
||||
|
||||
Ok(final_image)
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ impl RustPublish {
|
||||
format!("{}:{}", image.into(), tag.into()),
|
||||
dagger_sdk::ContainerPublishOpts {
|
||||
platform_variants: Some(ids),
|
||||
forced_compression: None,
|
||||
media_types: None,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
@ -6,13 +6,13 @@ use std::{
|
||||
use eyre::Context;
|
||||
|
||||
pub struct RustSource {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
|
||||
exclude: Vec<String>,
|
||||
}
|
||||
|
||||
impl RustSource {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self {
|
||||
client,
|
||||
exclude: vec!["node_modules/", ".git/", "target/", ".cuddle/"]
|
||||
@ -63,7 +63,7 @@ impl RustSource {
|
||||
|
||||
let src = self.get_src(source.clone()).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))
|
||||
}
|
||||
@ -119,7 +119,7 @@ impl RustSource {
|
||||
|
||||
let incremental_dir = self.client.directory().with_directory_opts(
|
||||
".",
|
||||
container.directory("target").id().await?,
|
||||
container.directory("target"),
|
||||
dagger_sdk::DirectoryWithDirectoryOpts {
|
||||
exclude: Some(exclude),
|
||||
include: None,
|
||||
|
@ -3,12 +3,12 @@ use std::{path::PathBuf, sync::Arc};
|
||||
use crate::{build::RustVersion, source::RustSource};
|
||||
|
||||
pub struct RustTest {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
registry: Option<String>,
|
||||
}
|
||||
|
||||
impl RustTest {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self {
|
||||
client,
|
||||
registry: None,
|
||||
@ -45,9 +45,9 @@ impl RustTest {
|
||||
let build_options = vec!["cargo", "build", "--workspace"];
|
||||
let rust_prebuild = rust_build_image
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory("/mnt/src", dep_src.id().await?)
|
||||
.with_directory("/mnt/src", dep_src)
|
||||
.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
|
||||
.get_rust_target_src(&source, rust_prebuild.clone(), crates.to_vec())
|
||||
@ -57,10 +57,10 @@ impl RustTest {
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory(
|
||||
"/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/", src.id().await?);
|
||||
.with_directory("/mnt/src/target", incremental_dir)
|
||||
.with_directory("/mnt/src/", src);
|
||||
|
||||
let test = rust_with_src.with_exec(vec!["cargo", "test"]);
|
||||
|
||||
@ -68,9 +68,7 @@ impl RustTest {
|
||||
let stderr = test.stderr().await?;
|
||||
println!("stdout: {}, stderr: {}", stdout, stderr);
|
||||
|
||||
if 0 != test.exit_code().await? {
|
||||
eyre::bail!("failed rust:test");
|
||||
}
|
||||
test.sync().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use dagger_cuddle_please::{models::CuddlePleaseArgs, DaggerCuddlePleaseAction};
|
||||
pub async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect().await?;
|
||||
|
||||
DaggerCuddlePleaseAction::dagger(client.clone())
|
||||
DaggerCuddlePleaseAction::dagger(client)
|
||||
.execute(&CuddlePleaseArgs {
|
||||
repository: "dagger-components".into(),
|
||||
owner: "kjuulh".into(),
|
||||
|
@ -22,7 +22,7 @@ pub async fn main() -> eyre::Result<()> {
|
||||
.await?;
|
||||
|
||||
for container in containers {
|
||||
container.exit_code().await?;
|
||||
container.sync().await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user