~starkingdoms/starkingdoms

ref: 9a16ae19edf42104cf85c5f2570a0c05f1909db1 starkingdoms/spacetime_rs/src/commands/docker.rs -rw-r--r-- 4.2 KiB
9a16ae19 — core make pretty 2 years ago
                                                                                
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use crate::commands::api::build_api_prod;
use crate::commands::client::build_client_prod;
use crate::commands::server::build_server_prod;
use crate::ninja::exec;
use std::error::Error;
use std::path::PathBuf;
use std::process::Command;

fn _build(img: &str, channel: &str, root: &PathBuf) -> Result<(), Box<dyn Error>> {
    // compile the various thingies
    if img == "server" {
        build_server_prod(vec![], root.clone())?;
    } else if img == "api" {
        build_api_prod(vec![], root.clone())?;
    } else {
        build_client_prod(vec![], root.clone())?
    }

    let git_commit_id = String::from_utf8(
        Command::new("git")
            .args(["rev-parse", "--short", "HEAD"])
            .current_dir(root)
            .output()
            .unwrap()
            .stdout,
    )
    .unwrap()
    .replace('\n', "");
    exec(
        "docker",
        root,
        vec![
            "buildx",
            "build",
            "-f",
            root.join(format!("{}.Dockerfile", img)).to_str().unwrap(),
            "-t",
            &format!(
                "registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:{}-{}",
                img, git_commit_id
            ),
            root.to_str().unwrap(),
        ]
        .iter()
        .map(|u| u.to_string())
        .collect(),
    )?;
    exec(
        "docker",
        root,
        vec![
            "buildx",
            "build",
            "-f",
            root.join(format!("{}.Dockerfile", img)).to_str().unwrap(),
            "-t",
            &format!(
                "registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:{}-{}",
                img, channel
            ),
            root.to_str().unwrap(),
        ]
        .iter()
        .map(|u| u.to_string())
        .collect(),
    )?;

    exec(
        "docker",
        root,
        vec![
            "push",
            &format!(
                "registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:{}-{}",
                img, git_commit_id
            ),
        ]
        .iter()
        .map(|u| u.to_string())
        .collect(),
    )?;
    exec(
        "docker",
        root,
        vec![
            "push",
            &format!(
                "registry.gitlab.com/starkingdoms.tk/starkingdoms.tk:{}-{}",
                img, channel
            ),
        ]
        .iter()
        .map(|u| u.to_string())
        .collect(),
    )?;

    Ok(())
}

pub fn build_docker_api(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("api", "bleeding", &root)
}
pub fn build_docker_server(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("server", "bleeding", &root)
}
pub fn build_docker_web(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("web", "bleeding", &root)
}
pub fn build_docker(_a: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    build_docker_api(_a.clone(), root.clone())?;
    build_docker_server(_a.clone(), root.clone())?;
    build_docker_web(_a, root)
}

pub fn build_docker_api_beta(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("api", "beta", &root)
}
pub fn build_docker_server_beta(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("server", "beta", &root)
}
pub fn build_docker_web_beta(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("web", "beta", &root)
}
pub fn build_docker_beta(_a: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    build_docker_api_beta(_a.clone(), root.clone())?;
    build_docker_server_beta(_a.clone(), root.clone())?;
    build_docker_web_beta(_a, root)
}

pub fn build_docker_api_stable(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("api", "stable", &root)
}
pub fn build_docker_server_stable(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("server", "stable", &root)
}
pub fn build_docker_web_stable(_: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    _build("web", "stable", &root)
}
pub fn build_docker_stable(_a: Vec<String>, root: PathBuf) -> Result<(), Box<dyn Error>> {
    build_docker_api_stable(_a.clone(), root.clone())?;
    build_docker_server_stable(_a.clone(), root.clone())?;
    build_docker_web_stable(_a, root)
}