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
use handlebars::Handlebars;
use std::fs;
use std::fs::File;
use std::str;
use super::log_exit;
use crate::conf::JinxConf;
use crate::file::get_jinx_files;
fn get_nginx_template() -> &'static str {
let nginx_bytes = include_bytes!("./templates/nginx.hbs");
let nginx_template = str::from_utf8(nginx_bytes).expect("[NGINX] Failed to convert template");
nginx_template
}
pub fn render_template(jinx_conf: &JinxConf) -> String {
let handlebars = Handlebars::new();
let nginx_template = get_nginx_template();
let rendered_nginx = handlebars
.render_template(nginx_template, &jinx_conf)
.expect("[NGINX] Failed to render template");
rendered_nginx
}
pub fn write_nginx_conf(jinx_conf: &JinxConf) {
let handlebars = Handlebars::new();
let nginx_template = get_nginx_template();
let jinx_files = get_jinx_files();
let output_file = match File::create(jinx_files.nginx_conf) {
Err(err) => log_exit!("[NGINX] Failed to create nginx_conf", err),
Ok(file) => file,
};
handlebars
.render_template_to_write(&nginx_template, &jinx_conf, output_file)
.expect("[NGINX] Failed to write nginx_conf");
}
pub fn write_nginx_dockerfile() {
let jinx_files = get_jinx_files();
let dockerfile_bytes = include_bytes!("./templates/Dockerfile");
fs::write(
&format!("{}/Dockerfile", jinx_files.jinx_home),
&dockerfile_bytes,
)
.expect("[CONF] Failed to write jinx Dockerfile");
}