Skip to content

Commit 927db93

Browse files
committed
added script and config files to deploy to zcluster
1 parent f26ff65 commit 927db93

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# --platform linux/amd64,linux/arm64
2+
FROM --platform=linux/amd64 nginx:latest
3+
4+
# Copy the custom Nginx configuration
5+
COPY ./custom.conf /etc/nginx/conf.d/default.conf
6+
7+
# Copy the static website files
8+
COPY ./web/bundle /usr/share/nginx/html

custom.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
# Explicitly handle 404s by serving the index.html
6+
error_page 404 =200 /index.html;
7+
8+
location / {
9+
root /usr/share/nginx/html;
10+
index index.html index.htm;
11+
try_files $uri $uri/ /index.html;
12+
}
13+
}

docker-compose.stage.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
web:
3+
image: ghcr.io/dzcode-io/stage-dot-dzcode-dot-io-server:latest
4+
pull_policy: always
5+
restart: unless-stopped
6+
environment:
7+
- VIRTUAL_HOST=stage.dzcode.io
8+
- LETSENCRYPT_HOST=stage.dzcode.io
9+
networks:
10+
- main-infra-network
11+
12+
networks:
13+
main-infra-network:
14+
external: true

scripts/deploy.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env RUST_BACKTRACE=1 cargo +nightly -Zscript
2+
3+
---
4+
package.edition = "2024"
5+
6+
[dependencies]
7+
cli-run = { git = "https://github.com/zibanpirate/cli-rs.git" }
8+
clap = { version = "4", features = ["derive"] }
9+
---
10+
11+
use clap::Parser;
12+
13+
#[derive(Clone, Debug, clap::ValueEnum)]
14+
enum Env {
15+
Stage,
16+
Prod,
17+
}
18+
19+
/// Deploy dzcode to stage or prod
20+
#[derive(Parser, Debug)]
21+
struct Args {
22+
/// Environment to deploy to
23+
#[arg(short, long, value_enum)]
24+
env: Env,
25+
}
26+
27+
fn main() {
28+
29+
let args = Args::parse();
30+
let env = args.env;
31+
32+
println!("Ensuring docker is running ...");
33+
cli_run::cli_run("docker", vec!["ps"]);
34+
35+
println!("Building ./web ...");
36+
cli_run::cli_run("npm", vec!["run", "pre-deploy", "[email protected]/web"]);
37+
38+
println!("Building docker image ...");
39+
let env_str = format!("{:?}", env).to_lowercase();
40+
cli_run::cli_run(
41+
"docker",
42+
vec![
43+
"build",
44+
".",
45+
"-t",
46+
&format!("ghcr.io/dzcode-io/{}-dot-dzcode-dot-io-server:latest", env_str),
47+
],
48+
);
49+
50+
println!("Logging in to GitHub Container Registry ...");
51+
let gh_token = std::env::var("DOCKER_REGISTRY_PASSWORD")
52+
.expect("DOCKER_REGISTRY_PASSWORD environment variable not set");
53+
cli_run::cli_run(
54+
"docker",
55+
vec![
56+
"login",
57+
"ghcr.io",
58+
"-u",
59+
"dzcode-io",
60+
"--password",
61+
&gh_token,
62+
],
63+
);
64+
65+
println!("Pushing docker image ...");
66+
cli_run::cli_run(
67+
"docker",
68+
vec!["push", &format!("ghcr.io/dzcode-io/{}-dot-dzcode-dot-io-server:latest", env_str)],
69+
);
70+
71+
println!("Deploying to zcluster ...");
72+
cli_run::cli_run(
73+
"zcluster",
74+
vec!["deploy", "-p", &format!("{}-dzcode", env_str), &format!("./docker-compose.{}.yml", env_str)],
75+
);
76+
}

0 commit comments

Comments
 (0)