Skip to content

Commit

Permalink
[buildx] add setup function
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Sep 27, 2024
1 parent 06ff147 commit d075b79
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 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.4",
"version": "v0.1.5",
"description": "",
"author": "Tsiry Sandratraina",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion buildx/fluentci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ authors = [
description = "CI/CD Plugin for Buildx"
license = "MIT"
name = "buildx"
version = "0.1.0"
version = "0.1.5"
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.4"
version = "0.1.5"

[lib]
crate-type = ["cdylib"]
Expand Down
43 changes: 43 additions & 0 deletions buildx/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,49 @@ mod helpers;

use helpers::detect_system;

#[plugin_fn]
pub fn setup(_args: String) -> FnResult<String> {
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/docker-buildx ]; then
wget {};
chmod +x {};
mkdir -p $HOME/.docker/cli-plugins;
mv {} $HOME/.docker/cli-plugins/docker-buildx;
fi
"#,
buildx_download_url, buildx_plugin, buildx_plugin
)])?
.with_exec(vec!["docker buildx rm builder || true"])?
.with_exec(vec![
"docker", "buildx", "create", "--name", "builder", "--use",
])?
.with_exec(vec!["docker", "buildx", "inspect", "--bootstrap"])?
.with_exec(vec!["docker", "buildx", "version"])?
.with_exec(vec!["docker", "-v"])?
.stdout()?;
Ok(stdout)
}

#[plugin_fn]
pub fn build(args: String) -> FnResult<String> {
let version = dag()
Expand Down

0 comments on commit d075b79

Please sign in to comment.