1use bollard::Docker;
2use std::fs;
3
4use super::log_exit;
5use crate::docker::run_image;
6use crate::file::get_jinx_files;
7use crate::file::JinxFiles;
8
9pub async fn run_letsencrypt_container(client: Docker, jinx_files: &JinxFiles, domain: String) {
10 let ports = vec!["80:80/tcp", "443:443/tcp"];
12
13 let conf = format!("{}:/etc/letsencrypt", jinx_files.letsencrypt_conf);
15 let www = format!("{}:/var/www/certbot", jinx_files.letsencrypt_www);
16 let volumes = vec![conf.as_str(), www.as_str()];
17
18 let std_domain = format!("-d {}", domain);
19 let www_domain = format!("-d www.{}", domain);
20
21 let cmds = vec![
22 "certonly",
23 "--register-unsafely-without-email",
24 "--agree-tos",
25 "--standalone",
26 std_domain.as_str(),
27 www_domain.as_str(),
28 ];
29
30 run_image(client, "certbot/certbot", ports, volumes, None, Some(cmds)).await
31}
32
33pub fn write_letsencrypt() {
35 let jinx_files = get_jinx_files();
37
38 match fs::create_dir_all(jinx_files.letsencrypt_conf) {
40 Ok(dir) => dir,
41 Err(err) => log_exit!("[CERT] Failed to create letsencrypt conf directory", err),
42 };
43
44 match fs::create_dir_all(jinx_files.letsencrypt_www) {
46 Ok(dir) => dir,
47 Err(err) => log_exit!("[CERT] Failed to create letsencrypt www directory", err),
48 };
49}