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/",
|
2023-08-12 21:42:13 +02:00
|
|
|
"cuddle/",
|
2023-06-17 03:38:48 +02:00
|
|
|
"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/")
|
2024-01-28 16:41:50 +01:00
|
|
|
.with_directory(".", src)
|
2023-06-17 03:38:48 +02:00
|
|
|
.with_exec(vec![
|
|
|
|
"cargo",
|
|
|
|
"install",
|
|
|
|
"--target",
|
|
|
|
&format!("{architecture}-unknown-linux-musl"),
|
|
|
|
"--path",
|
2023-08-12 21:42:13 +02:00
|
|
|
"cuddle",
|
2023-06-17 03:38:48 +02:00
|
|
|
"--profile=release",
|
|
|
|
]);
|
|
|
|
|
|
|
|
let final_image = client
|
|
|
|
.container_opts(
|
|
|
|
QueryContainerOptsBuilder::default()
|
|
|
|
.platform(platform)
|
|
|
|
.build()?,
|
|
|
|
)
|
|
|
|
.from("docker:dind")
|
|
|
|
.with_directory(
|
|
|
|
"/usr/local/cargo/bin/",
|
2024-01-28 16:41:50 +01:00
|
|
|
rust_bin.directory("/usr/local/cargo/bin/"),
|
2023-06-17 03:38:48 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|