2023-06-17 03:38:48 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use dagger_sdk::{
|
|
|
|
Container, ContainerPublishOptsBuilder, Directory, HostDirectoryOptsBuilder, Query,
|
|
|
|
QueryContainerOptsBuilder,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> eyre::Result<()> {
|
|
|
|
let client = dagger_sdk::connect().await?;
|
|
|
|
|
|
|
|
let src = client.host().directory_opts(
|
|
|
|
".",
|
|
|
|
HostDirectoryOptsBuilder::default()
|
|
|
|
.include(vec![
|
|
|
|
"ci/",
|
|
|
|
"cuddle_cli/",
|
|
|
|
"examples",
|
|
|
|
"Cargo.lock",
|
|
|
|
"Cargo.toml",
|
|
|
|
])
|
|
|
|
.build()?,
|
|
|
|
);
|
|
|
|
|
|
|
|
client
|
|
|
|
.container()
|
|
|
|
.publish_opts(
|
|
|
|
"kasperhermansen/cuddle:dev",
|
|
|
|
ContainerPublishOptsBuilder::default()
|
|
|
|
.platform_variants(vec![
|
|
|
|
dind_image(client.clone(), src.clone(), "x86_64", "linux/amd64")
|
|
|
|
.await?
|
|
|
|
.id()
|
|
|
|
.await?,
|
|
|
|
dind_image(client.clone(), src.clone(), "aarch64", "linux/arm64/v8")
|
|
|
|
.await?
|
|
|
|
.id()
|
|
|
|
.await?,
|
|
|
|
])
|
|
|
|
.build()?,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn dind_image(
|
|
|
|
client: Arc<Query>,
|
|
|
|
src: Directory,
|
|
|
|
architecture: &str,
|
|
|
|
platform: &str,
|
|
|
|
) -> eyre::Result<Container> {
|
|
|
|
let rust_bin = client
|
|
|
|
.container_opts(
|
|
|
|
QueryContainerOptsBuilder::default()
|
|
|
|
.platform(platform)
|
|
|
|
.build()?,
|
|
|
|
)
|
2023-07-27 15:04:46 +02:00
|
|
|
.from("rustlang/rust:nightly")
|
2023-06-17 03:38:48 +02:00
|
|
|
.with_exec(vec![
|
|
|
|
"rustup",
|
|
|
|
"target",
|
|
|
|
"add",
|
|
|
|
&format!("{architecture}-unknown-linux-musl"),
|
|
|
|
])
|
|
|
|
.with_exec(vec!["update-ca-certificates"])
|
|
|
|
.with_exec(vec!["apt-get", "update"])
|
|
|
|
.with_exec(vec!["apt-get", "upgrade", "-y"])
|
|
|
|
.with_exec(vec![
|
|
|
|
"apt-get",
|
|
|
|
"install",
|
|
|
|
"-y",
|
|
|
|
"-q",
|
|
|
|
"build-essential",
|
|
|
|
"curl",
|
|
|
|
"git",
|
|
|
|
"musl-tools",
|
|
|
|
"musl-dev",
|
|
|
|
"libz-dev",
|
|
|
|
])
|
|
|
|
.with_workdir("/app/cuddle/")
|
|
|
|
.with_directory(".", src.id().await?)
|
|
|
|
.with_exec(vec![
|
|
|
|
"cargo",
|
|
|
|
"install",
|
|
|
|
"--target",
|
|
|
|
&format!("{architecture}-unknown-linux-musl"),
|
|
|
|
"--path",
|
|
|
|
"cuddle_cli",
|
|
|
|
"--profile=release",
|
|
|
|
]);
|
|
|
|
|
|
|
|
let final_image = client
|
|
|
|
.container_opts(
|
|
|
|
QueryContainerOptsBuilder::default()
|
|
|
|
.platform(platform)
|
|
|
|
.build()?,
|
|
|
|
)
|
|
|
|
.from("docker:dind")
|
|
|
|
.with_directory(
|
|
|
|
"/usr/local/cargo/bin/",
|
|
|
|
rust_bin.directory("/usr/local/cargo/bin/").id().await?,
|
|
|
|
);
|
|
|
|
|
|
|
|
let path_env = final_image.env_variable("PATH").await?;
|
|
|
|
|
|
|
|
let final_image = final_image
|
|
|
|
.with_env_variable("PATH", format!("{path_env}:/usr/local/cargo/bin"))
|
|
|
|
.with_exec(vec![""]);
|
|
|
|
|
|
|
|
Ok(final_image)
|
|
|
|
}
|