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() .exclude(vec!["target/", ".git/", "ci/"]) .build()?, ); let variants = vec![/*"linux/amd64", */ "linux/arm64"]; 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") //.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", //]) .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") .with_exec(vec!["apt-get", "update"]) .with_exec(vec!["apt-get", "install", "-y", "openssl", "git"]) .with_file( "/usr/bin/update-deployment", rust_dep_image .file("target/release/update-deployment") .id() .await .unwrap(), ) .with_exec(vec!["update-deployment", "--help"]); 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::>(); 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(()) }