mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-07-25 19:09:22 +02:00
feat(sdk,core): 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?; // ... } ```
This commit is contained in:
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user