Skip to content

Commit

Permalink
ci: install curl
Browse files Browse the repository at this point in the history
add nix to PATH

add nix to PATH

add nix to PATH

add pkgx to PATH

fix e2e tests

ci: fix workdir

update exts
  • Loading branch information
tsirysndr committed Mar 16, 2024
1 parent 70aa135 commit face027
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 27 deletions.
33 changes: 21 additions & 12 deletions .fluentci/src/dagger/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions crates/ext/src/devbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
1 change: 1 addition & 0 deletions crates/ext/src/devenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions crates/ext/src/flox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 15 additions & 4 deletions crates/ext/src/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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(())
Expand Down
23 changes: 14 additions & 9 deletions crates/ext/src/pkgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Pkgx {}
impl Pkgx {
pub fn install(&self, pkgs: Vec<&str>) -> Result<ExitStatus, Error> {
self.setup()?;

let mut child = Command::new("sh")
.arg("-c")
.arg(format!("pkgx install {}", pkgs.join(" ")))
Expand Down Expand Up @@ -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),
}
}
});

Expand All @@ -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),
}
}
});

Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions fixtures/flox.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions fixtures/pkgx.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query Pkgx {
pipeline(name: "Demo") {
pkgx {
withWorkDir(path: "./pkgx-demo") {
withExec(args: ["pkgx", "--version"]) {
withExec(args: ["which", "deno"]) {
id
stdout
}
}
}
}
}
}

0 comments on commit face027

Please sign in to comment.