mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-12-29 11:11:02 +01:00
Compare commits
6 Commits
c35c104b49
...
dagger-sdk
| Author | SHA1 | Date | |
|---|---|---|---|
|
04990247ba
|
|||
| 978ede68ae | |||
|
a1887afc8b
|
|||
|
d3faa996e6
|
|||
| 93f40b356c | |||
| 9be6f435d9 |
38
Cargo.lock
generated
38
Cargo.lock
generated
@@ -114,7 +114,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"dagger-sdk 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dagger-sdk 0.2.6",
|
||||
"eyre",
|
||||
]
|
||||
|
||||
@@ -245,7 +245,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dagger-codegen"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
dependencies = [
|
||||
"convert_case",
|
||||
"dagger-core 0.2.2",
|
||||
@@ -331,6 +331,23 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "dagger-sdk"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "654625e954f59d70eb897bb681936c3e8b69c5f6e528f85c0b307554883db63f"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"dagger-core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"derive_builder",
|
||||
"eyre",
|
||||
"futures",
|
||||
"gql_client",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dagger-sdk"
|
||||
version = "0.2.8"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"dagger-core 0.2.2",
|
||||
@@ -346,23 +363,6 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dagger-sdk"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "654625e954f59d70eb897bb681936c3e8b69c5f6e528f85c0b307554883db63f"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"dagger-core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"derive_builder",
|
||||
"eyre",
|
||||
"futures",
|
||||
"gql_client",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.14.3"
|
||||
|
||||
@@ -24,7 +24,7 @@ See [dagger-sdk](./crates/dagger-sdk/README.md)
|
||||
- [x] fix build / release cycle
|
||||
- [x] general api stabilisation
|
||||
- [x] document usage
|
||||
- [ ] make async variant
|
||||
- [x] make async variant
|
||||
|
||||
## Architecture
|
||||
|
||||
|
||||
@@ -5,6 +5,53 @@ 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.5 (2023-02-19)
|
||||
|
||||
### New Features
|
||||
|
||||
- <csr-id-978ede68ae52f5b5150a2aa45b8d6e1fbbbee2f4/> add documentation strings
|
||||
- <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**
|
||||
- add documentation strings ([`978ede6`](https://github.com/kjuulh/dagger-rs/commit/978ede68ae52f5b5150a2aa45b8d6e1fbbbee2f4))
|
||||
- Use async runtime instead of blocking. ([`9be6f43`](https://github.com/kjuulh/dagger-rs/commit/9be6f435d9ea39f31a8906e55dbd3e8b1e5ec598))
|
||||
</details>
|
||||
|
||||
## v0.2.4 (2023-02-19)
|
||||
|
||||
### New Features
|
||||
@@ -51,7 +98,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
<csr-read-only-do-not-edit/>
|
||||
|
||||
- 5 commits contributed to the release.
|
||||
- 6 commits contributed to the release.
|
||||
- 5 commits were understood as [conventional](https://www.conventionalcommits.org).
|
||||
- 0 issues like '(#ID)' were seen in commit messages
|
||||
|
||||
@@ -62,6 +109,7 @@ 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.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))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "dagger-codegen"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
edition = "2021"
|
||||
readme = "README.md"
|
||||
license-file = "LICENSE.MIT"
|
||||
|
||||
@@ -10,6 +10,8 @@ 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)
|
||||
}
|
||||
@@ -29,19 +31,44 @@ pub fn field_options_struct_name(field: &FullTypeFields) -> Option<String> {
|
||||
}
|
||||
|
||||
pub fn format_function(funcs: &CommonFunctions, field: &FullTypeFields) -> Option<rust::Tokens> {
|
||||
let signature = quote! {
|
||||
pub fn $(field.name.pipe(|n | format_struct_name(n)))
|
||||
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 args = format_function_args(funcs, field);
|
||||
});
|
||||
|
||||
let signature = quote! {
|
||||
pub $(is_async) 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 output_type = field
|
||||
.type_
|
||||
.pipe(|t| &t.type_ref)
|
||||
.pipe(|t| render_output_type(funcs, t));
|
||||
|
||||
if let Some((args, true)) = args {
|
||||
if let Some((args, desc, 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()) {
|
||||
@@ -52,7 +79,9 @@ pub fn format_function(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
|
||||
$(render_execution(funcs, field))
|
||||
}
|
||||
|
||||
$(&signature)_opts(
|
||||
$(field.description.pipe(|d| format_struct_comment(d)))
|
||||
$(&desc)
|
||||
$(&signature)_opts$(lifecycle)(
|
||||
$args
|
||||
) -> $(output_type) {
|
||||
let mut query = self.selection.select($(quoted(field.name.as_ref())));
|
||||
@@ -65,8 +94,10 @@ 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())));
|
||||
|
||||
@@ -235,14 +266,16 @@ 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))
|
||||
query.execute(&$graphql_client(&self.conn)).await
|
||||
}
|
||||
}
|
||||
|
||||
fn format_function_args(
|
||||
funcs: &CommonFunctions,
|
||||
field: &FullTypeFields,
|
||||
) -> Option<(rust::Tokens, bool)> {
|
||||
lifecycle: Option<&rust::Tokens>,
|
||||
) -> Option<(rust::Tokens, rust::Tokens, bool)> {
|
||||
let mut argument_description = Vec::new();
|
||||
if let Some(args) = field.args.as_ref() {
|
||||
let args = args
|
||||
.into_iter()
|
||||
@@ -255,6 +288,18 @@ 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),
|
||||
})
|
||||
@@ -268,15 +313,34 @@ 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_options_struct_name(field))
|
||||
opts: $(field_name)$(lifecycle)
|
||||
},
|
||||
description,
|
||||
true,
|
||||
))
|
||||
} else {
|
||||
Some((required_args, false))
|
||||
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))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
@@ -316,3 +380,52 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ use itertools::Itertools;
|
||||
|
||||
use crate::functions::{type_ref_is_optional, CommonFunctions};
|
||||
use crate::rust::functions::{
|
||||
field_options_struct_name, format_function, format_name, format_struct_name,
|
||||
field_options_struct_name, format_function, format_name, format_optional_args,
|
||||
format_struct_comment, format_struct_name,
|
||||
};
|
||||
use crate::utility::OptionExt;
|
||||
|
||||
@@ -51,16 +52,7 @@ 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 = 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 fields = format_optional_args(funcs, field);
|
||||
|
||||
let builder = rust::import("derive_builder", "Builder");
|
||||
let _phantom_data = rust::import("std::marker", "PhantomData");
|
||||
@@ -79,7 +71,7 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
|
||||
}
|
||||
}
|
||||
|
||||
fn render_optional_field_args(
|
||||
pub fn render_optional_field_args(
|
||||
funcs: &CommonFunctions,
|
||||
args: &Vec<&FullTypeFieldsArgs>,
|
||||
) -> Option<(rust::Tokens, bool)> {
|
||||
@@ -93,6 +85,7 @@ 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_)>,
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ 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.6 (2023-02-19)
|
||||
## v0.2.8 (2023-02-19)
|
||||
|
||||
### Documentation
|
||||
### New Features
|
||||
|
||||
- <csr-id-04e70ce964b343e28b3dbd0c46d10ccda958ab8c/> fix readme
|
||||
- <csr-id-978ede68ae52f5b5150a2aa45b8d6e1fbbbee2f4/> add documentation strings
|
||||
|
||||
### Commit Statistics
|
||||
|
||||
@@ -26,6 +26,82 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
<details><summary>view details</summary>
|
||||
|
||||
* **Uncategorized**
|
||||
- add documentation strings ([`978ede6`](https://github.com/kjuulh/dagger-rs/commit/978ede68ae52f5b5150a2aa45b8d6e1fbbbee2f4))
|
||||
</details>
|
||||
|
||||
## 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/>
|
||||
|
||||
- 3 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**
|
||||
- Release dagger-sdk v0.2.7 ([`a1887af`](https://github.com/kjuulh/dagger-rs/commit/a1887afc8b51f61491ba7f13c5e7a5b7619623c4))
|
||||
- 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>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "dagger-sdk"
|
||||
version = "0.2.6"
|
||||
version = "0.2.8"
|
||||
edition = "2021"
|
||||
readme = "README.md"
|
||||
license-file = "LICENSE.MIT"
|
||||
|
||||
@@ -25,14 +25,15 @@ cargo add dagger-sdk
|
||||
### Usage
|
||||
|
||||
```rust
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let version = client
|
||||
.container()
|
||||
.from("golang:1.19")
|
||||
.with_exec(vec!["go", "version"])
|
||||
.stdout()?;
|
||||
.stdout().await?;
|
||||
|
||||
println!("Hello from Dagger and {}", version.trim());
|
||||
|
||||
@@ -45,3 +46,9 @@ 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.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use dagger_sdk::HostDirectoryOpts;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
@@ -14,7 +15,7 @@ fn main() -> eyre::Result<()> {
|
||||
let source = client
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?);
|
||||
.with_mounted_directory("/src", host_source_dir.id().await?);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
@@ -28,7 +29,7 @@ fn main() -> eyre::Result<()> {
|
||||
|
||||
let _ = build_dir.export("./build");
|
||||
|
||||
let entries = build_dir.entries();
|
||||
let entries = build_dir.entries().await;
|
||||
|
||||
println!("build dir contents: \n {:?}", entries);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use rand::Rng;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
@@ -10,12 +11,12 @@ fn main() -> eyre::Result<()> {
|
||||
.build()?,
|
||||
);
|
||||
|
||||
let node_cache = client.cache_volume("node").id()?;
|
||||
let node_cache = client.cache_volume("node").id().await?;
|
||||
|
||||
let source = client
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?)
|
||||
.with_mounted_directory("/src", host_source_dir.id().await?)
|
||||
.with_mounted_cache("/src/node_modules", node_cache);
|
||||
|
||||
let runner = source
|
||||
@@ -33,8 +34,8 @@ fn main() -> eyre::Result<()> {
|
||||
let ref_ = client
|
||||
.container()
|
||||
.from("nginx")
|
||||
.with_directory("/usr/share/nginx/html", build_dir.id()?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
||||
.with_directory("/usr/share/nginx/html", build_dir.id().await?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>())).await?;
|
||||
|
||||
println!("published image to: {}", ref_);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use rand::Rng;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let client = dagger_sdk::connect()?;
|
||||
@@ -11,8 +12,8 @@ fn main() -> eyre::Result<()> {
|
||||
|
||||
let ref_ = client
|
||||
.container()
|
||||
.build(context_dir.id()?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
||||
.build(context_dir.id().await?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>())).await?;
|
||||
|
||||
println!("published image to: {}", ref_);
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let version = client
|
||||
.container()
|
||||
.from("golang:1.19")
|
||||
.with_exec(vec!["go", "version".into()])
|
||||
.stdout()?;
|
||||
.with_exec(vec!["go", "version"])
|
||||
.stdout().await?;
|
||||
|
||||
println!("Hello from Dagger and {}", version.trim());
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use dagger_sdk::HostDirectoryOpts;
|
||||
use rand::Rng;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
@@ -15,7 +16,7 @@ fn main() -> eyre::Result<()> {
|
||||
let source = client
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?);
|
||||
.with_mounted_directory("/src", host_source_dir.id().await?);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
@@ -32,8 +33,9 @@ fn main() -> eyre::Result<()> {
|
||||
let ref_ = client
|
||||
.container()
|
||||
.from("nginx")
|
||||
.with_directory("/usr/share/nginx/html", build_dir.id()?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
||||
.with_directory("/usr/share/nginx/html", build_dir.id().await?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))
|
||||
.await?;
|
||||
|
||||
println!("published image to: {}", ref_);
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use dagger_sdk::HostDirectoryOpts;
|
||||
use rand::Rng;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
let output = "examples/publish-the-application/app/build";
|
||||
|
||||
@@ -16,7 +17,7 @@ fn main() -> eyre::Result<()> {
|
||||
let source = client
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?);
|
||||
.with_mounted_directory("/src", host_source_dir.id().await?);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
@@ -36,9 +37,9 @@ fn main() -> eyre::Result<()> {
|
||||
.from("nginx")
|
||||
.with_directory(
|
||||
"/usr/share/nginx/html",
|
||||
client.host().directory(output).id()?,
|
||||
client.host().directory(output).id().await?,
|
||||
)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>())).await?;
|
||||
|
||||
println!("published image to: {}", ref_);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use dagger_sdk::HostDirectoryOpts;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
@@ -14,7 +15,7 @@ fn main() -> eyre::Result<()> {
|
||||
let source = client
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?);
|
||||
.with_mounted_directory("/src", host_source_dir.id().await?);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
@@ -22,7 +23,7 @@ fn main() -> eyre::Result<()> {
|
||||
|
||||
let out = runner
|
||||
.with_exec(vec!["npm", "test", "--", "--watchAll=false"])
|
||||
.stderr()?;
|
||||
.stderr().await?;
|
||||
|
||||
println!("{}", out);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -93,18 +93,13 @@ impl Selection {
|
||||
Ok(fields.join("{") + &"}".repeat(fields.len() - 1))
|
||||
}
|
||||
|
||||
pub fn execute<D>(&self, gql_client: &gql_client::Client) -> eyre::Result<D>
|
||||
pub async fn execute<D>(&self, gql_client: &gql_client::Client) -> eyre::Result<D>
|
||||
where
|
||||
D: for<'de> Deserialize<'de>,
|
||||
{
|
||||
let query = self.build()?;
|
||||
|
||||
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)) {
|
||||
let resp: Option<serde_json::Value> = match gql_client.query(&query).await {
|
||||
Ok(r) => r,
|
||||
Err(e) => eyre::bail!(e),
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use dagger_sdk::{connect, ContainerExecOptsBuilder};
|
||||
|
||||
#[test]
|
||||
fn test_example_container() {
|
||||
#[tokio::test]
|
||||
async fn test_example_container() {
|
||||
let client = connect().unwrap();
|
||||
|
||||
let alpine = client.container().from("alpine:3.16.2");
|
||||
@@ -14,6 +14,7 @@ fn test_example_container() {
|
||||
.unwrap(),
|
||||
)
|
||||
.stdout()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(out, "3.16.2\n".to_string())
|
||||
|
||||
Reference in New Issue
Block a user