dagger-rs/crates/dagger-sdk/examples/publish-the-application/main.rs

48 lines
1.2 KiB
Rust
Raw Permalink Normal View History

use dagger_sdk::HostDirectoryOpts;
2023-02-17 17:29:23 +01:00
use rand::Rng;
#[tokio::main]
async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?;
2023-02-17 17:29:23 +01:00
let output = "examples/publish-the-application/app/build";
let host_source_dir = client.host().directory_opts(
"examples/publish-the-application/app",
HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]),
2023-02-17 17:29:23 +01:00
include: None,
},
2023-02-17 17:29:23 +01:00
);
let source = client
.container()
.from("node:16")
.with_mounted_directory("/src", host_source_dir.id().await?);
2023-02-17 17:29:23 +01:00
let runner = source
.with_workdir("/src")
.with_exec(vec!["npm", "install"]);
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]);
2023-02-17 17:29:23 +01:00
let _ = test
.with_exec(vec!["npm", "run", "build"])
.directory("./build")
.export(output);
2023-02-17 17:29:23 +01:00
let mut rng = rand::thread_rng();
let ref_ = client
.container()
.from("nginx")
2023-02-17 17:29:23 +01:00
.with_directory(
"/usr/share/nginx/html",
client.host().directory(output).id().await?,
2023-02-17 17:29:23 +01:00
)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>())).await?;
2023-02-17 17:29:23 +01:00
println!("published image to: {}", ref_);
Ok(())
}