2023-02-19 15:24:37 +01:00
|
|
|
use dagger_sdk::HostDirectoryOpts;
|
2023-02-17 17:29:23 +01:00
|
|
|
use rand::Rng;
|
|
|
|
|
2023-02-19 21:37:54 +01:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> eyre::Result<()> {
|
2023-02-20 10:10:42 +01:00
|
|
|
let client = dagger_sdk::connect().await?;
|
2023-02-17 17:29:23 +01:00
|
|
|
let output = "examples/publish-the-application/app/build";
|
|
|
|
|
2023-02-19 17:43:12 +01:00
|
|
|
let host_source_dir = client.host().directory_opts(
|
2023-02-19 17:21:40 +01:00
|
|
|
"examples/publish-the-application/app",
|
2023-02-19 17:49:22 +01:00
|
|
|
HostDirectoryOpts {
|
2023-02-19 17:21:40 +01:00
|
|
|
exclude: Some(vec!["node_modules", "ci/"]),
|
2023-02-17 17:29:23 +01:00
|
|
|
include: None,
|
2023-02-19 17:49:22 +01:00
|
|
|
},
|
2023-02-17 17:29:23 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
let source = client
|
2023-02-19 17:43:12 +01:00
|
|
|
.container()
|
2023-02-19 17:21:40 +01:00
|
|
|
.from("node:16")
|
2023-02-19 21:37:54 +01:00
|
|
|
.with_mounted_directory("/src", host_source_dir.id().await?);
|
2023-02-17 17:29:23 +01:00
|
|
|
|
|
|
|
let runner = source
|
2023-02-19 17:21:40 +01:00
|
|
|
.with_workdir("/src")
|
2023-02-19 17:43:12 +01:00
|
|
|
.with_exec(vec!["npm", "install"]);
|
2023-02-19 17:21:40 +01:00
|
|
|
|
2023-02-19 17:43:12 +01:00
|
|
|
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]);
|
2023-02-17 17:29:23 +01:00
|
|
|
|
|
|
|
let _ = test
|
2023-02-19 17:43:12 +01:00
|
|
|
.with_exec(vec!["npm", "run", "build"])
|
2023-02-19 17:21:40 +01:00
|
|
|
.directory("./build")
|
|
|
|
.export(output);
|
2023-02-17 17:29:23 +01:00
|
|
|
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
|
|
|
|
let ref_ = client
|
2023-02-19 17:43:12 +01:00
|
|
|
.container()
|
2023-02-19 17:21:40 +01:00
|
|
|
.from("nginx")
|
2023-02-17 17:29:23 +01:00
|
|
|
.with_directory(
|
2023-02-19 17:21:40 +01:00
|
|
|
"/usr/share/nginx/html",
|
2023-02-19 21:37:54 +01:00
|
|
|
client.host().directory(output).id().await?,
|
2023-02-17 17:29:23 +01:00
|
|
|
)
|
2023-02-19 21:37:54 +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(())
|
|
|
|
}
|