2023-02-19 15:24:37 +01:00
|
|
|
use dagger_sdk::HostDirectoryOpts;
|
2023-02-17 17:29:23 +01:00
|
|
|
use rand::Rng;
|
|
|
|
|
|
|
|
fn main() -> eyre::Result<()> {
|
2023-02-19 15:24:37 +01:00
|
|
|
let client = dagger_sdk::connect()?;
|
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-17 17:29:23 +01:00
|
|
|
Some(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,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
let source = client
|
2023-02-19 17:43:12 +01:00
|
|
|
.container()
|
2023-02-19 17:21:40 +01:00
|
|
|
.from("node:16")
|
|
|
|
.with_mounted_directory("/src", host_source_dir.id()?);
|
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 17:43:12 +01:00
|
|
|
client.host().directory(output).id()?,
|
2023-02-17 17:29:23 +01:00
|
|
|
)
|
2023-02-19 17:43:12 +01:00
|
|
|
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
2023-02-17 17:29:23 +01:00
|
|
|
|
|
|
|
println!("published image to: {}", ref_);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|