From a4a5098dfdf3045151f9628ca4b457334809d205 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Fri, 15 Mar 2024 23:54:38 +0000 Subject: [PATCH] add nix to PATH add nix to PATH add nix to PATH add pkgx to PATH fix e2e tests ci: fix workdir --- .fluentci/src/dagger/jobs.ts | 31 +++++++++++++++++++------------ crates/ext/src/devbox.rs | 13 +++++++++++++ crates/ext/src/devenv.rs | 14 ++++++++++++++ crates/ext/src/flox.rs | 24 ++++++++++++++++++++++++ crates/ext/src/nix.rs | 24 ++++++++++++++++++++---- crates/ext/src/pkgx.rs | 27 ++++++++++++++++++++------- fixtures/flox.graphql | 4 ++-- fixtures/pkgx.graphql | 14 ++++++++++++++ 8 files changed, 126 insertions(+), 25 deletions(-) create mode 100644 fixtures/pkgx.graphql diff --git a/.fluentci/src/dagger/jobs.ts b/.fluentci/src/dagger/jobs.ts index 53f1b42..a9699e4 100644 --- a/.fluentci/src/dagger/jobs.ts +++ b/.fluentci/src/dagger/jobs.ts @@ -228,6 +228,7 @@ export async function e2e( .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") @@ -237,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") @@ -248,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..43912f0 100644 --- a/crates/ext/src/devbox.rs +++ b/crates/ext/src/devbox.rs @@ -1,4 +1,5 @@ use std::{ + env, io::{BufRead, BufReader}, process::{Command, ExitStatus, Stdio}, sync::mpsc::{self, Receiver, Sender}, @@ -41,12 +42,22 @@ impl Extension for Devbox { return Ok(ExitStatus::default()); } + let home = env::var("HOME")?; + let nix_path = format!("{}/.nix-profile/bin", home); + let path = format!( + "{}:{}:{}", + nix_path, + "/nix/var/nix/profiles/default/bin", + env::var("PATH")? + ); + let (stdout_tx, stdout_rx): (Sender, Receiver) = mpsc::channel(); let (stderr_tx, stderr_rx): (Sender, Receiver) = mpsc::channel(); Command::new("bash") .arg("-c") .arg("[ -f devbox.json ] || devbox init") + .env("PATH", &path) .current_dir(work_dir) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -56,6 +67,7 @@ impl Extension for Devbox { let mut child = Command::new("bash") .arg("-c") .arg(format!("devbox run {}", cmd)) + .env("PATH", &path) .current_dir(work_dir) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -114,6 +126,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..4bedc8e 100644 --- a/crates/ext/src/devenv.rs +++ b/crates/ext/src/devenv.rs @@ -1,4 +1,5 @@ use std::{ + env, io::{BufRead, BufReader}, process::{Command, ExitStatus, Stdio}, sync::mpsc::{self, Receiver, Sender}, @@ -99,9 +100,19 @@ impl Extension for Devenv { fn setup(&self) -> Result<(), Error> { Nix::default().setup()?; + let home = env::var("HOME")?; + let nix_path = format!("{}/.nix-profile/bin", home); + let path = format!( + "{}:{}:{}", + nix_path, + "/nix/var/nix/profiles/default/bin", + env::var("PATH")? + ); + let mut child = Command::new("sh") .arg("-c") .arg("type devenv > /dev/null") + .env("PATH", &path) .spawn()?; let status = child.wait()?; @@ -118,18 +129,21 @@ impl Extension for Devenv { Command::new("sh") .arg("-c") .arg("nix profile install --accept-flake-config github:cachix/cachix") + .env("PATH", &path) .spawn()? .wait()?; Command::new("sh") .arg("-c") .arg("cachix use devenv") + .env("PATH", &path) .spawn()? .wait()?; Command::new("sh") .arg("-c") .arg("nix profile install --accept-flake-config github:cachix/devenv/latest") + .env("PATH", &path) .spawn()? .wait()?; diff --git a/crates/ext/src/flox.rs b/crates/ext/src/flox.rs index 7799883..83e1ee1 100644 --- a/crates/ext/src/flox.rs +++ b/crates/ext/src/flox.rs @@ -1,4 +1,5 @@ use std::{ + env, io::{BufRead, BufReader}, process::{Command, ExitStatus, Stdio}, sync::mpsc::{self, Receiver, Sender}, @@ -30,10 +31,20 @@ impl Extension for Flox { let (stdout_tx, stdout_rx): (Sender, Receiver) = mpsc::channel(); let (stderr_tx, stderr_rx): (Sender, Receiver) = mpsc::channel(); + let home = env::var("HOME")?; + let nix_path = format!("{}/.nix-profile/bin", home); + let path = format!( + "{}:{}:{}", + nix_path, + "/nix/var/nix/profiles/default/bin", + env::var("PATH")? + ); + Command::new("bash") .arg("-c") .arg("[ -d .flox ] || flox init") .current_dir(work_dir) + .env("PATH", &path) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .spawn()? @@ -42,6 +53,7 @@ impl Extension for Flox { let mut child = Command::new("bash") .arg("-c") .arg(format!("flox activate -- {}", cmd)) + .env("PATH", &path) .current_dir(work_dir) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -97,9 +109,20 @@ impl Extension for Flox { fn setup(&self) -> Result<(), Error> { Nix::default().setup()?; + + let home = env::var("HOME")?; + let nix_path = format!("{}/.nix-profile/bin", home); + let path = format!( + "{}:{}:{}", + nix_path, + "/nix/var/nix/profiles/default/bin", + env::var("PATH")? + ); + let status = Command::new("sh") .arg("-c") .arg("type flox > /dev/null") + .env("PATH", &path) .spawn()? .wait()?; @@ -121,6 +144,7 @@ impl Extension for Flox { --accept-flake-config \ github:flox/flox", ) + .env("PATH", path) .spawn()? .wait()?; diff --git a/crates/ext/src/nix.rs b/crates/ext/src/nix.rs index db2a731..38b515d 100644 --- a/crates/ext/src/nix.rs +++ b/crates/ext/src/nix.rs @@ -104,14 +104,28 @@ impl Extension for Nix { }; env::set_var("USER", user); + 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 nix_path = format!("{}/.nix-profile/bin", home); + let path = format!( + "{}:{}:{}", + nix_path, + "/nix/var/nix/profiles/default/bin", + env::var("PATH")? + ); + let mut child = Command::new("sh") .arg("-c") .arg("type systemctl > /dev/null") @@ -126,15 +140,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)) + .env("PATH", &path) .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)) + .env("PATH", &path) .spawn()?; child.wait()?; Ok(()) diff --git a/crates/ext/src/pkgx.rs b/crates/ext/src/pkgx.rs index 22fa80f..5bfa8a4 100644 --- a/crates/ext/src/pkgx.rs +++ b/crates/ext/src/pkgx.rs @@ -16,9 +16,16 @@ pub struct Pkgx {} impl Pkgx { pub fn install(&self, pkgs: Vec<&str>) -> Result { self.setup()?; + let path = format!( + "{}:{}", + env::var("PATH")?, + format!("{}/.local/bin", env::var("HOME")?) + ); + let mut child = Command::new("sh") .arg("-c") .arg(format!("pkgx install {}", pkgs.join(" "))) + .env("PATH", &path) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -45,9 +52,16 @@ impl Extension for Pkgx { let (stdout_tx, stdout_rx): (Sender, Receiver) = mpsc::channel(); let (stderr_tx, stderr_rx): (Sender, Receiver) = mpsc::channel(); + let path = format!( + "{}:{}", + env::var("PATH")?, + format!("{}/.local/bin", env::var("HOME")?) + ); + let mut child = Command::new("bash") .arg("-c") .arg(format!("eval \"$(pkgx --shellcode)\" && {}", cmd)) + .env("PATH", &path) .current_dir(work_dir) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -102,17 +116,16 @@ 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") + .env("PATH", &path) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) 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 + } + } + } + } + } +}