Compare commits

..

1 Commits

Author SHA1 Message Date
c3806bac00 feat(sdk): add documentation strings 2023-02-19 22:38:36 +01:00
29 changed files with 132 additions and 290 deletions

View File

@@ -5,31 +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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.2.10 (2023-02-20)
### Bug Fixes
- <csr-id-75bc17e57db222492c6ffd2dfe80208d2bda75c9/> Fix async panic on blocking #19
Replaced internal threads with tokio spawn functions
### Commit Statistics
<csr-read-only-do-not-edit/>
- 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
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- Fix async panic on blocking #19 ([`75bc17e`](https://github.com/kjuulh/dagger-rs/commit/75bc17e57db222492c6ffd2dfe80208d2bda75c9))
</details>
## v0.2.9 (2023-02-19) ## v0.2.9 (2023-02-19)
### New Features ### New Features

67
Cargo.lock generated
View File

@@ -114,9 +114,8 @@ version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"color-eyre", "color-eyre",
"dagger-sdk 0.2.8", "dagger-sdk 0.2.6",
"eyre", "eyre",
"tokio",
] ]
[[package]] [[package]]
@@ -246,10 +245,10 @@ dependencies = [
[[package]] [[package]]
name = "dagger-codegen" name = "dagger-codegen"
version = "0.2.5" version = "0.2.4"
dependencies = [ dependencies = [
"convert_case", "convert_case",
"dagger-core 0.2.3", "dagger-core 0.2.2",
"eyre", "eyre",
"genco", "genco",
"itertools", "itertools",
@@ -258,6 +257,28 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "dagger-core"
version = "0.2.2"
dependencies = [
"clap",
"dirs",
"eyre",
"flate2",
"genco",
"graphql-introspection-query",
"graphql_client",
"hex",
"hex-literal",
"platform-info",
"reqwest",
"serde",
"serde_json",
"sha2",
"tar",
"tempfile",
]
[[package]] [[package]]
name = "dagger-core" name = "dagger-core"
version = "0.2.2" version = "0.2.2"
@@ -282,37 +303,14 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "dagger-core"
version = "0.2.3"
dependencies = [
"clap",
"dirs",
"eyre",
"flate2",
"genco",
"graphql-introspection-query",
"graphql_client",
"hex",
"hex-literal",
"platform-info",
"reqwest",
"serde",
"serde_json",
"sha2",
"tar",
"tempfile",
"tokio",
]
[[package]] [[package]]
name = "dagger-rs" name = "dagger-rs"
version = "0.2.10" version = "0.2.9"
dependencies = [ dependencies = [
"clap", "clap",
"color-eyre", "color-eyre",
"dagger-codegen", "dagger-codegen",
"dagger-core 0.2.3", "dagger-core 0.2.2",
"dirs", "dirs",
"eyre", "eyre",
"flate2", "flate2",
@@ -328,17 +326,16 @@ dependencies = [
"sha2", "sha2",
"tar", "tar",
"tempfile", "tempfile",
"tokio",
] ]
[[package]] [[package]]
name = "dagger-sdk" name = "dagger-sdk"
version = "0.2.8" version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e90636d5b74ce8a62e8507a8d075c4d997c3123a1709596d0f97c3070f993b2d" checksum = "654625e954f59d70eb897bb681936c3e8b69c5f6e528f85c0b307554883db63f"
dependencies = [ dependencies = [
"base64", "base64",
"dagger-core 0.2.2", "dagger-core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"derive_builder", "derive_builder",
"eyre", "eyre",
"futures", "futures",
@@ -350,10 +347,10 @@ dependencies = [
[[package]] [[package]]
name = "dagger-sdk" name = "dagger-sdk"
version = "0.2.9" version = "0.2.7"
dependencies = [ dependencies = [
"base64", "base64",
"dagger-core 0.2.3", "dagger-core 0.2.2",
"derive_builder", "derive_builder",
"eyre", "eyre",
"futures", "futures",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dagger-rs" name = "dagger-rs"
version = "0.2.10" version = "0.2.9"
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
license-file = "LICENSE.MIT" license-file = "LICENSE.MIT"
@@ -20,7 +20,7 @@ members = [
[dependencies] [dependencies]
dagger-codegen = { path = "crates/dagger-codegen", version = "^0.2.3" } dagger-codegen = { path = "crates/dagger-codegen", version = "^0.2.3" }
dagger-core = { path = "crates/dagger-core", version = "^0.2.3" } dagger-core = { path = "crates/dagger-core", version = "^0.2.2" }
clap = "4.1.6" clap = "4.1.6"
dirs = "4.0.0" dirs = "4.0.0"
@@ -42,4 +42,3 @@ sha2 = "0.10.6"
tar = "0.4.38" tar = "0.4.38"
tempfile = "3.3.0" tempfile = "3.3.0"
color-eyre = "0.6.2" color-eyre = "0.6.2"
tokio = { version = "1.25.0", features = ["full"] }

View File

@@ -10,4 +10,3 @@ clap = "4.1.6"
color-eyre = "0.6.2" color-eyre = "0.6.2"
dagger-sdk = "0.2.6" dagger-sdk = "0.2.6"
eyre = "0.6.8" eyre = "0.6.8"
tokio = { version = "1.25.0", features = ["full"] }

View File

@@ -2,8 +2,7 @@ use std::sync::Arc;
use dagger_sdk::{Container, HostDirectoryOpts, Query}; use dagger_sdk::{Container, HostDirectoryOpts, Query};
#[tokio::main] fn main() -> eyre::Result<()> {
async fn main() -> eyre::Result<()> {
color_eyre::install().unwrap(); color_eyre::install().unwrap();
let matches = clap::Command::new("ci") let matches = clap::Command::new("ci")
@@ -16,10 +15,10 @@ async fn main() -> eyre::Result<()> {
match matches.subcommand() { match matches.subcommand() {
Some(("pr", _)) => { Some(("pr", _)) => {
let base = select_base_image(client.clone()).await?; let base = select_base_image(client.clone())?;
return validate_pr(client, base).await; return validate_pr(client, base);
} }
Some(("release", subm)) => return release(client, subm).await, Some(("release", subm)) => return release(client, subm),
Some(_) => { Some(_) => {
panic!("invalid subcommand selected!") panic!("invalid subcommand selected!")
} }
@@ -29,7 +28,7 @@ async fn main() -> eyre::Result<()> {
} }
} }
async fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> { fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> {
let src_dir = client.host().directory_opts( let src_dir = client.host().directory_opts(
".", ".",
HostDirectoryOpts { HostDirectoryOpts {
@@ -41,7 +40,7 @@ async fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), col
.container() .container()
.from("rust:latest") .from("rust:latest")
.with_workdir("app") .with_workdir("app")
.with_mounted_directory("/app/", src_dir.id().await?); .with_mounted_directory("/app/", src_dir.id()?);
let container = base_image let container = base_image
.with_exec(vec!["cargo", "install", "cargo-smart-release"]) .with_exec(vec!["cargo", "install", "cargo-smart-release"])
@@ -54,7 +53,7 @@ async fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), col
"dagger-rs", "dagger-rs",
"dagger-sdk", "dagger-sdk",
]); ]);
let exit = container.exit_code().await?; let exit = container.exit_code()?;
if exit != 0 { if exit != 0 {
eyre::bail!("container failed with non-zero exit code"); eyre::bail!("container failed with non-zero exit code");
} }
@@ -64,7 +63,7 @@ async fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), col
Ok(()) Ok(())
} }
async fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> { fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> {
let cargo_dir = client.host().directory_opts( let cargo_dir = client.host().directory_opts(
".", ".",
HostDirectoryOpts { HostDirectoryOpts {
@@ -122,16 +121,16 @@ async fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> {
.with_env_variable("SCCACHE_BUCKET", "sccache") .with_env_variable("SCCACHE_BUCKET", "sccache")
.with_env_variable("SCCACHE_REGION", "auto") .with_env_variable("SCCACHE_REGION", "auto")
.with_env_variable("SCCACHE_ENDPOINT", "https://api-minio.front.kjuulh.io") .with_env_variable("SCCACHE_ENDPOINT", "https://api-minio.front.kjuulh.io")
.with_mounted_cache("~/.cargo/bin", cache_cargo_bin.id().await?) .with_mounted_cache("~/.cargo/bin", cache_cargo_bin.id()?)
.with_mounted_cache("~/.cargo/registry/index", cache_cargo_bin.id().await?) .with_mounted_cache("~/.cargo/registry/index", cache_cargo_bin.id()?)
.with_mounted_cache("~/.cargo/registry/cache", cache_cargo_bin.id().await?) .with_mounted_cache("~/.cargo/registry/cache", cache_cargo_bin.id()?)
.with_mounted_cache("~/.cargo/git/db", cache_cargo_bin.id().await?) .with_mounted_cache("~/.cargo/git/db", cache_cargo_bin.id()?)
.with_mounted_cache("target/", cache_cargo_bin.id().await?) .with_mounted_cache("target/", cache_cargo_bin.id()?)
.with_exec(vec!["cargo", "install", "cargo-chef"]); .with_exec(vec!["cargo", "install", "cargo-chef"]);
let recipe = base_image let recipe = base_image
.with_mounted_directory(".", cargo_dir.id().await?) .with_mounted_directory(".", cargo_dir.id()?)
.with_mounted_cache("~/.cargo/.package-cache", cache_cargo_index_dir.id().await?) .with_mounted_cache("~/.cargo/.package-cache", cache_cargo_index_dir.id()?)
.with_exec(vec![ .with_exec(vec![
"cargo", "cargo",
"chef", "chef",
@@ -142,7 +141,7 @@ async fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> {
.file("/app/recipe.json"); .file("/app/recipe.json");
let builder_start = base_image let builder_start = base_image
.with_mounted_file("/app/recipe.json", recipe.id().await?) .with_mounted_file("/app/recipe.json", recipe.id()?)
.with_exec(vec![ .with_exec(vec![
"cargo", "cargo",
"chef", "chef",
@@ -152,23 +151,23 @@ async fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> {
"--recipe-path", "--recipe-path",
"recipe.json", "recipe.json",
]) ])
.with_mounted_cache("/app/", cache_cargo_deps.id().await?) .with_mounted_cache("/app/", cache_cargo_deps.id()?)
.with_mounted_directory("/app/", src_dir.id().await?) .with_mounted_directory("/app/", src_dir.id()?)
.with_exec(vec!["cargo", "build", "--all", "--release"]); .with_exec(vec!["cargo", "build", "--all", "--release"]);
return Ok(builder_start); return Ok(builder_start);
} }
async fn select_base_image(client: Arc<Query>) -> eyre::Result<Container> { fn select_base_image(client: Arc<Query>) -> eyre::Result<Container> {
let src_dir = get_dependencies(client.clone()).await; let src_dir = get_dependencies(client.clone());
src_dir src_dir
} }
async fn validate_pr(_client: Arc<Query>, container: Container) -> eyre::Result<()> { 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", "test", "--all"], None);
let exit = container.exit_code().await?; let exit = container.exit_code()?;
if exit != 0 { if exit != 0 {
eyre::bail!("container failed with non-zero exit code"); eyre::bail!("container failed with non-zero exit code");
} }

View File

@@ -5,53 +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/), 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). 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) ## v0.2.4 (2023-02-19)
### New Features ### New Features
@@ -98,7 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/> <csr-read-only-do-not-edit/>
- 6 commits contributed to the release. - 5 commits contributed to the release.
- 5 commits were understood as [conventional](https://www.conventionalcommits.org). - 5 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages - 0 issues like '(#ID)' were seen in commit messages
@@ -109,7 +62,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<details><summary>view details</summary> <details><summary>view details</summary>
* **Uncategorized** * **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)) - 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)) - 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)) - with _opts methods ([`9762da8`](https://github.com/kjuulh/dagger-rs/commit/9762da895a164e30c5dc60e89a83e934ceae47ab))

View File

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

View File

@@ -5,12 +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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.2.3 (2023-02-20) ## v0.2.2 (2023-02-19)
### Bug Fixes ### New Features
- <csr-id-75bc17e57db222492c6ffd2dfe80208d2bda75c9/> Fix async panic on blocking #19 - <csr-id-6e5f4074329ab0462445b31d4153f8497c483438/> update to dagger v0.3.12
Replaced internal threads with tokio spawn functions
### Commit Statistics ### Commit Statistics
@@ -27,31 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<details><summary>view details</summary> <details><summary>view details</summary>
* **Uncategorized** * **Uncategorized**
- Fix async panic on blocking #19 ([`75bc17e`](https://github.com/kjuulh/dagger-rs/commit/75bc17e57db222492c6ffd2dfe80208d2bda75c9))
</details>
## v0.2.2 (2023-02-19)
### New Features
- <csr-id-6e5f4074329ab0462445b31d4153f8497c483438/> update to dagger v0.3.12
### 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-core v0.2.2, dagger-codegen v0.2.2, dagger-rs v0.2.8 ([`1638f15`](https://github.com/kjuulh/dagger-rs/commit/1638f15fba9d16512e8452f87b908d6dce417cd9))
- update to dagger v0.3.12 ([`6e5f407`](https://github.com/kjuulh/dagger-rs/commit/6e5f4074329ab0462445b31d4153f8497c483438)) - update to dagger v0.3.12 ([`6e5f407`](https://github.com/kjuulh/dagger-rs/commit/6e5f4074329ab0462445b31d4153f8497c483438))
</details> </details>

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dagger-core" name = "dagger-core"
version = "0.2.3" version = "0.2.2"
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
license-file = "LICENSE.MIT" license-file = "LICENSE.MIT"
@@ -29,4 +29,3 @@ serde_json = "1.0.93"
sha2 = "0.10.6" sha2 = "0.10.6"
tar = "0.4.38" tar = "0.4.38"
tempfile = "3.3.0" tempfile = "3.3.0"
tokio = { version = "1.25.0", features = ["full"] }

View File

@@ -3,7 +3,7 @@ use std::{
io::{BufRead, BufReader}, io::{BufRead, BufReader},
path::PathBuf, path::PathBuf,
process::{Child, Stdio}, process::{Child, Stdio},
sync::Arc, sync::{mpsc::sync_channel, Arc},
}; };
use crate::{config::Config, connect_params::ConnectParams}; use crate::{config::Config, connect_params::ConnectParams};
@@ -20,12 +20,12 @@ impl CliSession {
} }
} }
pub async fn connect( pub fn connect(
&self, &self,
config: &Config, config: &Config,
cli_path: &PathBuf, cli_path: &PathBuf,
) -> eyre::Result<(ConnectParams, Child)> { ) -> eyre::Result<(ConnectParams, Child)> {
self.inner.connect(config, cli_path).await self.inner.connect(config, cli_path)
} }
} }
@@ -33,13 +33,13 @@ impl CliSession {
struct InnerCliSession {} struct InnerCliSession {}
impl InnerCliSession { impl InnerCliSession {
pub async fn connect( pub fn connect(
&self, &self,
config: &Config, config: &Config,
cli_path: &PathBuf, cli_path: &PathBuf,
) -> eyre::Result<(ConnectParams, Child)> { ) -> eyre::Result<(ConnectParams, Child)> {
let proc = self.start(config, cli_path)?; let proc = self.start(config, cli_path)?;
let params = self.get_conn(proc).await?; let params = self.get_conn(proc)?;
Ok(params) Ok(params)
} }
@@ -70,7 +70,7 @@ impl InnerCliSession {
return Ok(proc); return Ok(proc);
} }
async fn get_conn( fn get_conn(
&self, &self,
mut proc: std::process::Child, mut proc: std::process::Child,
) -> eyre::Result<(ConnectParams, std::process::Child)> { ) -> eyre::Result<(ConnectParams, std::process::Child)> {
@@ -84,14 +84,14 @@ impl InnerCliSession {
.take() .take()
.ok_or(eyre::anyhow!("could not acquire stderr from child process"))?; .ok_or(eyre::anyhow!("could not acquire stderr from child process"))?;
let (sender, mut receiver) = tokio::sync::mpsc::channel(1); let (sender, receiver) = sync_channel(1);
tokio::spawn(async move { std::thread::spawn(move || {
let stdout_bufr = BufReader::new(stdout); let stdout_bufr = BufReader::new(stdout);
for line in stdout_bufr.lines() { for line in stdout_bufr.lines() {
let out = line.as_ref().unwrap(); let out = line.as_ref().unwrap();
if let Ok(conn) = serde_json::from_str::<ConnectParams>(&out) { if let Ok(conn) = serde_json::from_str::<ConnectParams>(&out) {
sender.send(conn).await.unwrap(); sender.send(conn).unwrap();
} }
if let Ok(line) = line { if let Ok(line) = line {
println!("dagger: {}", line); println!("dagger: {}", line);
@@ -99,7 +99,7 @@ impl InnerCliSession {
} }
}); });
tokio::spawn(async move { std::thread::spawn(|| {
let stderr_bufr = BufReader::new(stderr); let stderr_bufr = BufReader::new(stderr);
for line in stderr_bufr.lines() { for line in stderr_bufr.lines() {
if let Ok(line) = line { if let Ok(line) = line {
@@ -109,7 +109,7 @@ impl InnerCliSession {
} }
}); });
let conn = receiver.recv().await.ok_or(eyre::anyhow!("could not receive ok signal from dagger-engine"))?; let conn = receiver.recv()?;
Ok((conn, proc)) Ok((conn, proc))
} }

View File

@@ -119,7 +119,7 @@ impl Downloader {
Ok(path) Ok(path)
} }
pub async fn get_cli(&self) -> eyre::Result<PathBuf> { pub fn get_cli(&self) -> eyre::Result<PathBuf> {
let version = &self.version; let version = &self.version;
let mut cli_bin_path = self.cache_dir()?; let mut cli_bin_path = self.cache_dir()?;
cli_bin_path.push(format!("{CLI_BIN_PREFIX}{version}")); cli_bin_path.push(format!("{CLI_BIN_PREFIX}{version}"));
@@ -129,7 +129,7 @@ impl Downloader {
if !cli_bin_path.exists() { if !cli_bin_path.exists() {
cli_bin_path = self cli_bin_path = self
.download(cli_bin_path).await .download(cli_bin_path)
.context("failed to download CLI from archive")?; .context("failed to download CLI from archive")?;
} }
@@ -145,8 +145,8 @@ impl Downloader {
Ok(cli_bin_path) Ok(cli_bin_path)
} }
async fn download(&self, path: PathBuf) -> eyre::Result<PathBuf> { fn download(&self, path: PathBuf) -> eyre::Result<PathBuf> {
let expected_checksum = self.expected_checksum().await?; let expected_checksum = self.expected_checksum()?;
let mut bytes = vec![]; let mut bytes = vec![];
let actual_hash = self.extract_cli_archive(&mut bytes)?; let actual_hash = self.extract_cli_archive(&mut bytes)?;
@@ -165,15 +165,15 @@ impl Downloader {
Ok(path) Ok(path)
} }
async fn expected_checksum(&self) -> eyre::Result<String> { fn expected_checksum(&self) -> eyre::Result<String> {
let archive_url = &self.archive_url(); let archive_url = &self.archive_url();
let archive_path = PathBuf::from(&archive_url); let archive_path = PathBuf::from(&archive_url);
let archive_name = archive_path let archive_name = archive_path
.file_name() .file_name()
.ok_or(eyre::anyhow!("could not get file_name from archive_url"))?; .ok_or(eyre::anyhow!("could not get file_name from archive_url"))?;
let resp = reqwest::get(self.checksum_url()).await?; let resp = reqwest::blocking::get(self.checksum_url())?;
let resp = resp.error_for_status()?; let resp = resp.error_for_status()?;
for line in resp.text().await?.lines() { for line in resp.text()?.lines() {
let mut content = line.split_whitespace(); let mut content = line.split_whitespace();
let checksum = content let checksum = content
.next() .next()
@@ -240,9 +240,9 @@ impl Downloader {
mod test { mod test {
use super::Downloader; use super::Downloader;
#[tokio::test] #[test]
async fn download() { fn download() {
let cli_path = Downloader::new("0.3.10".into()).unwrap().get_cli().await.unwrap(); let cli_path = Downloader::new("0.3.10".into()).unwrap().get_cli().unwrap();
assert_eq!( assert_eq!(
Some("dagger-0.3.10"), Some("dagger-0.3.10"),

View File

@@ -11,17 +11,17 @@ impl Engine {
Self {} Self {}
} }
async fn from_cli(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> { fn from_cli(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> {
let cli = Downloader::new("0.3.12".into())?.get_cli().await?; let cli = Downloader::new("0.3.12".into())?.get_cli()?;
let cli_session = CliSession::new(); let cli_session = CliSession::new();
Ok(cli_session.connect(cfg, &cli).await?) Ok(cli_session.connect(cfg, &cli)?)
} }
pub async fn start(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> { pub fn start(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> {
// TODO: Add from existing session as well // TODO: Add from existing session as well
self.from_cli(cfg).await self.from_cli(cfg)
} }
} }
@@ -32,10 +32,10 @@ mod tests {
use super::Engine; use super::Engine;
// TODO: these tests potentially have a race condition // TODO: these tests potentially have a race condition
#[tokio::test] #[test]
async fn engine_can_start() { fn engine_can_start() {
let engine = Engine::new(); let engine = Engine::new();
let params = engine.start(&Config::new(None, None, None, None)).await.unwrap(); let params = engine.start(&Config::new(None, None, None, None)).unwrap();
assert_ne!( assert_ne!(
params.0, params.0,

View File

@@ -1,14 +1,14 @@
use crate::introspection::IntrospectionResponse; use crate::introspection::IntrospectionResponse;
use crate::{config::Config, engine::Engine, session::Session}; use crate::{config::Config, engine::Engine, session::Session};
pub async fn get_schema() -> eyre::Result<IntrospectionResponse> { pub fn get_schema() -> eyre::Result<IntrospectionResponse> {
let cfg = Config::new(None, None, None, None); let cfg = Config::new(None, None, None, None);
//TODO: Implement context for proc //TODO: Implement context for proc
let (conn, _proc) = Engine::new().start(&cfg).await?; let (conn, _proc) = Engine::new().start(&cfg)?;
let session = Session::new(); let session = Session::new();
let req_builder = session.start(&cfg, &conn)?; let req_builder = session.start(&cfg, &conn)?;
let schema = session.schema(req_builder).await?; let schema = session.schema(req_builder)?;
Ok(schema) Ok(schema)
} }
@@ -17,8 +17,8 @@ pub async fn get_schema() -> eyre::Result<IntrospectionResponse> {
mod tests { mod tests {
use super::get_schema; use super::get_schema;
#[tokio::test] #[test]
async fn can_get_schema() { fn can_get_schema() {
let _ = get_schema().await.unwrap(); let _ = get_schema().unwrap();
} }
} }

View File

@@ -1,7 +1,7 @@
use graphql_client::GraphQLQuery; use graphql_client::GraphQLQuery;
use reqwest::{ use reqwest::{
blocking::{Client, RequestBuilder},
header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE}, header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE},
Client, RequestBuilder,
}; };
use crate::{config::Config, connect_params::ConnectParams, introspection::IntrospectionResponse}; use crate::{config::Config, connect_params::ConnectParams, introspection::IntrospectionResponse};
@@ -37,14 +37,14 @@ impl Session {
Ok(req_builder) Ok(req_builder)
} }
pub async fn schema(&self, req_builder: RequestBuilder) -> eyre::Result<IntrospectionResponse> { pub fn schema(&self, req_builder: RequestBuilder) -> eyre::Result<IntrospectionResponse> {
let request_body: graphql_client::QueryBody<()> = graphql_client::QueryBody { let request_body: graphql_client::QueryBody<()> = graphql_client::QueryBody {
variables: (), variables: (),
query: introspection_query::QUERY, query: introspection_query::QUERY,
operation_name: introspection_query::OPERATION_NAME, operation_name: introspection_query::OPERATION_NAME,
}; };
let res = req_builder.json(&request_body).send().await?; let res = req_builder.json(&request_body).send()?;
if res.status().is_success() { if res.status().is_success() {
// do nothing // do nothing
@@ -52,7 +52,7 @@ impl Session {
return Err(eyre::anyhow!("server error!")); return Err(eyre::anyhow!("server error!"));
} else { } else {
let status = res.status(); let status = res.status();
let error_message = match res.text().await { let error_message = match res.text() {
Ok(msg) => match serde_json::from_str::<serde_json::Value>(&msg) { Ok(msg) => match serde_json::from_str::<serde_json::Value>(&msg) {
Ok(json) => { Ok(json) => {
format!("HTTP {}\n{}", status, serde_json::to_string_pretty(&json)?) format!("HTTP {}\n{}", status, serde_json::to_string_pretty(&json)?)
@@ -64,7 +64,7 @@ impl Session {
return Err(eyre::anyhow!(error_message)); return Err(eyre::anyhow!(error_message));
} }
let json: IntrospectionResponse = res.json().await?; let json: IntrospectionResponse = res.json()?;
Ok(json) Ok(json)
} }

View File

@@ -5,56 +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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.2.9 (2023-02-20)
### Bug Fixes
- <csr-id-75bc17e57db222492c6ffd2dfe80208d2bda75c9/> Fix async panic on blocking #19
Replaced internal threads with tokio spawn functions
### Commit Statistics
<csr-read-only-do-not-edit/>
- 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
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- Fix async panic on blocking #19 ([`75bc17e`](https://github.com/kjuulh/dagger-rs/commit/75bc17e57db222492c6ffd2dfe80208d2bda75c9))
</details>
## v0.2.8 (2023-02-19)
### New Features
- <csr-id-978ede68ae52f5b5150a2aa45b8d6e1fbbbee2f4/> add documentation strings
### 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.8, dagger-codegen v0.2.5 ([`0499024`](https://github.com/kjuulh/dagger-rs/commit/04990247ba8e9d0555847f582fef14849dbedebf))
- add documentation strings ([`978ede6`](https://github.com/kjuulh/dagger-rs/commit/978ede68ae52f5b5150a2aa45b8d6e1fbbbee2f4))
</details>
## v0.2.7 (2023-02-19) ## v0.2.7 (2023-02-19)
### Documentation ### Documentation
@@ -90,7 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/> <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). - 2 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages - 0 issues like '(#ID)' were seen in commit messages
@@ -101,7 +51,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<details><summary>view details</summary> <details><summary>view details</summary>
* **Uncategorized** * **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)) - 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)) - Use async runtime instead of blocking. ([`9be6f43`](https://github.com/kjuulh/dagger-rs/commit/9be6f435d9ea39f31a8906e55dbd3e8b1e5ec598))
</details> </details>

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dagger-sdk" name = "dagger-sdk"
version = "0.2.9" version = "0.2.7"
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
license-file = "LICENSE.MIT" license-file = "LICENSE.MIT"
@@ -11,7 +11,7 @@ publish = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
dagger-core = { path = "../dagger-core", version = "^0.2.3" } dagger-core = { path = "../dagger-core", version = "^0.2.2" }
base64 = "0.21.0" base64 = "0.21.0"
eyre = "0.6.8" eyre = "0.6.8"

View File

@@ -2,7 +2,7 @@ use dagger_sdk::HostDirectoryOpts;
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?; let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory_opts(
"examples/build-the-application/app", "examples/build-the-application/app",

View File

@@ -2,7 +2,7 @@ use rand::Rng;
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?; let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory_opts(
"./examples/caching/app", "./examples/caching/app",

View File

@@ -4,7 +4,7 @@ use rand::Rng;
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
let client = dagger_sdk::connect().await?; let client = dagger_sdk::connect()?;
let context_dir = client let context_dir = client
.host() .host()

View File

@@ -1,6 +1,6 @@
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?; let client = dagger_sdk::connect()?;
let version = client let version = client
.container() .container()

View File

@@ -3,7 +3,7 @@ use rand::Rng;
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?; let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory_opts(
"examples/publish-the-application/app", "examples/publish-the-application/app",

View File

@@ -3,7 +3,7 @@ use rand::Rng;
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?; let client = dagger_sdk::connect()?;
let output = "examples/publish-the-application/app/build"; let output = "examples/publish-the-application/app/build";
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory_opts(

View File

@@ -2,7 +2,7 @@ use dagger_sdk::HostDirectoryOpts;
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?; let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory_opts(
"examples/test-the-application/app", "examples/test-the-application/app",

View File

@@ -13,9 +13,9 @@ use crate::querybuilder::query;
pub type DaggerConn = Arc<Query>; pub type DaggerConn = Arc<Query>;
pub async fn connect() -> eyre::Result<DaggerConn> { pub fn connect() -> eyre::Result<DaggerConn> {
let cfg = Config::default(); let cfg = Config::default();
let (conn, proc) = DaggerEngine::new().start(&cfg).await?; let (conn, proc) = DaggerEngine::new().start(&cfg)?;
Ok(Arc::new(Query { Ok(Arc::new(Query {
conn, conn,
@@ -44,8 +44,8 @@ pub fn graphql_client(conn: &ConnectParams) -> gql_client::Client {
mod test { mod test {
use super::connect; use super::connect;
#[tokio::test] #[test]
async fn test_connect() { fn test_connect() {
let _ = connect().await.unwrap(); let _ = connect().unwrap();
} }
} }

View File

@@ -22,8 +22,8 @@ pub struct SecretId(String);
pub struct SocketId(String); pub struct SocketId(String);
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct BuildArg { pub struct BuildArg {
pub value: String,
pub name: String, pub name: String,
pub value: String,
} }
pub struct CacheVolume { pub struct CacheVolume {
pub proc: Arc<Child>, pub proc: Arc<Child>,

View File

@@ -2,7 +2,7 @@ use dagger_sdk::{connect, ContainerExecOptsBuilder};
#[tokio::test] #[tokio::test]
async fn test_example_container() { async fn test_example_container() {
let client = connect().await.unwrap(); let client = connect().unwrap();
let alpine = client.container().from("alpine:3.16.2"); let alpine = client.container().from("alpine:3.16.2");

View File

@@ -13,11 +13,11 @@ impl Cli {
}) })
} }
pub async fn execute(self, args: &[&str]) -> eyre::Result<()> { pub fn execute(self, args: &[&str]) -> eyre::Result<()> {
let matches = self.cmd.get_matches_from(args); let matches = self.cmd.get_matches_from(args);
match matches.subcommand() { match matches.subcommand() {
Some(("generate", args)) => cli_generate::GenerateCommand::exec(args).await?, Some(("generate", args)) => cli_generate::GenerateCommand::exec(args)?,
_ => eyre::bail!("command missing"), _ => eyre::bail!("command missing"),
} }

View File

@@ -17,12 +17,12 @@ impl GenerateCommand {
clap::Command::new("generate").arg(Arg::new("output").long("output")) clap::Command::new("generate").arg(Arg::new("output").long("output"))
} }
pub async fn exec(arg_matches: &ArgMatches) -> eyre::Result<()> { pub fn exec(arg_matches: &ArgMatches) -> eyre::Result<()> {
let cfg = Config::default(); let cfg = Config::default();
let (conn, _proc) = Engine::new().start(&cfg).await?; let (conn, _proc) = Engine::new().start(&cfg)?;
let session = Session::new(); let session = Session::new();
let req = session.start(&cfg, &conn)?; let req = session.start(&cfg, &conn)?;
let schema = session.schema(req).await?; let schema = session.schema(req)?;
let code = generate( let code = generate(
schema.into_schema().schema.unwrap(), schema.into_schema().schema.unwrap(),
Arc::new(RustGenerator {}), Arc::new(RustGenerator {}),

View File

@@ -3,15 +3,14 @@ use cli::Cli;
pub mod cli; pub mod cli;
mod cli_generate; mod cli_generate;
#[tokio::main] fn main() -> eyre::Result<()> {
async fn main() -> eyre::Result<()> {
color_eyre::install().unwrap(); color_eyre::install().unwrap();
let args = std::env::args(); let args = std::env::args();
let args = args.collect::<Vec<String>>(); let args = args.collect::<Vec<String>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<&str>>(); let args = args.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
Cli::new()?.execute(args.as_slice()).await?; Cli::new()?.execute(args.as_slice())?;
Ok(()) Ok(())
} }