Compare commits

..

6 Commits

Author SHA1 Message Date
a6d4b9e062 fix: cargo clippy 2023-02-19 17:54:45 +01:00
e5bfbe7218 fix: roadmap item api stabilization 2023-02-19 17:52:48 +01:00
57ecf97d23 feat(sdk): without Some in _opts functions
Option has been removed as a wrapper around opts. This makes it much
more convenient to use

```rust
client.container_opts(Some(ContainerOpts{}))
// ->
client.container_opts(ContainerOpts{})
```

The same options are still available, either an empty object can be
passed, or a non _opts function can be used
2023-02-19 17:49:22 +01:00
6779808322 feat(sdk): with _opts methods
Now all opt values enter into a _opts function instead of the original.
This avoids a lot of verbosity for both None in the case opts are
unwanted, and Some() if they actually are.

They are used like so:

```rust
client.container().from("...");
client.container_opts(Some(ContainerOpts{ ... }))
```

Some from opts will be removed in a future commit/pr
2023-02-19 17:43:12 +01:00
b25b350d90 fix(sdk): without phantom data 2023-02-19 17:30:03 +01:00
c14cd64453 feat(sdk): move to &str instead of String and introduce builder.
This will make the api much easier to use, as we can now rely on ""
instead of "".into() for normal string values.

Introduced builder as well, which makes it much easier to use *Opts, as
it can handle the building of that, and get the benefits from String ->
&str, as that is currently not allowed for optional values
2023-02-19 17:21:40 +01:00
21 changed files with 566 additions and 1604 deletions

13
Cargo.lock generated
View File

