Skip to content

Commit

Permalink
[buildx] add build_cloud function
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Sep 14, 2024
1 parent c450cb3 commit 3d49ef4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion buildx/dagger.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "buildx",
"sdk": "github.com/fluentci-io/daggerverse/deno-sdk@main",
"version": "v0.1.1",
"version": "v0.1.2",
"description": "",
"author": "Tsiry Sandratraina",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion buildx/plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "buildx"
version = "0.1.1"
version = "0.1.2"

[lib]
crate-type = ["cdylib"]
Expand Down
49 changes: 49 additions & 0 deletions buildx/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,55 @@ pub fn build(args: String) -> FnResult<String> {
Ok(stdout)
}

#[plugin_fn]
pub fn build_cloud(args: String) -> FnResult<String> {
let builder = dag().get_env("BUILDX_BUILDER")?;
if builder.is_empty() {
return Err(Error::msg("BUILDX_BUILDER must be set").into());
}

let version = dag()
.get_env("BUILDX_VERSION")
.unwrap_or("v0.17.1-desktop.1".into());
let version = match version.as_str() {
"" => "v0.17.1-desktop.1".into(),
_ => version,
};
let (os, arch) = detect_system()?;

let buildx_download_url = format!(
"https://github.com/docker/buildx-desktop/releases/download/{}/buildx-{}.{}-{}",
version, version, os, arch
);

let buildx_plugin = format!("buildx-{}.{}-{}", version, os, arch);
let stdout = dag()
.pipeline("build")?
.pkgx()?
.with_exec(vec!["pkgx", "install", "docker", "wget"])?
.with_exec(vec![&format!(
r#"
if [ ! -f $HOME/.docker/cli-plugins/{} ]; then
wget {};
chmod +x {};
mkdir -p $HOME/.docker/cli-plugins;
mv {} $HOME/.docker/cli-plugins;
fi
"#,
buildx_plugin, buildx_download_url, buildx_plugin, buildx_plugin
)])?
.with_exec(vec![&format!(
"docker buildx create --driver cloud {} || true",
&builder
)])?
.with_exec(vec!["docker", "buildx", "inspect", "--bootstrap"])?
.with_exec(vec!["docker", "buildx", "version"])?
.with_exec(vec!["docker", "-v"])?
.with_exec(vec!["docker", "buildx", "build", &args])?
.stdout()?;
Ok(stdout)
}

#[plugin_fn]
pub fn publish(args: String) -> FnResult<String> {
let registry_password = dag().get_env("REGISTRY_PASSWORD")?;
Expand Down

0 comments on commit 3d49ef4

Please sign in to comment.