@@ -249,8 +249,16 @@ def env_tag(name)
249
249
env_tags . detect { |t | t . name == name . to_s }
250
250
end
251
251
252
- def proxy_publish_args ( http_port , https_port )
253
- argumentize "--publish" , [ "#{ http_port } :#{ PROXY_HTTP_PORT } " , "#{ https_port } :#{ PROXY_HTTPS_PORT } " ]
252
+ def proxy_publish_args ( http_port , https_port , bind_ips = nil )
253
+ ensure_valid_bind_ips ( bind_ips )
254
+
255
+ ( bind_ips || [ nil ] ) . map do |bind_ip |
256
+ bind_ip = format_bind_ip ( bind_ip )
257
+ publish_http = [ bind_ip , http_port , PROXY_HTTP_PORT ] . compact . join ( ":" )
258
+ publish_https = [ bind_ip , https_port , PROXY_HTTPS_PORT ] . compact . join ( ":" )
259
+
260
+ argumentize "--publish" , [ publish_http , publish_https ]
261
+ end . join ( " " )
254
262
end
255
263
256
264
def proxy_logging_args ( max_size )
@@ -344,6 +352,15 @@ def ensure_valid_kamal_version
344
352
true
345
353
end
346
354
355
+ def ensure_valid_bind_ips ( bind_ips )
356
+ bind_ips . present? && bind_ips . each do |ip |
357
+ next if ip =~ Resolv ::IPv4 ::Regex || ip =~ Resolv ::IPv6 ::Regex
358
+ raise ArgumentError , "Invalid publish IP address: #{ ip } "
359
+ end
360
+
361
+ true
362
+ end
363
+
347
364
def ensure_retain_containers_valid
348
365
raise Kamal ::ConfigurationError , "Must retain at least 1 container" if retain_containers < 1
349
366
@@ -375,6 +392,15 @@ def ensure_unique_hosts_for_ssl_roles
375
392
true
376
393
end
377
394
395
+ def format_bind_ip ( ip )
396
+ # Ensure IPv6 address inside square brackets - e.g. [::1]
397
+ if ip =~ Resolv ::IPv6 ::Regex && ip !~ /\[ .*\] /
398
+ "[#{ ip } ]"
399
+ else
400
+ ip
401
+ end
402
+ end
403
+
378
404
def role_names
379
405
raw_config . servers . is_a? ( Array ) ? [ "web" ] : raw_config . servers . keys . sort
380
406
end
0 commit comments