1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use crate::buildsystem::BuildSystem;
use crate::{Cmd, File, MasterConfig, Worker, AUTH_TOKEN_PATH};

/// This struct is identical to the Bash buildsystem,
/// except that it does not confirm anything with the user at all.
/// This is meant to be used by scripts that automate the usage of rusty-ci.
#[derive(Default)]
pub struct Quiet;

impl BuildSystem for Quiet {
    /// Rebuild master without killing any running processes
    fn rebuild(&mut self, master: MasterConfig) -> Result<(), String> {
        self.prebuild()?; // Call the prebuild method

        info!("Creating master...");
        self.create_master()?;

        let workers = master.get_workers();
        info!("Creating workers...");
        self.create_workers(&workers)?;
        info!("Writing to master/master.cfg...");
        self.write_master_config(&master)?;
        info!("Writing to worker configs...");
        self.write_worker_configs(&workers)?;
        info!("Reconfiguring master...");
        self.reconfigure_master()?;
        Ok(())
    }

    /// Writes install script to `install.sh` for user to run
    fn install(&mut self) -> Result<(), String> {
        info!("Writing install file to `./install.sh`");
        File::write(
            "install.sh",
            "#!/bin/sh

python3 -m venv venv 2>&1
. venv/bin/activate

python3 -m pip install -U pip >/dev/null
python3 -m pip install txrequests treq 'buildbot[bundle]' >/dev/null
python3 -m pip install buildbot-worker setuptools-trial >/dev/null
",
        )?;
        info!("Successfully wrote install file");
        warn!("To install dependencies run `install.sh`");
        warn!("Before building from a YAML file, be sure to run `. venv/bin/activate`");
        info!(
            "Next, write your VCS's api token to '{}', and then run the `build` subcommand",
            AUTH_TOKEN_PATH
        );
        Ok(())
    }

    fn build(&mut self, master: MasterConfig) -> Result<(), String> {
        self.prebuild()?; // Call the prebuild method

        info!("Creating master...");
        self.create_master()?;

        let workers = master.get_workers();
        info!("Creating workers...");
        self.create_workers(&workers)?;
        info!("Writing to master/master.cfg...");
        self.write_master_config(&master)?;
        info!("Writing to worker configs...");
        self.write_worker_configs(&workers)?;
        info!("Next, run the `start` subcommand to execute the master and the workers");
        Ok(())
    }

    /// This kills the buildbot workers and all instances of python and python3
    fn stop(&mut self) -> Result<(), String> {
        info!("Killing python...");
        Cmd::new("killall").arg("python").run();
        info!("Killing python3...");
        Cmd::new("killall").arg("python3").run();
        info!("Killing workers...");
        Cmd::new("killall").arg("buildbot-worker").run();
        Ok(())
    }

    /// This starts the master and the workers
    fn start(&mut self, workers: &[Worker]) -> Result<(), String> {
        info!("Starting workers and masters...");
        self.start_master()?;
        self.start_workers(workers)?;
        Ok(())
    }

    fn install_python(&mut self) -> Result<(), String> {
        Ok(())
    }
    fn install_buildbot(&mut self) -> Result<(), String> {
        Ok(())
    }
}