-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathdeploy.rs
More file actions
executable file
·117 lines (96 loc) · 2.99 KB
/
deploy.rs
File metadata and controls
executable file
·117 lines (96 loc) · 2.99 KB
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
#!/usr/bin/env RUST_BACKTRACE=1 cargo +nightly -Zscript
---
package.edition = "2024"
[dependencies]
cli-run = { git = "https://github.com/zibanpirate/cli-rs.git" }
clap = { version = "4", features = ["derive"] }
---
use clap::Parser;
#[derive(Clone, Debug, clap::ValueEnum)]
enum Env {
Stage,
Prod,
}
/// Deploy dzcode to stage or prod
#[derive(Parser, Debug)]
struct Args {
/// Environment to deploy to
#[arg(short, long, value_enum)]
env: Env,
/// Clean build
#[arg(short, long, default_value_t = false)]
clean: bool,
}
fn main() {
let args = Args::parse();
let env = args.env;
println!("Ensuring docker is running ...");
cli_run::cli_run("docker", vec!["ps"]);
if args.clean {
println!("clean...");
cli_run::cli_run("npm", vec!["run", "clean"]);
}
println!("Build...");
cli_run::cli_run("npm", vec!["run", "build"]);
println!("Preparing ./web-server ...");
cli_run::cli_run("npm", vec!["run", "bundle:alone", "--workspace=@dzcode.io/web"]);
cli_run::cli_run("npm", vec!["run", "pre-deploy", "--workspace=@dzcode.io/web"]);
cli_run::cli_run("npm", vec!["run", "prepare-dockerfile", "--workspace=@dzcode.io/web-server"]);
println!("Preparing ./api ...");
cli_run::cli_run("npm", vec!["run", "prepare-dockerfile", "--workspace=@dzcode.io/api"]);
let env_str = format!("{:?}", env).to_lowercase();
println!("Building ./web-server docker image ...");
cli_run::cli_run(
"docker",
vec![
"buildx",
"build",
"-f",
"web-server.Dockerfile",
".",
"-t",
&format!("ghcr.io/dzcode-io/{}-dot-dzcode-dot-io-server:latest", env_str),
],
);
println!("Building ./api docker image ...");
cli_run::cli_run(
"docker",
vec![
"buildx",
"build",
"-f",
"api.Dockerfile",
".",
"-t",
&format!("ghcr.io/dzcode-io/api-dot-{}-dot-dzcode-dot-io-server:latest", env_str),
],
);
println!("Logging in to GitHub Container Registry ...");
let gh_token = std::env::var("DOCKER_REGISTRY_PASSWORD")
.expect("DOCKER_REGISTRY_PASSWORD environment variable not set");
cli_run::cli_run(
"docker",
vec![
"login",
"ghcr.io",
"-u",
"dzcode-io",
"--password",
&gh_token,
],
);
println!("Pushing docker image ...");
cli_run::cli_run(
"docker",
vec!["push", &format!("ghcr.io/dzcode-io/{}-dot-dzcode-dot-io-server:latest", env_str)],
);
cli_run::cli_run(
"docker",
vec!["push", &format!("ghcr.io/dzcode-io/api-dot-{}-dot-dzcode-dot-io-server:latest", env_str)],
);
println!("Deploying to zcluster ...");
cli_run::cli_run(
"zcluster",
vec!["deploy", "-p", &format!("{}-dzcode", env_str), &format!("./docker-compose.{}.yml", env_str)],
);
}