Repository navigation
Expand file tree
/
Copy pathdeploy.lua
More file actions
executable file
·79 lines (68 loc) · 2.76 KB
/
Copy pathdeploy.lua
File metadata and controls
executable file
·79 lines (68 loc) · 2.76 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
#!/usr/bin/env luajit
---@type (string?)[]
local args = arg
require("pkg_config")
local Deployment = require("deploy.Deployment")
local Shell = require("rizu.build.Shell")
local function usage()
print([[Usage:
./deploy.lua build-deploy <commit>
./deploy.lua deploy <commit|release-directory>
./deploy.lua rollback [commit]
./deploy.lua status
Environment:
RIZU_DEPLOY_ROOT Deployment root (default: repository root)
RIZU_ARTIFACT_ROOT Release artifact root (default: build/release)
RIZU_COMPOSE_FILE Compose file (default: compose.yaml)
RIZU_COMPOSE Compose command (default: docker compose)
RIZU_HEALTH_ATTEMPTS Health polling attempts (default: 30)
RIZU_HEALTH_INTERVAL Seconds between health checks (default: 2)
RIZU_DEPLOY_TEST_COMMAND VDS test command (default: ./test)
RIZU_DEPLOY_AUTO_ROLLBACK Restore previous app on failure: 0 or 1 (default: 1)]])
end
local function positiveInteger(name, default)
local value = tonumber(os.getenv(name) or default)
assert(value and value >= 1 and value % 1 == 0, name .. " must be a positive integer")
return value
end
---@param name string
---@param default string
---@return boolean
local function environmentFlag(name, default)
local value = os.getenv(name) or default
assert(value == "0" or value == "1", name .. " must be 0 or 1")
return value == "1"
end
local command = args[1]
if command ~= "build-deploy" and command ~= "deploy" and command ~= "rollback" and command ~= "status" then
usage()
os.exit(command == "help" or command == "--help" and 0 or 2)
end
if (command == "build-deploy" or command == "deploy") and not args[2] then
usage()
os.exit(2)
end
local deployment = Deployment(Shell(), {
root = os.getenv("RIZU_DEPLOY_ROOT") or ".",
artifact_root = os.getenv("RIZU_ARTIFACT_ROOT") or "build/release",
compose_file = os.getenv("RIZU_COMPOSE_FILE") or "compose.yaml",
compose_command = os.getenv("RIZU_COMPOSE") or "docker compose",
health_attempts = positiveInteger("RIZU_HEALTH_ATTEMPTS", "30"),
health_interval = positiveInteger("RIZU_HEALTH_INTERVAL", "2"),
auto_rollback = environmentFlag("RIZU_DEPLOY_AUTO_ROLLBACK", "1"),
})
deployment.config.root = deployment:absolute(deployment.config.root)
deployment.config.artifact_root = deployment:absolute(deployment.config.artifact_root)
deployment.config.compose_file = deployment:absolute(deployment.config.compose_file)
local mutating = command == "build-deploy" or command == "deploy" or command == "rollback"
if mutating and os.getenv("RIZU_DEPLOY_LOCKED") ~= "1" then
deployment:runLocked(command, args[2])
elseif command == "build-deploy" then
deployment:buildDeploy(args[2])
elseif command == "deploy" then
deployment:deploy(args[2])
elseif command == "rollback" then
deployment:rollback(args[2])
else
deployment:status()
end