From face027857fbeb41e2aef1ecd91f92c05b1dd4ae Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Fri, 15 Mar 2024 23:21:45 +0000 Subject: [PATCH] ci: install curl add nix to PATH add nix to PATH add nix to PATH add pkgx to PATH fix e2e tests ci: fix workdir update exts --- .fluentci/src/dagger/jobs.ts | 33 +++++++++++++++++++++------------ crates/ext/src/devbox.rs | 1 + crates/ext/src/devenv.rs | 1 + crates/ext/src/flox.rs | 1 + crates/ext/src/nix.rs | 19 +++++++++++++++---- crates/ext/src/pkgx.rs | 23 ++++++++++++++--------- fixtures/flox.graphql | 4 ++-- fixtures/pkgx.graphql | 14 ++++++++++++++ 8 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 fixtures/pkgx.graphql diff --git a/.fluentci/src/dagger/jobs.ts b/.fluentci/src/dagger/jobs.ts index 715ecd3..a9699e4 100644 --- a/.fluentci/src/dagger/jobs.ts +++ b/.fluentci/src/dagger/jobs.ts @@ -225,7 +225,10 @@ export async function e2e( const engine = dag .container() .from("debian:bookworm") + .withExec(["apt-get", "update"]) + .withExec(["apt-get", "install", "-y", "curl", "ca-certificates", "git"]) .withDirectory("/app", context, { exclude }) + .withWorkdir("/app") .withFile( "/fluentci-engine", dag.host().file("./target/release/fluentci-engine") @@ -235,7 +238,7 @@ export async function e2e( .withExposedPort(6880) .asService(); - let ctr = await dag + const ctr = await dag .pipeline(Job.e2e) .container() .from("pkgxdev/pkgx:latest") @@ -246,40 +249,46 @@ export async function e2e( .withServiceBinding("fluentci-engine", engine) .sync(); - ctr = ctr.withExec([ + const pkgx = ctr.withExec([ + "bash", + "-c", + `http POST http://fluentci-engine:6880/graphql Content-Type:application/json query="$(cat pkgx.graphql)" --ignore-stdin`, + ]); + + console.log(await pkgx.stdout()); + + const nix = ctr.withExec([ "bash", "-c", `http POST http://fluentci-engine:6880/graphql Content-Type:application/json query="$(cat nix.graphql)" --ignore-stdin`, ]); - let stdout = await ctr.stdout(); - console.log(stdout); + console.log(await nix.stdout()); - ctr = ctr.withExec([ + const flox = ctr.withExec([ "bash", "-c", `http POST http://fluentci-engine:6880/graphql Content-Type:application/json query="$(cat flox.graphql)" --ignore-stdin`, ]); - stdout = await ctr.stdout(); - console.log(stdout); + console.log(await flox.stdout()); - ctr = ctr.withExec([ + const devenv = ctr.withExec([ "bash", "-c", `http POST http://fluentci-engine:6880/graphql Content-Type:application/json query="$(cat devenv.graphql)" --ignore-stdin`, ]); - stdout = await ctr.stdout(); - console.log(stdout); + console.log(await devenv.stdout()); - ctr = ctr.withExec([ + const devbox = ctr.withExec([ "bash", "-c", `http POST http://fluentci-engine:6880/graphql Content-Type:application/json query="$(cat devbox.graphql)" --ignore-stdin`, ]); - stdout = await ctr.stdout(); + const stdout = await devbox.stdout(); + console.log(stdout); return stdout; diff --git a/crates/ext/src/devbox.rs b/crates/ext/src/devbox.rs index 9c08018..5cfd521 100644 --- a/crates/ext/src/devbox.rs +++ b/crates/ext/src/devbox.rs @@ -114,6 +114,7 @@ impl Extension for Devbox { let mut child = Command::new("sh") .arg("-c") .arg("type devbox > /dev/null || curl -fsSL https://get.jetpack.io/devbox | bash") + .env("FORCE", "1") .spawn()?; child.wait()?; Ok(()) diff --git a/crates/ext/src/devenv.rs b/crates/ext/src/devenv.rs index e54dd63..babc8db 100644 --- a/crates/ext/src/devenv.rs +++ b/crates/ext/src/devenv.rs @@ -99,6 +99,7 @@ impl Extension for Devenv { fn setup(&self) -> Result<(), Error> { Nix::default().setup()?; + let mut child = Command::new("sh") .arg("-c") .arg("type devenv > /dev/null") diff --git a/crates/ext/src/flox.rs b/crates/ext/src/flox.rs index 7799883..1d9ab4f 100644 --- a/crates/ext/src/flox.rs +++ b/crates/ext/src/flox.rs @@ -97,6 +97,7 @@ impl Extension for Flox { fn setup(&self) -> Result<(), Error> { Nix::default().setup()?; + let status = Command::new("sh") .arg("-c") .arg("type flox > /dev/null") diff --git a/crates/ext/src/nix.rs b/crates/ext/src/nix.rs index db2a731..776f685 100644 --- a/crates/ext/src/nix.rs +++ b/crates/ext/src/nix.rs @@ -104,14 +104,23 @@ impl Extension for Nix { }; env::set_var("USER", user); + env::set_var("SHELL", "/bin/bash"); + + let home = match env::var("HOME") { + Ok(home) => home, + Err(_) => "/root".to_string(), + }; + let nix_path = format!("{}/.nix-profile/bin", home); env::set_var( "PATH", format!( - "{}:{}", + "{}:{}:{}", env::var("PATH")?, - "/nix/var/nix/profiles/default/bin" + "/nix/var/nix/profiles/default/bin", + nix_path ), ); + let mut child = Command::new("sh") .arg("-c") .arg("type systemctl > /dev/null") @@ -126,15 +135,17 @@ impl Extension for Nix { "linux" => format!("linux --extra-conf 'sandbox = false' {}", init), _ => "".to_string(), }; - let mut child = Command::new("sh") + let mut child = Command::new("bash") .arg("-c") .arg(format!("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install {}", linux)) + .spawn()?; child.wait()?; - let mut child = Command::new("sh") + let mut child = Command::new("bash") .arg("-c") .arg(format!("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install {} --no-confirm", linux)) + .spawn()?; child.wait()?; Ok(()) diff --git a/crates/ext/src/pkgx.rs b/crates/ext/src/pkgx.rs index 22fa80f..38e9fb6 100644 --- a/crates/ext/src/pkgx.rs +++ b/crates/ext/src/pkgx.rs @@ -16,6 +16,7 @@ pub struct Pkgx {} impl Pkgx { pub fn install(&self, pkgs: Vec<&str>) -> Result { self.setup()?; + let mut child = Command::new("sh") .arg("-c") .arg(format!("pkgx install {}", pkgs.join(" "))) @@ -68,7 +69,10 @@ impl Extension for Pkgx { stdout.push_str("\n"); } if out_clone == Output::Stdout && last_cmd { - tx_clone.send(stdout).unwrap(); + match tx_clone.send(stdout) { + Ok(_) => {} + Err(e) => eprintln!("{}", e), + } } }); @@ -80,7 +84,10 @@ impl Extension for Pkgx { stderr.push_str("\n"); } if out == Output::Stderr && last_cmd { - tx.send(stderr).unwrap(); + match tx.send(stderr) { + Ok(_) => {} + Err(e) => eprintln!("{}", e), + } } }); @@ -102,14 +109,12 @@ impl Extension for Pkgx { } fn setup(&self) -> Result<(), Error> { - env::set_var( - "PATH", - format!( - "{}:{}", - env::var("PATH")?, - format!("{}/.local/bin", env::var("HOME")?) - ), + let path = format!( + "{}:{}", + env::var("PATH")?, + format!("{}/.local/bin", env::var("HOME")?) ); + env::set_var("PATH", &path); let mut child = Command::new("sh") .arg("-c") .arg("type pkgx > /dev/null || curl -fsS https://pkgx.sh | sh") diff --git a/fixtures/flox.graphql b/fixtures/flox.graphql index 1b3301a..8621570 100644 --- a/fixtures/flox.graphql +++ b/fixtures/flox.graphql @@ -2,8 +2,8 @@ query Flox { pipeline(name: "Demo") { flox { withWorkDir(path: "./flox-demo") { - withExec(args: ["echo", "hello"]) { - withExec(args: ["flox", "--version"]) { + withExec(args: ["flox", "--version"]) { + withExec(args: ["which", "jq"]) { id stdout } diff --git a/fixtures/pkgx.graphql b/fixtures/pkgx.graphql new file mode 100644 index 0000000..b671381 --- /dev/null +++ b/fixtures/pkgx.graphql @@ -0,0 +1,14 @@ +query Pkgx { + pipeline(name: "Demo") { + pkgx { + withWorkDir(path: "./pkgx-demo") { + withExec(args: ["pkgx", "--version"]) { + withExec(args: ["which", "deno"]) { + id + stdout + } + } + } + } + } +}