Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #43 from tsirysndr/fix/drivers
Browse files Browse the repository at this point in the history
fix(driver): verify if required command line tools are installed
  • Loading branch information
tsirysndr authored May 14, 2023
2 parents a38580a + 3a51f3c commit 32c1849
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/superviseur/drivers/devenv/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ impl Driver {
}
}

pub fn verify_devenv(&self) -> Result<(), Error> {
std::process::Command::new("sh")
.arg("-c")
.arg("devenv --version")
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.spawn()
.expect("devenv is not installed, see https://devenv.sh/getting-started/");
Ok(())
}

pub fn write_logs(&self, stdout: ChildStdout, stderr: ChildStderr) {
let cloned_service = self.service.clone();
let log_engine = self.log_engine.clone();
Expand Down Expand Up @@ -167,6 +178,7 @@ impl Driver {
#[async_trait]
impl DriverPlugin for Driver {
async fn start(&self, project: String) -> Result<(), Error> {
self.verify_devenv()?;
let mut sp = Spinner::new(Spinners::Line, "Setup devenv ...".into());
let envs = self.service.env.clone();
let mut envs = envs
Expand Down
11 changes: 11 additions & 0 deletions src/superviseur/drivers/docker/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ impl Driver {
}
}

pub fn verify_docker(&self) -> Result<(), anyhow::Error> {
let mut cmd = Command::new("docker");
cmd.arg("--version");
let output = cmd.output()?;
if !output.status.success() {
return Err(anyhow::anyhow!("Docker is not installed on your system"));
}
Ok(())
}

async fn setup_container_network(&self, container_name: &str) -> anyhow::Result<()> {
match &self.config {
Some(cfg) => {
Expand Down Expand Up @@ -332,6 +342,7 @@ impl Driver {
#[async_trait]
impl DriverPlugin for Driver {
async fn start(&self, project: String) -> Result<(), anyhow::Error> {
self.verify_docker()?;
let container_name = format!("{}_{}", project, self.service.name);
let container = self.docker.containers().get(&container_name);
match container.inspect().await {
Expand Down
15 changes: 15 additions & 0 deletions src/superviseur/drivers/nix/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ impl Driver {
}
}

pub fn verify_nix(&self) -> Result<(), Error> {
std::process::Command::new("sh")
.arg("-c")
.arg("nix --version")
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.spawn()
.expect(
"nix is not installed, see https://github.com/DeterminateSystems/nix-installer",
);
Ok(())
}

pub fn write_logs(&self, stdout: ChildStdout, stderr: ChildStderr) {
let cloned_service = self.service.clone();
let log_engine = self.log_engine.clone();
Expand Down Expand Up @@ -146,6 +159,8 @@ impl Driver {
#[async_trait]
impl DriverPlugin for Driver {
async fn start(&self, project: String) -> Result<(), Error> {
self.verify_nix()?;

let command = format!("nix develop --command -- {}", &self.service.command);
println!("command: {}", command);

Expand Down

0 comments on commit 32c1849

Please sign in to comment.