Skip to content

Commit

Permalink
Added tests for accessory configuration with proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-alexandrov committed Sep 26, 2024
1 parent 3030405 commit 2c6010d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/kamal/cli/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def stop(name)
on(hosts) do
execute *KAMAL.auditor.record("Stopped #{name} accessory"), verbosity: :debug
execute *accessory.stop, raise_on_non_zero_exit: false
# execute *accessory.remove if accessory.running_proxy?
execute *accessory.remove if accessory.running_proxy?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/configuration/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(name, config:)
secrets: config.secrets,
context: "accessories/#{name}/env"

# initialize_proxy if running_proxy?
initialize_proxy if running_proxy?
end

def service_name
Expand Down
85 changes: 85 additions & 0 deletions lib/kamal/configuration/docs/accessory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,88 @@ accessories:
# They are not created or copied before mounting
volumes:
- /path/to/mysql-logs:/var/log/mysql

# Proxy
#
proxy:
# Host
#
# The hosts that will be used to serve the app. The proxy will only route requests
# to this host to your app.
#
# If no hosts are set, then all requests will be forwarded, except for matching
# requests for other apps deployed on that server that do have a host set.
host: foo.example.com

# App port
#
# The port the application container is exposed on
#
# Defaults to 80
app_port: 3000

# SSL
#
# kamal-proxy can provide automatic HTTPS for your application via Let's Encrypt.
#
# This requires that we are deploying to a one server and the host option is set.
# The host value must point to the server we are deploying to and port 443 must be
# open for the Let's Encrypt challenge to succeed.
#
# Defaults to false
ssl: true

# Response timeout
#
# How long to wait for requests to complete before timing out, defaults to 30 seconds
response_timeout: 10

# Healthcheck
#
# When deploying, the proxy will by default hit /up once every second until we hit
# the deploy timeout, with a 5 second timeout for each request.
#
# Once the app is up, the proxy will stop hitting the healthcheck endpoint.
healthcheck:
interval: 3
path: /health
timeout: 3

# Buffering
#
# Whether to buffer request and response bodies in the proxy
#
# By default buffering is enabled with a max request body size of 1GB and no limit
# for response size.
#
# You can also set the memory limit for buffering, which defaults to 1MB, anything
# larger than that is written to disk.
buffering:
requests: true
responses: true
max_request_body: 40_000_000
max_response_body: 0
memory: 2_000_000

# Logging
#
# Configure request logging for the proxy
# You can specify request and response headers to log.
# By default, Cache-Control, Last-Modified and User-Agent request headers are logged
logging:
request_headers:
- Cache-Control
- X-Forwarded-Proto
response_headers:
- X-Request-ID
- X-Request-Start

# Forward headers
#
# Whether to forward the X-Forwarded-For and X-Forwarded-Proto headers.
#
# If you are behind a trusted proxy, you can set this to true to forward the headers.
#
# By default kamal-proxy will not forward the headers the ssl option is set to true, and
# will forward them if it is set to false.
forward_headers: true
8 changes: 8 additions & 0 deletions test/configuration/accessory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
"options" => {
"cpus" => "4",
"memory" => "2GB"
},
"proxy" => {
"host" => "monitoring.example.com"
}
}
}
Expand Down Expand Up @@ -152,4 +155,9 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
test "options" do
assert_equal [ "--cpus", "\"4\"", "--memory", "\"2GB\"" ], @config.accessory(:redis).option_args
end

test "proxy" do
assert @config.accessory(:monitoring).running_proxy?
assert_equal "monitoring.example.com", @config.accessory(:monitoring).proxy.host
end
end

0 comments on commit 2c6010d

Please sign in to comment.