Skip to content

Commit

Permalink
feat: add support for executing wasm from a container registry (ghcr.…
Browse files Browse the repository at this point in the history
…io, gcr.io, azurecr.io)
  • Loading branch information
tsirysndr committed Jul 26, 2024
1 parent 00bfd17 commit 92f0a38
Show file tree
Hide file tree
Showing 10 changed files with 1,012 additions and 952 deletions.
1,830 changes: 915 additions & 915 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ license = "MPL-2.0"
name = "fluentci-engine"
readme = "../../README.md"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.4.6"
version = "0.4.7"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.81"
clap = "3.2.20"
extism = "1.2.0"
fluentci-core = {path = "../core", version = "0.3.4"}
fluentci-core = {path = "../core", version = "0.3.5"}
fluentci-ext = {path = "../ext", version = "0.2.4"}
fluentci-server = {path = "../server", version = "0.3.4"}
fluentci-shared = {path = "../shared", version = "0.2.4"}
fluentci-server = {path = "../server", version = "0.3.5"}
fluentci-shared = {path = "../shared", version = "0.2.5"}
get-port = "4.0.0"
md5 = "0.7.0"
regex = "1.10.3"
Expand Down
62 changes: 61 additions & 1 deletion crates/cli/src/cmd/call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
env::consts::{ARCH, OS},
fs,
process::{Command, Stdio},
sync::{mpsc, Arc, Mutex},
Expand Down Expand Up @@ -52,7 +53,11 @@ pub fn call(module: &str, command: &str) -> Result<(), Error> {
runner: "default".into(),
});