@@ -114,7 +114,7 @@ version = "0.1.0"
dependencies = [
"clap",
"color-eyre",
"dagger-sdk 0.2.6",
"dagger-sdk 0.2.2",
"eyre",
]
@@ -245,7 +245,7 @@ dependencies = [
[[package]]
name = "dagger-codegen"
version = "0.2.4"
version = "0.2.3"
dependencies = [
"convert_case",
"dagger-core 0.2.2",
@@ -330,16 +330,17 @@ dependencies = [
[[package]]
name = "dagger-sdk"
version = "0.2.6"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "654625e954f59d70eb897bb681936c3e8b69c5f6e528f85c0b307554883db63f"
checksum = "d1562df6d7d47fbb891331896ec9c04da1db129c1a9f073c40c33ab918f06e99"
dependencies = [
"base64",
"dagger-core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"derive_builder",
"eyre",
"futures",
"genco",
"gql_client",
"pretty_assertions",
"serde",
"serde_json",
"tokio",
@@ -347,7 +348,7 @@ dependencies = [
[[package]]
name = "dagger-sdk"
version = "0.2.7"
version = "0.2.4"
dependencies = [
"base64",
"dagger-core 0.2.2",

View File

@@ -24,7 +24,7 @@ See [dagger-sdk](./crates/dagger-sdk/README.md)
- [x] fix build / release cycle
- [x] general api stabilisation
- [x] document usage
- [x] make async variant
- [ ] make async variant
## Architecture

View File

@@ -8,5 +8,5 @@ edition = "2021"
[dependencies]
clap = "4.1.6"
color-eyre = "0.6.2"
dagger-sdk = "0.2.6"
dagger-sdk = "0.2.2"
eyre = "0.6.8"

View File

@@ -1,6 +1,6 @@
use std::sync::Arc;
use dagger_sdk::{Container, HostDirectoryOpts, Query};
use dagger_sdk::gen::{Container, HostDirectoryOpts, Query};
fn main() -> eyre::Result<()> {
color_eyre::install().unwrap();
@@ -11,11 +11,11 @@ fn main() -> eyre::Result<()> {
.subcommand(clap::Command::new("release"))
.get_matches();
let client = dagger_sdk::connect()?;
let client = dagger_sdk::client::connect()?;
match matches.subcommand() {
Some(("pr", _)) => {
let base = select_base_image(client.clone())?;
let base = select_base_image(client.clone());
return validate_pr(client, base);
}
Some(("release", subm)) => return release(client, subm),
@@ -29,31 +29,41 @@ fn main() -> eyre::Result<()> {
}
fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> {
let src_dir = client.host().directory_opts(
".",
HostDirectoryOpts {
exclude: Some(vec!["target/"]),
let src_dir = client.host().directory(
".".into(),
Some(HostDirectoryOpts {
exclude: Some(vec!["target/".into()]),
include: None,
},
}),
);
let base_image = client
.container()
.from("rust:latest")
.with_workdir("app")
.with_mounted_directory("/app/", src_dir.id()?);
.container(None)
.from("rust:latest".into())
.with_workdir("app".into())
.with_mounted_directory("/app/".into(), src_dir.id());
let container = base_image
.with_exec(vec!["cargo", "install", "cargo-smart-release"])
.with_exec(vec![
"cargo",
"smart-release",
"--execute",
"--allow-fully-generated-changelogs",
"--no-changelog-preview",
"dagger-rs",
"dagger-sdk",
]);
let exit = container.exit_code()?;
.with_exec(
vec![
"cargo".into(),
"install".into(),
"cargo-smart-release".into(),
],
None,
)
.with_exec(
vec![
"cargo".into(),
"smart-release".into(),
"--execute".into(),
"--allow-fully-generated-changelogs".into(),
"--no-changelog-preview".into(),
"dagger-rs".into(),
"dagger-sdk".into(),
],
None,
);
let exit = container.exit_code();
if exit != 0 {
eyre::bail!("container failed with non-zero exit code");
}
@@ -63,111 +73,153 @@ fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), color_eyr
Ok(())
}
fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> {
let cargo_dir = client.host().directory_opts(
".",
HostDirectoryOpts {
fn get_dependencies(client: Arc<Query>) -> Container {
let cargo_dir = client.host().directory(
".".into(),
Some(HostDirectoryOpts {
exclude: None,
include: Some(vec![
"**/Cargo.lock",
"**/Cargo.toml",
"**/main.rs",
"**/lib.rs",
"**/Cargo.lock".into(),
"**/Cargo.toml".into(),
"**/main.rs".into(),
"**/lib.rs".into(),
]),
},
}),
);
let src_dir = client.host().directory_opts(
".",
HostDirectoryOpts {
exclude: Some(vec!["target/"]),
let src_dir = client.host().directory(
".".into(),
Some(HostDirectoryOpts {
exclude: Some(vec!["target/".into()]),
include: None,
},
}),
);
let cache_cargo_index_dir = client.cache_volume("cargo_index");
let cache_cargo_deps = client.cache_volume("cargo_deps");
let cache_cargo_bin = client.cache_volume("cargo_bin_cache");
let cache_cargo_index_dir = client.cache_volume("cargo_index".into());
let cache_cargo_deps = client.cache_volume("cargo_deps".into());
let cache_cargo_bin = client.cache_volume("cargo_bin_cache".into());
let minio_url = "https://github.com/mozilla/sccache/releases/download/v0.3.3/sccache-v0.3.3-x86_64-unknown-linux-musl.tar.gz";
let minio_url = "https://github.com/mozilla/sccache/releases/download/v0.3.3/sccache-v0.3.3-x86_64-unknown-linux-musl.tar.gz".into();
let base_image = client
.container()
.from("rust:latest")
.with_workdir("app")
.with_exec(vec!["apt-get", "update"])
.with_exec(vec!["apt-get", "install", "--yes", "libpq-dev", "wget"])
.with_exec(vec!["wget", minio_url])
.with_exec(vec![
"tar",
"xzf",
"sccache-v0.3.3-x86_64-unknown-linux-musl.tar.gz",
])
.with_exec(vec![
"mv",
"sccache-v0.3.3-x86_64-unknown-linux-musl/sccache",
"/usr/local/bin/sccache",
])
.with_exec(vec!["chmod", "+x", "/usr/local/bin/sccache"])
.with_env_variable("RUSTC_WRAPPER", "/usr/local/bin/sccache")
.container(None)
.from("rust:latest".into())
.with_workdir("app".into())
.with_exec(vec!["apt-get".into(), "update".into()], None)
.with_exec(
vec![
"apt-get".into(),
"install".into(),
"--yes".into(),
"libpq-dev".into(),
"wget".into(),
],
None,
)
.with_exec(vec!["wget".into(), minio_url], None)
.with_exec(
vec![
"tar".into(),
"xzf".into(),
"sccache-v0.3.3-x86_64-unknown-linux-musl.tar.gz".into(),
],
None,
)
.with_exec(
vec![
"mv".into(),
"sccache-v0.3.3-x86_64-unknown-linux-musl/sccache".into(),
"/usr/local/bin/sccache".into(),
],
None,
)
.with_exec(
vec!["chmod".into(), "+x".into(), "/usr/local/bin/sccache".into()],
None,
)
.with_env_variable("RUSTC_WRAPPER".into(), "/usr/local/bin/sccache".into())
.with_env_variable(
"AWS_ACCESS_KEY_ID",
"AWS_ACCESS_KEY_ID".into(),
std::env::var("AWS_ACCESS_KEY_ID").unwrap_or("".into()),
)
.with_env_variable(
"AWS_SECRET_ACCESS_KEY",
"AWS_SECRET_ACCESS_KEY".into(),
std::env::var("AWS_SECRET_ACCESS_KEY").unwrap_or("".into()),
)
.with_env_variable("SCCACHE_BUCKET", "sccache")
.with_env_variable("SCCACHE_REGION", "auto")
.with_env_variable("SCCACHE_ENDPOINT", "https://api-minio.front.kjuulh.io")
.with_mounted_cache("~/.cargo/bin", cache_cargo_bin.id()?)
.with_mounted_cache("~/.cargo/registry/index", cache_cargo_bin.id()?)
.with_mounted_cache("~/.cargo/registry/cache", cache_cargo_bin.id()?)
.with_mounted_cache("~/.cargo/git/db", cache_cargo_bin.id()?)
.with_mounted_cache("target/", cache_cargo_bin.id()?)
.with_exec(vec!["cargo", "install", "cargo-chef"]);
.with_env_variable("SCCACHE_BUCKET".into(), "sccache".into())
.with_env_variable("SCCACHE_REGION".into(), "auto".into())
.with_env_variable(
"SCCACHE_ENDPOINT".into(),
"https://api-minio.front.kjuulh.io".into(),
)
.with_mounted_cache("~/.cargo/bin".into(), cache_cargo_bin.id(), None)
.with_mounted_cache("~/.cargo/registry/index".into(), cache_cargo_bin.id(), None)
.with_mounted_cache("~/.cargo/registry/cache".into(), cache_cargo_bin.id(), None)
.with_mounted_cache("~/.cargo/git/db".into(), cache_cargo_bin.id(), None)
.with_mounted_cache("target/".into(), cache_cargo_bin.id(), None)
.with_exec(
vec!["cargo".into(), "install".into(), "cargo-chef".into()],
None,
);
let recipe = base_image
.with_mounted_directory(".", cargo_dir.id()?)
.with_mounted_cache("~/.cargo/.package-cache", cache_cargo_index_dir.id()?)
.with_exec(vec![
"cargo",
"chef",
"prepare",
"--recipe-path",
"recipe.json",
])
.file("/app/recipe.json");
.with_mounted_directory(".".into(), cargo_dir.id())
.with_mounted_cache(
"~/.cargo/.package-cache".into(),
cache_cargo_index_dir.id(),
None,
)
.with_exec(
vec![
"cargo".into(),
"chef".into(),
"prepare".into(),
"--recipe-path".into(),
"recipe.json".into(),
],
None,
)
.file("/app/recipe.json".into());
let builder_start = base_image
.with_mounted_file("/app/recipe.json", recipe.id()?)
.with_exec(vec![
"cargo",
"chef",
"cook",
"--release",
"--workspace",
"--recipe-path",
"recipe.json",
])
.with_mounted_cache("/app/", cache_cargo_deps.id()?)
.with_mounted_directory("/app/", src_dir.id()?)
.with_exec(vec!["cargo", "build", "--all", "--release"]);
.with_mounted_file("/app/recipe.json".into(), recipe.id())
.with_exec(
vec![
"cargo".into(),
"chef".into(),
"cook".into(),
"--release".into(),
"--workspace".into(),
"--recipe-path".into(),
"recipe.json".into(),
],
None,
)
.with_mounted_cache("/app/".into(), cache_cargo_deps.id(), None)
.with_mounted_directory("/app/".into(), src_dir.id())
.with_exec(
vec![
"cargo".into(),
"build".into(),
"--all".into(),
"--release".into(),
],
None,
);
return Ok(builder_start);
return builder_start;
}
fn select_base_image(client: Arc<Query>) -> eyre::Result<Container> {
fn select_base_image(client: Arc<Query>) -> Container {
let src_dir = get_dependencies(client.clone());
src_dir
}
fn validate_pr(_client: Arc<Query>, container: Container) -> eyre::Result<()> {
//let container = container.with_exec(vec!["cargo", "test", "--all"], None);
//let container = container.with_exec(vec!["cargo".into(), "test".into(), "--all".into()], None);
let exit = container.exit_code()?;
let exit = container.exit_code();
if exit != 0 {
eyre::bail!("container failed with non-zero exit code");
}

View File

@@ -5,70 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.2.4 (2023-02-19)
### New Features
- <csr-id-f29ff836cfd72d5e051ca6a71a230ba1e9933091/> without Some in _opts functions
Option has been removed as a wrapper around opts. This makes it much
more convenient to use
```rust
client.container_opts(Some(ContainerOpts{}))
// ->
client.container_opts(ContainerOpts{})
```
The same options are still available, either an empty object can be
passed, or a non _opts function can be used
- <csr-id-9762da895a164e30c5dc60e89a83e934ceae47ab/> with _opts methods
Now all opt values enter into a _opts function instead of the original.
This avoids a lot of verbosity for both None in the case opts are
unwanted, and Some() if they actually are.
They are used like so:
```rust
client.container().from("...");
client.container_opts(Some(ContainerOpts{ ... }))
```
Some from opts will be removed in a future commit/pr
- <csr-id-94336d06378f035464e233b921dc3858070f582d/> move to &str instead of String and introduce builder.
This will make the api much easier to use, as we can now rely on ""
instead of "".into() for normal string values.
Introduced builder as well, which makes it much easier to use *Opts, as
it can handle the building of that, and get the benefits from String ->
&str, as that is currently not allowed for optional values
### Bug Fixes
- <csr-id-c627595fd2695e236924175d137c42f1480ccd6b/> cargo clippy
- <csr-id-02006d40fc2c0383e0412c15c36db9af7eda991f/> without phantom data
### Commit Statistics
<csr-read-only-do-not-edit/>
- 5 commits contributed to the release.
- 5 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- cargo clippy ([`c627595`](https://github.com/kjuulh/dagger-rs/commit/c627595fd2695e236924175d137c42f1480ccd6b))
- without Some in _opts functions ([`f29ff83`](https://github.com/kjuulh/dagger-rs/commit/f29ff836cfd72d5e051ca6a71a230ba1e9933091))
- with _opts methods ([`9762da8`](https://github.com/kjuulh/dagger-rs/commit/9762da895a164e30c5dc60e89a83e934ceae47ab))
- without phantom data ([`02006d4`](https://github.com/kjuulh/dagger-rs/commit/02006d40fc2c0383e0412c15c36db9af7eda991f))
- move to &str instead of String and introduce builder. ([`94336d0`](https://github.com/kjuulh/dagger-rs/commit/94336d06378f035464e233b921dc3858070f582d))
</details>
## v0.2.3 (2023-02-19)
### New Features
@@ -80,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/>
- 3 commits contributed to the release.
- 2 commits contributed to the release.
- 2 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
@@ -91,7 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<details><summary>view details</summary>
* **Uncategorized**
- Release dagger-sdk v0.2.3, dagger-codegen v0.2.3, dagger-rs v0.2.9 ([`9235030`](https://github.com/kjuulh/dagger-rs/commit/92350306b3f0da40b4fc6dcaffcd90b891e83f70))
- with return result instead of unwrap ([`de063ea`](https://github.com/kjuulh/dagger-rs/commit/de063eae858eb3335d2558a57ee6a88689635200))
- remove unnecessary option returns ([`5d66736`](https://github.com/kjuulh/dagger-rs/commit/5d667369900a47d3a6015cd3814c240bc5c54436))
</details>

View File

@@ -1,6 +1,6 @@
[package]
name = "dagger-codegen"
version = "0.2.4"
version = "0.2.3"
edition = "2021"
readme = "README.md"
license-file = "LICENSE.MIT"

View File

@@ -10,8 +10,6 @@ use crate::functions::{
};
use crate::utility::OptionExt;
use super::templates::object_tmpl::render_optional_field_args;
pub fn format_name(s: &str) -> String {
s.to_case(Case::Pascal)
}
@@ -31,44 +29,19 @@ pub fn field_options_struct_name(field: &FullTypeFields) -> Option<String> {
}
pub fn format_function(funcs: &CommonFunctions, field: &FullTypeFields) -> Option<rust::Tokens> {
let is_async = field.type_.pipe(|t| &t.type_ref).pipe(|t| {
if type_ref_is_object(&t) || type_ref_is_list_of_objects(&t) {
return None;
} else {
return Some(quote! {
async
});
};
});
let signature = quote! {
pub $(is_async) fn $(field.name.pipe(|n | format_struct_name(n)))
pub fn $(field.name.pipe(|n | format_struct_name(n)))
};
let lifecycle = format_optional_args(funcs, field)
.pipe(|(_, contains_lifecycle)| contains_lifecycle)
.and_then(|c| {
if *c {
Some(quote! {
<'a>
})
} else {
None
}
});
let args = format_function_args(funcs, field, lifecycle.as_ref());
let args = format_function_args(funcs, field);
let output_type = field
.type_
.pipe(|t| &t.type_ref)
.pipe(|t| render_output_type(funcs, t));
if let Some((args, desc, true)) = args {
if let Some((args, true)) = args {
let required_args = format_required_function_args(funcs, field);
Some(quote! {
$(field.description.pipe(|d| format_struct_comment(d)))
$(&desc)
$(&signature)(
$(required_args)
) -> $(output_type.as_ref()) {
@@ -79,9 +52,7 @@ pub fn format_function(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
$(render_execution(funcs, field))
}
$(field.description.pipe(|d| format_struct_comment(d)))
$(&desc)
$(&signature)_opts$(lifecycle)(
$(&signature)_opts(
$args
) -> $(output_type) {
let mut query = self.selection.select($(quoted(field.name.as_ref())));
@@ -94,10 +65,8 @@ pub fn format_function(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
})
} else {
Some(quote! {
$(field.description.pipe(|d| format_struct_comment(d)))
$(if let Some((_, desc, _)) = &args => $desc)
$(signature)(
$(if let Some((args, _, _)) = &args => $args)
$(if let Some((args, _)) = args => $args)
) -> $(output_type) {
let mut query = self.selection.select($(quoted(field.name.as_ref())));
@@ -266,16 +235,14 @@ fn render_execution(funcs: &CommonFunctions, field: &FullTypeFields) -> rust::To
let graphql_client = rust::import("crate::client", "graphql_client");
quote! {
query.execute(&$graphql_client(&self.conn)).await
query.execute(&$graphql_client(&self.conn))
}
}
fn format_function_args(
funcs: &CommonFunctions,
field: &FullTypeFields,
lifecycle: Option<&rust::Tokens>,
) -> Option<(rust::Tokens, rust::Tokens, bool)> {
let mut argument_description = Vec::new();
) -> Option<(rust::Tokens, bool)> {
if let Some(args) = field.args.as_ref() {
let args = args
.into_iter()
@@ -288,18 +255,6 @@ fn format_function_args(
let t = funcs.format_input_type(&s.input_value.type_);
let n = format_struct_name(&s.input_value.name);
if let Some(desc) = s.input_value.description.as_ref().and_then(|d| {
if d != "" {
Some(write_comment_line(&format!("* `{n}` - {}", d)))
} else {
None
}
}) {
argument_description.push(quote! {
$(desc)
});
}
Some(quote! {
$(n): $(t),
})
@@ -313,34 +268,15 @@ fn format_function_args(
};
if type_field_has_optional(field) {
let field_name = field_options_struct_name(field);
argument_description.push(quote! {
$(field_name.pipe(|_| write_comment_line(&format!("* `opt` - optional argument, see inner type for documentation, use <func>_opts to use"))))
});
let description = quote! {
$(if argument_description.len() > 0 => $(format!("/// ")))
$(if argument_description.len() > 0 => $(format!("/// # Arguments")))
$(if argument_description.len() > 0 => $(format!("/// ")))
$(for arg_desc in argument_description join ($['\r']) => $arg_desc)
};
Some((
quote! {
$(required_args)
opts: $(field_name)$(lifecycle)
opts: $(field_options_struct_name(field))
},
description,
true,
))
} else {
let description = quote! {
$(if argument_description.len() > 0 => $(format!("/// ")))
$(if argument_description.len() > 0 => $(format!("/// # Arguments")))
$(if argument_description.len() > 0 => $(format!("/// ")))
$(for arg_desc in argument_description join ($['\r']) => $arg_desc)
};
Some((required_args, description, false))
Some((required_args, false))
}
} else {
None
@@ -380,52 +316,3 @@ fn format_required_function_args(
None
}
}
pub fn format_optional_args(
funcs: &CommonFunctions,
field: &FullTypeFields,
) -> Option<(rust::Tokens, bool)> {
field
.args
.pipe(|t| t.into_iter().flatten().collect::<Vec<_>>())
.map(|t| {
t.into_iter()
.filter(|t| type_ref_is_optional(&t.input_value.type_))
.collect::<Vec<_>>()
})
.pipe(|t| render_optional_field_args(funcs, t))
.flatten()
}
pub fn write_comment_line(content: &str) -> Option<rust::Tokens> {
let cnt = content.trim();
if cnt == "" {
return None;
}
let mut tokens = rust::Tokens::new();
for line in content.split('\n') {
tokens.append(format!("/// {}", line.trim()));
tokens.push();
}
Some(tokens)
}
pub fn format_struct_comment(desc: &str) -> Option<rust::Tokens> {
let lines = desc.trim().split("\n");
let formatted_lines = lines
.into_iter()
.map(write_comment_line)
.collect::<Vec<_>>();
if formatted_lines.len() > 0 {
Some(quote! {
$(for line in formatted_lines join($['\r']) => $line)
})
} else {
None
}
}

View File

@@ -5,8 +5,7 @@ use itertools::Itertools;
use crate::functions::{type_ref_is_optional, CommonFunctions};
use crate::rust::functions::{
field_options_struct_name, format_function, format_name, format_optional_args,
format_struct_comment, format_struct_name,
field_options_struct_name, format_function, format_name, format_struct_name,
};
use crate::utility::OptionExt;
@@ -52,7 +51,16 @@ fn render_optional_args(
fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Option<rust::Tokens> {
let output_type = field_options_struct_name(field);
let fields = format_optional_args(funcs, field);
let fields = field
.args
.pipe(|t| t.into_iter().flatten().collect::<Vec<_>>())
.map(|t| {
t.into_iter()
.filter(|t| type_ref_is_optional(&t.input_value.type_))
.collect::<Vec<_>>()
})
.pipe(|t| render_optional_field_args(funcs, t))
.flatten();
let builder = rust::import("derive_builder", "Builder");
let _phantom_data = rust::import("std::marker", "PhantomData");
@@ -71,7 +79,7 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
}
}
pub fn render_optional_field_args(
fn render_optional_field_args(
funcs: &CommonFunctions,
args: &Vec<&FullTypeFieldsArgs>,
) -> Option<(rust::Tokens, bool)> {
@@ -85,7 +93,6 @@ pub fn render_optional_field_args(
contains_lifetime = true;
}
quote! {
$(a.description.pipe(|d| format_struct_comment(d)))
#[builder(setter(into, strip_option))]
pub $(format_struct_name(&a.name)): Option<$(type_)>,
}

View File

@@ -5,148 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.2.7 (2023-02-19)
### Documentation
- <csr-id-93f40b356c48f14e910968516bed9487912095c1/> change to await syntax
### New Features
- <csr-id-9be6f435d9ea39f31a8906e55dbd3e8b1e5ec598/> Use async runtime instead of blocking.
Default to using async runtime instead of blocking. I.e.
```rust
fn main() -> eyre::Result<()> {
// ...
client.container().from("rust").publish("somewhere")?;
// ...
}
// to
async fn main() -> eyre::Result<()> {
// ...
client.container().from("rust").publish("somewhere").await?;
// ...
}
```
### Commit Statistics
<csr-read-only-do-not-edit/>
- 2 commits contributed to the release.
- 2 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- change to await syntax ([`93f40b3`](https://github.com/kjuulh/dagger-rs/commit/93f40b356c48f14e910968516bed9487912095c1))
- Use async runtime instead of blocking. ([`9be6f43`](https://github.com/kjuulh/dagger-rs/commit/9be6f435d9ea39f31a8906e55dbd3e8b1e5ec598))
</details>
## v0.2.6 (2023-02-19)
### Documentation
- <csr-id-04e70ce964b343e28b3dbd0c46d10ccda958ab8c/> fix readme
### Commit Statistics
<csr-read-only-do-not-edit/>
- 2 commits contributed to the release.
- 1 commit was understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- Release dagger-sdk v0.2.6 ([`c312bc5`](https://github.com/kjuulh/dagger-rs/commit/c312bc57ad3e5380b6a2a927f3bb758aa5344efd))
- fix readme ([`04e70ce`](https://github.com/kjuulh/dagger-rs/commit/04e70ce964b343e28b3dbd0c46d10ccda958ab8c))
</details>
## v0.2.5 (2023-02-19)
### New Features
- <csr-id-f29ff836cfd72d5e051ca6a71a230ba1e9933091/> without Some in _opts functions
Option has been removed as a wrapper around opts. This makes it much
more convenient to use
```rust
client.container_opts(Some(ContainerOpts{}))
// ->
client.container_opts(ContainerOpts{})
```
The same options are still available, either an empty object can be
passed, or a non _opts function can be used
- <csr-id-9762da895a164e30c5dc60e89a83e934ceae47ab/> with _opts methods
Now all opt values enter into a _opts function instead of the original.
This avoids a lot of verbosity for both None in the case opts are
unwanted, and Some() if they actually are.
They are used like so:
```rust
client.container().from("...");
client.container_opts(Some(ContainerOpts{ ... }))
```
Some from opts will be removed in a future commit/pr
- <csr-id-94336d06378f035464e233b921dc3858070f582d/> move to &str instead of String and introduce builder.
This will make the api much easier to use, as we can now rely on ""
instead of "".into() for normal string values.
Introduced builder as well, which makes it much easier to use *Opts, as
it can handle the building of that, and get the benefits from String ->
&str, as that is currently not allowed for optional values
### Bug Fixes
- <csr-id-c627595fd2695e236924175d137c42f1480ccd6b/> cargo clippy
- <csr-id-02006d40fc2c0383e0412c15c36db9af7eda991f/> without phantom data
- <csr-id-6e2292cf11942fbd26a52fe4e0fc8471e6eb70a3/> dependencies
### Commit Statistics
<csr-read-only-do-not-edit/>
- 7 commits contributed to the release.
- 6 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- Release dagger-sdk v0.2.5, dagger-codegen v0.2.4 ([`f727318`](https://github.com/kjuulh/dagger-rs/commit/f72731807d8358fdb3d80432136b7a08bb7b1773))
- cargo clippy ([`c627595`](https://github.com/kjuulh/dagger-rs/commit/c627595fd2695e236924175d137c42f1480ccd6b))
- without Some in _opts functions ([`f29ff83`](https://github.com/kjuulh/dagger-rs/commit/f29ff836cfd72d5e051ca6a71a230ba1e9933091))
- with _opts methods ([`9762da8`](https://github.com/kjuulh/dagger-rs/commit/9762da895a164e30c5dc60e89a83e934ceae47ab))
- without phantom data ([`02006d4`](https://github.com/kjuulh/dagger-rs/commit/02006d40fc2c0383e0412c15c36db9af7eda991f))
- move to &str instead of String and introduce builder. ([`94336d0`](https://github.com/kjuulh/dagger-rs/commit/94336d06378f035464e233b921dc3858070f582d))
- dependencies ([`6e2292c`](https://github.com/kjuulh/dagger-rs/commit/6e2292cf11942fbd26a52fe4e0fc8471e6eb70a3))
</details>
## v0.2.4 (2023-02-19)
### Bug Fixes
@@ -157,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/>
- 2 commits contributed to the release.
- 1 commit contributed to the release.
- 1 commit was understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
@@ -168,7 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<details><summary>view details</summary>
* **Uncategorized**
- Release dagger-sdk v0.2.4 ([`cc81124`](https://github.com/kjuulh/dagger-rs/commit/cc81124f899f44f80c1ee7d1e23a7e02d8cc4b7c))
- readme dagger-rs -> dagger-sdk ([`7d04ab1`](https://github.com/kjuulh/dagger-rs/commit/7d04ab1240e497e7804fed23a378d28c78f50a0a))
</details>

View File

@@ -1,6 +1,6 @@
[package]
name = "dagger-sdk"
version = "0.2.7"
version = "0.2.4"
edition = "2021"
readme = "README.md"
license-file = "LICENSE.MIT"

View File

@@ -25,15 +25,14 @@ cargo add dagger-sdk
### Usage
```rust
#[tokio::main]
async fn main() -> eyre::Result<()> {
fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?;
let version = client
.container()
.from("golang:1.19")
.with_exec(vec!["go", "version"])
.stdout().await?;
.container(None)
.from("golang:1.19".into())
.with_exec(vec!["go".into(), "version".into()], None)
.stdout()?;
println!("Hello from Dagger and {}", version.trim());
@@ -46,9 +45,3 @@ And run it like a normal application:
```bash
cargo run
```
### Disclaimer
You are free to use something else than `tokio`, I haven't tested it with
anything else, but it should work with any other runtime. We don't rely on it
specifically. That might change in the future though.

View File

@@ -1,7 +1,6 @@
use dagger_sdk::HostDirectoryOpts;
#[tokio::main]
async fn main() -> eyre::Result<()> {
fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts(
@@ -15,7 +14,7 @@ async fn main() -> eyre::Result<()> {
let source = client
.container()
.from("node:16")
.with_mounted_directory("/src", host_source_dir.id().await?);
.with_mounted_directory("/src", host_source_dir.id()?);
let runner = source
.with_workdir("/src")
@@ -29,7 +28,7 @@ async fn main() -> eyre::Result<()> {
let _ = build_dir.export("./build");
let entries = build_dir.entries().await;
let entries = build_dir.entries();
println!("build dir contents: \n {:?}", entries);

View File

@@ -1,7 +1,6 @@
use rand::Rng;
#[tokio::main]
async fn main() -> eyre::Result<()> {
fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts(
@@ -11,12 +10,12 @@ async fn main() -> eyre::Result<()> {
.build()?,
);
let node_cache = client.cache_volume("node").id().await?;
let node_cache = client.cache_volume("node").id()?;
let source = client
.container()
.from("node:16")
.with_mounted_directory("/src", host_source_dir.id().await?)
.with_mounted_directory("/src", host_source_dir.id()?)
.with_mounted_cache("/src/node_modules", node_cache);
let runner = source
@@ -34,8 +33,8 @@ async fn main() -> eyre::Result<()> {
let ref_ = client
.container()
.from("nginx")
.with_directory("/usr/share/nginx/html", build_dir.id().await?)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>())).await?;
.with_directory("/usr/share/nginx/html", build_dir.id()?)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
println!("published image to: {}", ref_);

View File

@@ -1,7 +1,6 @@
use rand::Rng;
#[tokio::main]
async fn main() -> eyre::Result<()> {
fn main() -> eyre::Result<()> {
let mut rng = rand::thread_rng();
let client = dagger_sdk::connect()?;
@@ -12,8 +11,8 @@ async fn main() -> eyre::Result<()> {
let ref_ = client
.container()
.build(context_dir.id().await?)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>())).await?;
.build(context_dir.id()?)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
println!("published image to: {}", ref_);

View File

@@ -1,12 +1,11 @@
#[tokio::main]
async fn main() -> eyre::Result<()> {
fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?;
let version = client
.container()
.from("golang:1.19")
.with_exec(vec!["go", "version"])
.stdout().await?;
.with_exec(vec!["go", "version".into()])
.stdout()?;
println!("Hello from Dagger and {}", version.trim());

View File

@@ -1,8 +1,7 @@
use dagger_sdk::HostDirectoryOpts;
use rand::Rng;
#[tokio::main]
async fn main() -> eyre::Result<()> {
fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts(
@@ -16,7 +15,7 @@ async fn main() -> eyre::Result<()> {
let source = client
.container()
.from("node:16")
.with_mounted_directory("/src", host_source_dir.id().await?);
.with_mounted_directory("/src", host_source_dir.id()?);
let runner = source
.with_workdir("/src")
@@ -33,9 +32,8 @@ async fn main() -> eyre::Result<()> {
let ref_ = client
.container()
.from("nginx")
.with_directory("/usr/share/nginx/html", build_dir.id().await?)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))
.await?;
.with_directory("/usr/share/nginx/html", build_dir.id()?)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
println!("published image to: {}", ref_);

View File

@@ -1,8 +1,7 @@
use dagger_sdk::HostDirectoryOpts;
use rand::Rng;
#[tokio::main]
async fn main() -> eyre::Result<()> {
fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?;
let output = "examples/publish-the-application/app/build";
@@ -17,7 +16,7 @@ async fn main() -> eyre::Result<()> {
let source = client
.container()
.from("node:16")
.with_mounted_directory("/src", host_source_dir.id().await?);
.with_mounted_directory("/src", host_source_dir.id()?);
let runner = source
.with_workdir("/src")
@@ -37,9 +36,9 @@ async fn main() -> eyre::Result<()> {
.from("nginx")
.with_directory(
"/usr/share/nginx/html",
client.host().directory(output).id().await?,
client.host().directory(output).id()?,
)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>())).await?;
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
println!("published image to: {}", ref_);

View File

@@ -1,7 +1,6 @@
use dagger_sdk::HostDirectoryOpts;
#[tokio::main]
async fn main() -> eyre::Result<()> {
fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts(
@@ -15,7 +14,7 @@ async fn main() -> eyre::Result<()> {
let source = client
.container()
.from("node:16")
.with_mounted_directory("/src", host_source_dir.id().await?);
.with_mounted_directory("/src", host_source_dir.id()?);
let runner = source
.with_workdir("/src")
@@ -23,7 +22,7 @@ async fn main() -> eyre::Result<()> {
let out = runner
.with_exec(vec!["npm", "test", "--", "--watchAll=false"])
.stderr().await?;
.stderr()?;
println!("{}", out);

File diff suppressed because it is too large Load Diff

View File

@@ -93,13 +93,18 @@ impl Selection {
Ok(fields.join("{") + &"}".repeat(fields.len() - 1))
}
pub async fn execute<D>(&self, gql_client: &gql_client::Client) -> eyre::Result<D>
pub fn execute<D>(&self, gql_client: &gql_client::Client) -> eyre::Result<D>
where
D: for<'de> Deserialize<'de>,
{
let query = self.build()?;
let resp: Option<serde_json::Value> = match gql_client.query(&query).await {
let basic = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let resp: Option<serde_json::Value> = match basic.block_on(gql_client.query(&query)) {
Ok(r) => r,
Err(e) => eyre::bail!(e),
};

View File

@@ -1,7 +1,7 @@
use dagger_sdk::{connect, ContainerExecOptsBuilder};
#[tokio::test]
async fn test_example_container() {
#[test]
fn test_example_container() {
let client = connect().unwrap();
let alpine = client.container().from("alpine:3.16.2");
@@ -14,7 +14,6 @@ async fn test_example_container() {
.unwrap(),
)
.stdout()
.await
.unwrap();
assert_eq!(out, "3.16.2\n".to_string())