kjuulh
85cc1d46db
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
113 lines
2.9 KiB
Rust
113 lines
2.9 KiB
Rust
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/",
|
|
"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()?,
|
|
)
|
|
.from("rustlang/rust:nightly")
|
|
.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)
|
|
.with_exec(vec![
|
|
"cargo",
|
|
"install",
|
|
"--target",
|
|
&format!("{architecture}-unknown-linux-musl"),
|
|
"--path",
|
|
"cuddle",
|
|
"--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/"),
|
|
);
|
|
|
|
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)
|
|
}
|