2023-04-02 23:23:50 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use dagger_sdk::{HostDirectoryOptsBuilder, QueryContainerOptsBuilder};
|
|
|
|
use tokio::sync::Mutex;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> eyre::Result<()> {
|
|
|
|
color_eyre::install().unwrap();
|
|
|
|
|
|
|
|
let client = dagger_sdk::connect().await?;
|
|
|
|
|
|
|
|
let src = client.host().directory_opts(
|
|
|
|
".",
|
|
|
|
HostDirectoryOptsBuilder::default()
|
2023-04-03 00:18:32 +02:00
|
|
|
.exclude(vec!["target/", ".git/", "ci/"])
|
2023-04-02 23:23:50 +02:00
|
|
|
.build()?,
|
|
|
|
);
|
|
|
|
|
2023-04-03 00:18:32 +02:00
|
|
|
let variants = vec![/*"linux/amd64", */ "linux/arm64"];
|
2023-04-02 23:23:50 +02:00
|
|
|
let platform_variants = Arc::new(Mutex::new(Vec::new()));
|
|
|
|
|
|
|
|
tokio_scoped::scope(|s| {
|
|
|
|
for platform in variants {
|
|
|
|
let client = client.clone();
|
|
|
|
let platform_variants = platform_variants.clone();
|
|
|
|
let src = src.clone();
|
|
|
|
|
|
|
|
s.spawn(async move {
|
|
|
|
let rust_dep_image = client
|
|
|
|
.container_opts(
|
|
|
|
QueryContainerOptsBuilder::default()
|
|
|
|
.platform(platform)
|
|
|
|
.build()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.from("rustlang/rust:nightly")
|
|
|
|
.with_workdir("/app")
|
2023-04-03 00:18:32 +02:00
|
|
|
//.with_exec(vec!["apt-get", "update"])
|
|
|
|
//.with_exec(vec![
|
|
|
|
// "apt-get",
|
|
|
|
// "install",
|
|
|
|
// "-y",
|
|
|
|
// "build-essential",
|
|
|
|
// "cmake",
|
|
|
|
// "curl",
|
|
|
|
// "file",
|
|
|
|
// "git",
|
|
|
|
// "sudo",
|
|
|
|
// "xutils-dev",
|
|
|
|
// "unzip",
|
|
|
|
// "ca-certificates",
|
|
|
|
// "python3",
|
|
|
|
// "python3-pip",
|
|
|
|
// "autoconf",
|
|
|
|
// "autoconf-archive",
|
|
|
|
// "automake",
|
|
|
|
// "flex",
|
|
|
|
// "bison",
|
|
|
|
// "llvm-dev",
|
|
|
|
// "libclang-dev",
|
|
|
|
// "clang",
|
|
|
|
//])
|
2023-04-02 23:23:50 +02:00
|
|
|
.with_directory(".", src.id().await.unwrap())
|
|
|
|
.with_exec(vec!["cargo", "build", "--release"]);
|
|
|
|
|
|
|
|
let dep_image = client
|
|
|
|
.container_opts(
|
|
|
|
QueryContainerOptsBuilder::default()
|
|
|
|
.platform(platform)
|
|
|
|
.build()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.from("debian:bullseye")
|
2023-04-03 00:18:32 +02:00
|
|
|
.with_exec(vec!["apt-get", "update"])
|
|
|
|
.with_exec(vec!["apt-get", "install", "-y", "openssl", "git"])
|
2023-04-02 23:23:50 +02:00
|
|
|
.with_file(
|
|
|
|
"/usr/bin/update-deployment",
|
|
|
|
rust_dep_image
|
|
|
|
.file("target/release/update-deployment")
|
|
|
|
.id()
|
|
|
|
.await
|
|
|
|
.unwrap(),
|
2023-04-03 00:18:32 +02:00
|
|
|
)
|
|
|
|
.with_exec(vec!["update-deployment", "--help"]);
|
2023-04-02 23:23:50 +02:00
|
|
|
|
|
|
|
let mut platform_variants = platform_variants.lock().await;
|
|
|
|
platform_variants.push(dep_image.id().await.unwrap())
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let variants = platform_variants
|
|
|
|
.lock()
|
|
|
|
.await
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let tag = chrono::Utc::now().timestamp();
|
|
|
|
|
|
|
|
let _ = client
|
|
|
|
.container()
|
|
|
|
.publish_opts(
|
|
|
|
format!("kasperhermansen/update-deployment:{tag}"),
|
|
|
|
dagger_sdk::ContainerPublishOptsBuilder::default()
|
|
|
|
.platform_variants(variants)
|
|
|
|
.build()?,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|