let module = match module.starts_with("http") {
let module = match module.starts_with("http")
|| module.starts_with("azurecr.io/")
|| module.starts_with("ghcr.io/")
|| module.starts_with("gcr.io/")
{
true => download_module(module)?,
false => Wasm::file(module),
};
Expand Down Expand Up @@ -153,6 +158,23 @@ pub fn download_module(url: &str) -> Result<Wasm, Error> {

Pkgx::default().setup()?;

if url.starts_with("azurecr.io/") || url.starts_with("ghcr.io/") || url.starts_with("gcr.io/") {
fs::create_dir_all(&work_dir)?;
setup_wasm_to_oci()?;

let mut child = Command::new("bash")
.arg("-c")
.arg(format!("wasm-to-oci pull {} --out {}", url, filename))
.current_dir(&work_dir)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()?;

child.wait()?;

return Ok(Wasm::file(format!("{}/{}", work_dir, filename)));
}

let cmd = format!(
"pkgx +rockdaboot.github.io/libpsl +curl.se curl -s {} -o {}",
url, filename
Expand All @@ -171,3 +193,41 @@ pub fn download_module(url: &str) -> Result<Wasm, Error> {

Ok(Wasm::file(format!("{}/{}", work_dir, filename)))
}

pub fn setup_wasm_to_oci() -> Result<(), Error> {
let os = match OS {
"macos" => "darwin",
_ => OS,
};
let arch = match ARCH {
"x86_64" => "amd64",
"aarch64" => "arm64",
_ => ARCH,
};

std::env::set_var("OS", os);
std::env::set_var("ARCH", arch);

let path = std::env::var("PATH").unwrap();
let home = std::env::var("HOME").unwrap();
let path = format!("{}/.local/bin:{}", home, path);
std::env::set_var("PATH", path);

fs::create_dir_all(format!("{}/.local/bin", home))?;

let mut child = Command::new("bash")
.arg("-c")
.arg("type wasm-to-oci > /dev/null 2> /dev/null || pkgx wget https://github.com/fluentci-io/wasm-to-oci/releases/download/v0.1.2/wasm-to-oci_${OS}-${ARCH}.tar.gz ; \
type wasm-to-oci > /dev/null 2> /dev/null || pkgx tar xvf wasm-to-oci_${OS}-${ARCH}.tar.gz ; \
type wasm-to-oci > /dev/null 2> /dev/null || cp wasm-to-oci ${HOME}/.local/bin ; \
[ -f wasm-to-oci ] && rm wasm-to-oci || true ; \
[ -f wasm-to-oci_${OS}-${ARCH}.tar.gz ] && rm wasm-to-oci_${OS}-${ARCH}.tar.gz || true \
")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()?;

child.wait()?;

Ok(())
}
4 changes: 2 additions & 2 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-common"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.2.4"
version = "0.2.5"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.81"
dirs = "5.0.1"
fluentci-core = {path = "../core", version = "0.3.4"}
fluentci-core = {path = "../core", version = "0.3.5"}
fluentci-ext = {path = "../ext", version = "0.2.4"}
fluentci-secrets = {path = "../secrets", version = "0.1.0"}
fluentci-types = {path = "../types", version = "0.1.7"}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-core"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.3.4"
version = "0.3.5"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
10 changes: 5 additions & 5 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,39 +111,39 @@ pub fn init_tracer() -> Result<(), TraceError> {
pub fn set_git_repo_metadata() -> Result<(), Error> {
let child = Command::new("sh")
.arg("-c")
.arg("git log -1 --pretty=%s")
.arg("git log -1 --pretty=%s 2> /dev/null")
.stdout(std::process::Stdio::piped())
.spawn()?;
let output = child.wait_with_output()?;
let commit_message = String::from_utf8(output.stdout)?;

let child = Command::new("sh")
.arg("-c")
.arg("git rev-parse --abbrev-ref HEAD")
.arg("git rev-parse --abbrev-ref HEAD 2> /dev/null")
.stdout(std::process::Stdio::piped())
.spawn()?;
let output = child.wait_with_output()?;
let branch = String::from_utf8(output.stdout)?;

let child = Command::new("sh")
.arg("-c")
.arg("git log -1 --pretty=%h")
.arg("git log -1 --pretty=%h 2> /dev/null")
.stdout(std::process::Stdio::piped())
.spawn()?;
let output = child.wait_with_output()?;
let commit_hash = String::from_utf8(output.stdout)?;

let child = Command::new("sh")
.arg("-c")
.arg("git remote get-url origin")
.arg("git remote get-url origin 2> /dev/null")
.stdout(std::process::Stdio::piped())
.spawn()?;
let output = child.wait_with_output()?;
let remote_url = String::from_utf8(output.stdout)?;

let child = Command::new("sh")
.arg("-c")
.arg("git log -1 --pretty=%an")
.arg("git log -1 --pretty=%an 2> /dev/null")
.stdout(std::process::Stdio::piped())
.spawn()?;
let output = child.wait_with_output()?;
Expand Down
6 changes: 3 additions & 3 deletions crates/graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-graphql"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.3.4"
version = "0.3.5"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -16,8 +16,8 @@ anyhow = "1.0.80"
async-graphql = "7.0.2"
async-graphql-actix-web = "7.0.2"
dirs = "5.0.1"
fluentci-common = {path = "../common", version = "0.2.4"}
fluentci-core = {path = "../core", version = "0.3.4"}
fluentci-common = {path = "../common", version = "0.2.5"}
fluentci-core = {path = "../core", version = "0.3.5"}
fluentci-ext = {path = "../ext", version = "0.2.4"}
fluentci-secrets = {path = "../secrets", version = "0.1.0"}
fluentci-types = {path = "../types", version = "0.1.7"}
Expand Down
6 changes: 3 additions & 3 deletions crates/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-server"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.3.4"
version = "0.3.5"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -17,9 +17,9 @@ actix-web = "4.5.1"
anyhow = "1.0.81"
async-graphql = "7.0.2"
async-graphql-actix-web = "7.0.2"
fluentci-core = {path = "../core", version = "0.3.4"}
fluentci-core = {path = "../core", version = "0.3.5"}
fluentci-ext = {path = "../ext", version = "0.2.4"}
fluentci-graphql = {path = "../graphql", version = "0.3.4"}
fluentci-graphql = {path = "../graphql", version = "0.3.5"}
mime_guess = "2.0.4"
owo-colors = "4.0.0"
tokio = "1.36.0"
6 changes: 3 additions & 3 deletions crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-shared"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.2.4"
version = "0.2.5"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.82"
extism = "1.2.0"
extism-pdk = "1.1.0"
fluentci-common = {path = "../common", version = "0.2.4"}
fluentci-core = {path = "../core", version = "0.3.4"}
fluentci-common = {path = "../common", version = "0.2.5"}
fluentci-core = {path = "../core", version = "0.3.5"}
fluentci-ext = {path = "../ext", version = "0.2.4"}
fluentci-secrets = {path = "../secrets", version = "0.1.0"}
fluentci-types = {path = "../types", version = "0.1.7"}
Expand Down
30 changes: 15 additions & 15 deletions flake.lock

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

0 comments on commit 92f0a38

Please sign in to comment.