kamal 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kamal/cli/accessory.rb +27 -22
- data/lib/kamal/cli/app/boot.rb +70 -18
- data/lib/kamal/cli/app/prepare_assets.rb +1 -1
- data/lib/kamal/cli/app.rb +57 -47
- data/lib/kamal/cli/base.rb +26 -28
- data/lib/kamal/cli/build/clone.rb +61 -0
- data/lib/kamal/cli/build.rb +58 -50
- data/lib/kamal/cli/env.rb +5 -5
- data/lib/kamal/cli/healthcheck/barrier.rb +31 -0
- data/lib/kamal/cli/healthcheck/error.rb +2 -0
- data/lib/kamal/cli/healthcheck/poller.rb +4 -5
- data/lib/kamal/cli/main.rb +36 -43
- data/lib/kamal/cli/prune.rb +3 -3
- data/lib/kamal/cli/server.rb +39 -15
- data/lib/kamal/cli/traefik.rb +8 -8
- data/lib/kamal/commander/specifics.rb +1 -1
- data/lib/kamal/commander.rb +6 -6
- data/lib/kamal/commands/app/containers.rb +8 -0
- data/lib/kamal/commands/app/execution.rb +3 -3
- data/lib/kamal/commands/app/logging.rb +2 -2
- data/lib/kamal/commands/app.rb +6 -5
- data/lib/kamal/commands/base.rb +2 -3
- data/lib/kamal/commands/builder/base.rb +6 -12
- data/lib/kamal/commands/builder/clone.rb +28 -0
- data/lib/kamal/commands/builder/multiarch.rb +9 -9
- data/lib/kamal/commands/builder/native/cached.rb +6 -7
- data/lib/kamal/commands/builder/native/remote.rb +9 -9
- data/lib/kamal/commands/builder/native.rb +6 -7
- data/lib/kamal/commands/builder.rb +2 -0
- data/lib/kamal/configuration/builder.rb +33 -2
- data/lib/kamal/configuration/env/tag.rb +12 -0
- data/lib/kamal/configuration/env.rb +1 -1
- data/lib/kamal/configuration/role.rb +29 -6
- data/lib/kamal/configuration.rb +14 -2
- data/lib/kamal/git.rb +4 -0
- data/lib/kamal/sshkit_with_ext.rb +36 -0
- data/lib/kamal/version.rb +1 -1
- metadata +18 -10
- data/lib/kamal/cli/healthcheck.rb +0 -21
- data/lib/kamal/commands/app.rb.orig +0 -127
- data/lib/kamal/commands/healthcheck.rb +0 -59
@@ -1,127 +0,0 @@
|
|
1
|
-
class Kamal::Commands::App < Kamal::Commands::Base
|
2
|
-
include Assets, Containers, Cord, Execution, Images, Logging
|
3
|
-
|
4
|
-
ACTIVE_DOCKER_STATUSES = [ :running, :restarting ]
|
5
|
-
|
6
|
-
attr_reader :role
|
7
|
-
|
8
|
-
def initialize(config, role: nil)
|
9
|
-
super(config)
|
10
|
-
@role = role
|
11
|
-
end
|
12
|
-
|
13
|
-
def run(hostname: nil)
|
14
|
-
docker :run,
|
15
|
-
"--detach",
|
16
|
-
"--restart unless-stopped",
|
17
|
-
"--name", container_name,
|
18
|
-
*([ "--hostname", hostname ] if hostname),
|
19
|
-
"-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
|
20
|
-
"-e", "KAMAL_VERSION=\"#{config.version}\"",
|
21
|
-
*role.env_args,
|
22
|
-
*role.health_check_args,
|
23
|
-
*role.logging_args,
|
24
|
-
*config.volume_args,
|
25
|
-
*role.asset_volume_args,
|
26
|
-
*role.label_args,
|
27
|
-
*role.option_args,
|
28
|
-
config.absolute_image,
|
29
|
-
role.cmd
|
30
|
-
end
|
31
|
-
|
32
|
-
def start
|
33
|
-
docker :start, container_name
|
34
|
-
end
|
35
|
-
|
36
|
-
def status(version:)
|
37
|
-
pipe container_id_for_version(version), xargs(docker(:inspect, "--format", DOCKER_HEALTH_STATUS_FORMAT))
|
38
|
-
end
|
39
|
-
|
40
|
-
def stop(version: nil)
|
41
|
-
pipe \
|
42
|
-
version ? container_id_for_version(version) : current_running_container_id,
|
43
|
-
xargs(config.stop_wait_time ? docker(:stop, "-t", config.stop_wait_time) : docker(:stop))
|
44
|
-
end
|
45
|
-
|
46
|
-
def info
|
47
|
-
docker :ps, *filter_args
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
def current_running_container_id
|
52
|
-
current_running_container(format: "--quiet")
|
53
|
-
end
|
54
|
-
|
55
|
-
def container_id_for_version(version, only_running: false)
|
56
|
-
container_id_for(container_name: container_name(version), only_running: only_running)
|
57
|
-
end
|
58
|
-
|
59
|
-
<<<<<<< HEAD
|
60
|
-
def current_running_version
|
61
|
-
pipe \
|
62
|
-
current_running_container(format: "--format '{{.Names}}'"),
|
63
|
-
extract_version_from_name
|
64
|
-
=======
|
65
|
-
def current_running_version(prefix: nil)
|
66
|
-
list_versions("--latest", statuses: ACTIVE_DOCKER_STATUSES)
|
67
|
-
>>>>>>> 4dc8aca (Rename roles)
|
68
|
-
end
|
69
|
-
|
70
|
-
def list_versions(*docker_args, statuses: nil)
|
71
|
-
pipe \
|
72
|
-
docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
|
73
|
-
extract_version_from_name
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
def make_env_directory
|
78
|
-
make_directory role.env.secrets_directory
|
79
|
-
end
|
80
|
-
|
81
|
-
def remove_env_file
|
82
|
-
[ :rm, "-f", role.env.secrets_file ]
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
private
|
87
|
-
def container_name(version = nil)
|
88
|
-
[ role.container_prefix, version || config.version ].compact.join("-")
|
89
|
-
end
|
90
|
-
|
91
|
-
def latest_image_id
|
92
|
-
docker :image, :ls, *argumentize("--filter", "reference=#{config.latest_image}"), "--format", "'{{.ID}}'"
|
93
|
-
end
|
94
|
-
|
95
|
-
def current_running_container(format:)
|
96
|
-
pipe \
|
97
|
-
shell(chain(latest_image_container(format: format), latest_container(format: format))),
|
98
|
-
[ :head, "-1" ]
|
99
|
-
end
|
100
|
-
|
101
|
-
def latest_image_container(format:)
|
102
|
-
latest_container format: format, filters: [ "ancestor=$(#{latest_image_id.join(" ")})" ]
|
103
|
-
end
|
104
|
-
|
105
|
-
def latest_container(format:, filters: nil)
|
106
|
-
docker :ps, "--latest", *format, *filter_args(statuses: ACTIVE_DOCKER_STATUSES), argumentize("--filter", filters)
|
107
|
-
end
|
108
|
-
|
109
|
-
def filter_args(statuses: nil)
|
110
|
-
argumentize "--filter", filters(statuses: statuses)
|
111
|
-
end
|
112
|
-
|
113
|
-
def extract_version_from_name
|
114
|
-
# Extract SHA from "service-role-dest-SHA"
|
115
|
-
%(while read line; do echo ${line##{role.container_prefix}-}; done)
|
116
|
-
end
|
117
|
-
|
118
|
-
def filters(statuses: nil)
|
119
|
-
[ "label=service=#{config.service}" ].tap do |filters|
|
120
|
-
filters << "label=destination=#{config.destination}" if config.destination
|
121
|
-
filters << "label=role=#{role}" if role
|
122
|
-
statuses&.each do |status|
|
123
|
-
filters << "status=#{status}"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
class Kamal::Commands::Healthcheck < Kamal::Commands::Base
|
2
|
-
def run
|
3
|
-
primary = config.role(config.primary_role)
|
4
|
-
|
5
|
-
docker :run,
|
6
|
-
"--detach",
|
7
|
-
"--name", container_name_with_version,
|
8
|
-
"--publish", "#{exposed_port}:#{config.healthcheck["port"]}",
|
9
|
-
"--label", "service=#{config.healthcheck_service}",
|
10
|
-
"-e", "KAMAL_CONTAINER_NAME=\"#{config.healthcheck_service}\"",
|
11
|
-
*primary.env_args,
|
12
|
-
*primary.health_check_args(cord: false),
|
13
|
-
*config.volume_args,
|
14
|
-
*primary.option_args,
|
15
|
-
config.absolute_image,
|
16
|
-
primary.cmd
|
17
|
-
end
|
18
|
-
|
19
|
-
def status
|
20
|
-
pipe container_id, xargs(docker(:inspect, "--format", DOCKER_HEALTH_STATUS_FORMAT))
|
21
|
-
end
|
22
|
-
|
23
|
-
def container_health_log
|
24
|
-
pipe container_id, xargs(docker(:inspect, "--format", DOCKER_HEALTH_LOG_FORMAT))
|
25
|
-
end
|
26
|
-
|
27
|
-
def logs
|
28
|
-
pipe container_id, xargs(docker(:logs, "--tail", log_lines, "2>&1"))
|
29
|
-
end
|
30
|
-
|
31
|
-
def stop
|
32
|
-
pipe container_id, xargs(docker(:stop))
|
33
|
-
end
|
34
|
-
|
35
|
-
def remove
|
36
|
-
pipe container_id, xargs(docker(:container, :rm))
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def container_name_with_version
|
41
|
-
"#{config.healthcheck_service}-#{config.version}"
|
42
|
-
end
|
43
|
-
|
44
|
-
def container_id
|
45
|
-
container_id_for(container_name: container_name_with_version)
|
46
|
-
end
|
47
|
-
|
48
|
-
def health_url
|
49
|
-
"http://localhost:#{exposed_port}#{config.healthcheck["path"]}"
|
50
|
-
end
|
51
|
-
|
52
|
-
def exposed_port
|
53
|
-
config.healthcheck["exposed_port"]
|
54
|
-
end
|
55
|
-
|
56
|
-
def log_lines
|
57
|
-
config.healthcheck["log_lines"]
|
58
|
-
end
|
59
|
-
end
|