@@ -13,9 +13,10 @@ def boot
13
13
14
14
version = capture_with_info ( *KAMAL . proxy . version ) . strip . presence
15
15
16
- if version && Kamal ::Utils . older_version? ( version , Kamal ::Configuration ::PROXY_MINIMUM_VERSION )
17
- raise "kamal-proxy version #{ version } is too old, run `kamal proxy reboot` in order to update to at least #{ Kamal ::Configuration ::PROXY_MINIMUM_VERSION } "
16
+ if version && Kamal ::Utils . older_version? ( version , Kamal ::Configuration ::Proxy :: Boot :: MINIMUM_VERSION )
17
+ raise "kamal-proxy version #{ version } is too old, run `kamal proxy reboot` in order to update to at least #{ Kamal ::Configuration ::Proxy :: Boot :: MINIMUM_VERSION } "
18
18
end
19
+ execute *KAMAL . proxy . ensure_apps_config_directory
19
20
execute *KAMAL . proxy . start_or_run
20
21
end
21
22
end
@@ -24,49 +25,63 @@ def boot
24
25
desc "boot_config <set|get|reset>" , "Manage kamal-proxy boot configuration"
25
26
option :publish , type : :boolean , default : true , desc : "Publish the proxy ports on the host"
26
27
option :publish_host_ip , type : :string , repeatable : true , default : nil , desc : "Host IP address to bind HTTP/HTTPS traffic to. Defaults to all interfaces"
27
- option :http_port , type : :numeric , default : Kamal ::Configuration ::PROXY_HTTP_PORT , desc : "HTTP port to publish on the host"
28
- option :https_port , type : :numeric , default : Kamal ::Configuration ::PROXY_HTTPS_PORT , desc : "HTTPS port to publish on the host"
29
- option :log_max_size , type : :string , default : Kamal ::Configuration ::PROXY_LOG_MAX_SIZE , desc : "Max size of proxy logs"
28
+ option :http_port , type : :numeric , default : Kamal ::Configuration ::Proxy :: Boot :: DEFAULT_HTTP_PORT , desc : "HTTP port to publish on the host"
29
+ option :https_port , type : :numeric , default : Kamal ::Configuration ::Proxy :: Boot :: DEFAULT_HTTPS_PORT , desc : "HTTPS port to publish on the host"
30
+ option :log_max_size , type : :string , default : Kamal ::Configuration ::Proxy :: Boot :: DEFAULT_LOG_MAX_SIZE , desc : "Max size of proxy logs"
30
31
option :registry , type : :string , default : nil , desc : "Registry to use for the proxy image"
31
32
option :repository , type : :string , default : nil , desc : "Repository for the proxy image"
32
33
option :image_version , type : :string , default : nil , desc : "Version of the proxy to run"
34
+ option :metrics_port , type : :numeric , default : nil , desc : "Port to report prometheus metrics on"
35
+ option :debug , type : :boolean , default : false , desc : "Whether to run the proxy in debug mode"
33
36
option :docker_options , type : :array , default : [ ] , desc : "Docker options to pass to the proxy container" , banner : "option=value option2=value2"
34
37
def boot_config ( subcommand )
38
+ proxy_boot_config = KAMAL . config . proxy_boot
39
+
35
40
case subcommand
36
41
when "set"
37
42
boot_options = [
38
- *( KAMAL . config . proxy_publish_args ( options [ :http_port ] , options [ :https_port ] , options [ :publish_host_ip ] ) if options [ :publish ] ) ,
39
- *( KAMAL . config . proxy_logging_args ( options [ :log_max_size ] ) ) ,
43
+ *( proxy_boot_config . publish_args ( options [ :http_port ] , options [ :https_port ] , options [ :publish_host_ip ] ) if options [ :publish ] ) ,
44
+ *( proxy_boot_config . logging_args ( options [ :log_max_size ] ) ) ,
45
+ *( "--expose=#{ options [ :metrics_port ] } " if options [ :metrics_port ] ) ,
40
46
*options [ :docker_options ] . map { |option | "--#{ option } " }
41
47
]
42
48
43
49
image = [
44
50
options [ :registry ] . presence ,
45
- options [ :repository ] . presence || KAMAL . config . proxy_repository_name ,
46
- KAMAL . config . proxy_image_name
51
+ options [ :repository ] . presence || proxy_boot_config . repository_name ,
52
+ proxy_boot_config . image_name
47
53
] . compact . join ( "/" )
48
54
49
55
image_version = options [ :image_version ]
50
56
57
+ run_command_options = { debug : options [ :debug ] || nil , "metrics-port" : options [ :metrics_port ] } . compact
58
+ run_command = "kamal-proxy run #{ Kamal ::Utils . optionize ( run_command_options ) . join ( " " ) } " if run_command_options . any?
59
+
51
60
on ( KAMAL . proxy_hosts ) do |host |
52
61
execute ( *KAMAL . proxy . ensure_proxy_directory )
53
- if boot_options != KAMAL . config . proxy_default_boot_options
54
- upload! StringIO . new ( boot_options . join ( " " ) ) , KAMAL . config . proxy_options_file
62
+ if boot_options != proxy_boot_config . default_boot_options
63
+ upload! StringIO . new ( boot_options . join ( " " ) ) , proxy_boot_config . options_file
55
64
else
56
65
execute *KAMAL . proxy . reset_boot_options , raise_on_non_zero_exit : false
57
66
end
58
67
59
- if image != KAMAL . config . proxy_image_default
60
- upload! StringIO . new ( image ) , KAMAL . config . proxy_image_file
68
+ if image != proxy_boot_config . image_default
69
+ upload! StringIO . new ( image ) , proxy_boot_config . image_file
61
70
else
62
71
execute *KAMAL . proxy . reset_image , raise_on_non_zero_exit : false
63
72
end
64
73
65
74
if image_version
66
- upload! StringIO . new ( image_version ) , KAMAL . config . proxy_image_version_file
75
+ upload! StringIO . new ( image_version ) , proxy_boot_config . image_version_file
67
76
else
68
77
execute *KAMAL . proxy . reset_image_version , raise_on_non_zero_exit : false
69
78
end
79
+
80
+ if run_command
81
+ upload! StringIO . new ( run_command ) , proxy_boot_config . run_command_file
82
+ else
83
+ execute *KAMAL . proxy . reset_run_command , raise_on_non_zero_exit : false
84
+ end
70
85
end
71
86
when "get"
72
87
@@ -78,6 +93,7 @@ def boot_config(subcommand)
78
93
execute *KAMAL . proxy . reset_boot_options , raise_on_non_zero_exit : false
79
94
execute *KAMAL . proxy . reset_image , raise_on_non_zero_exit : false
80
95
execute *KAMAL . proxy . reset_image_version , raise_on_non_zero_exit : false
96
+ execute *KAMAL . proxy . reset_run_command , raise_on_non_zero_exit : false
81
97
end
82
98
else
83
99
raise ArgumentError , "Unknown boot_config subcommand #{ subcommand } "
@@ -101,6 +117,7 @@ def reboot
101
117
"Stopping and removing kamal-proxy on #{ host } , if running..."
102
118
execute *KAMAL . proxy . stop , raise_on_non_zero_exit : false
103
119
execute *KAMAL . proxy . remove_container
120
+ execute *KAMAL . proxy . ensure_apps_config_directory
104
121
105
122
execute *KAMAL . proxy . run
106
123
0 commit comments