-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build_machine.rs
121 lines (109 loc) · 4.67 KB
/
build_machine.rs
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use crate::fs::temp::TempFs;
use crate::launchers::docker;
use crate::INCLUDE_FRONTEND;
use std::env;
use std::process::Command;
#[derive(Debug, Default)]
pub(crate) struct Build {}
impl Build {
/// run docker build command with system or npm install for the sidecar.
pub(crate) fn process(local: &bool, standalone: &bool) {
let mut file_manager = TempFs::new();
let frontend: bool = match env::var(INCLUDE_FRONTEND) {
Ok(val) => val == "true",
Err(_) => false,
};
if *local {
Command::new("npm")
.args(["i", "@a11ywatch/a11ywatch", "-g"])
.status()
.expect("Failed to execute command - npm install @a11ywatch/a11ywatch command");
// pin cross-platform kill-port for security, possible alternatives to simply pipe windows cmd commands
Command::new("npm")
.args(["i", "kill-port@2.0.1", "-g"])
.status()
.expect("Failed to execute command - npm install kill-port command");
let web_folder_tmp = format!("{}/web_tmp", file_manager.get_temp_dir());
let web_folder = format!("{}/web", file_manager.get_temp_dir());
if frontend {
// install the codebase via npm for versioning ability
Command::new("npm")
.args(["i", "--prefix", &web_folder_tmp, "@a11ywatch/web"])
.status()
.expect("Failed to execute npm i command inside @a11ywatch/web!");
if cfg!(windows) {
Command::new("copy")
.args([
&format!("{}/{}", &web_folder_tmp, "node_modules/@a11ywatch/web/"),
&web_folder,
])
.status()
.expect("Failed to execute copy command!");
Command::new("rmdir")
.args(["-s", &format!("{}", &web_folder_tmp)])
.status()
.expect("Failed to execute rmdir command!");
} else if cfg!(unix) {
Command::new("cp")
.args([
"-R",
&format!("{}/{}", &web_folder_tmp, "node_modules/@a11ywatch/web/"),
&web_folder,
])
.status()
.expect("Failed to execute cp command!");
Command::new("rm")
.args(["-R", &format!("{}", &web_folder_tmp)])
.status()
.expect("Failed to execute rm command!");
};
// force install @types/react issues apollo deprecated version. All other modules should be pinned for security.
Command::new("npm")
.args([
"--prefix",
&format!("{}/", &web_folder),
"install",
"./",
"--force",
])
.status()
.expect("Failed to execute @a11ywatch/web i command!");
Command::new("npm")
.args(["run", "build", "--prefix", &web_folder])
.status()
.expect("Failed to execute @a11ywatch/web build command!");
}
} else {
file_manager.create_env_file().unwrap();
file_manager
.create_compose_backend_file(standalone)
.unwrap();
if frontend {
file_manager.create_compose_frontend_file().unwrap();
}
docker::build_backend(&file_manager);
}
}
/// run docker build backend to upgrade images or re-install the sidecar@latest.
pub(crate) fn upgrade(local: &bool, standalone: &bool) {
let mut file_manager = TempFs::new();
if *local {
Command::new("npm")
.args(["i", "@a11ywatch/a11ywatch", "-g"])
.status()
.expect("Failed to execute command - npm install @a11ywatch/a11ywatch command");
} else {
let frontend: bool = match env::var(INCLUDE_FRONTEND) {
Ok(val) => val == "true",
Err(_) => false,
};
file_manager
.create_compose_backend_file(standalone)
.unwrap();
if frontend {
file_manager.create_compose_frontend_file().unwrap();
}
docker::upgrade(&file_manager);
}
}
}