Rip out Traefik
This commit is contained in:
@@ -137,15 +137,9 @@ builder:
|
||||
accessories:
|
||||
...
|
||||
|
||||
# Traefik
|
||||
#
|
||||
# The Traefik proxy is used for zero-downtime deployments, see kamal docs traefik
|
||||
traefik:
|
||||
...
|
||||
|
||||
# Proxy
|
||||
#
|
||||
# **Experimental** Configuration for kamal-proxy the replacement for Traefik, see kamal docs proxy
|
||||
# Configuration for kamal-proxy, see kamal docs proxy
|
||||
proxy:
|
||||
...
|
||||
|
||||
@@ -161,12 +155,6 @@ sshkit:
|
||||
boot:
|
||||
...
|
||||
|
||||
# Healthcheck
|
||||
#
|
||||
# Configuring healthcheck commands, intervals and timeouts, see kamal docs healthcheck
|
||||
healthcheck:
|
||||
...
|
||||
|
||||
# Logging
|
||||
#
|
||||
# Docker logging configuration, see kamal docs logging
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
# Healthcheck configuration
|
||||
#
|
||||
# On roles that are running Traefik, Kamal will supply a default healthcheck to `docker run`.
|
||||
# For other roles, by default no healthcheck is supplied.
|
||||
#
|
||||
# If no healthcheck is supplied and the image does not define one, then we wait for the container
|
||||
# to reach a running state and then pause for the readiness delay.
|
||||
#
|
||||
# The default healthcheck is `curl -f http://localhost:<port>/<path>`, so it assumes that `curl`
|
||||
# is available within the container.
|
||||
|
||||
# Healthcheck options
|
||||
#
|
||||
# These go under the `healthcheck` key in the root or role configuration.
|
||||
healthcheck:
|
||||
|
||||
# Command
|
||||
#
|
||||
# The command to run, defaults to `curl -f http://localhost:<port>/<path>` on roles running Traefik
|
||||
cmd: "curl -f http://localhost"
|
||||
|
||||
# Interval
|
||||
#
|
||||
# The Docker healthcheck interval, defaults to `1s`
|
||||
interval: 10s
|
||||
|
||||
# Max attempts
|
||||
#
|
||||
# The maximum number of times we poll the container to see if it is healthy, defaults to `7`
|
||||
# Each check is separated by an increasing interval starting with 1 second.
|
||||
max_attempts: 3
|
||||
|
||||
# Port
|
||||
#
|
||||
# The port to use in the healthcheck, defaults to `3000`
|
||||
port: "80"
|
||||
|
||||
# Path
|
||||
#
|
||||
# The path to use in the healthcheck, defaults to `/up`
|
||||
path: /health
|
||||
|
||||
# Cords for zero-downtime deployments
|
||||
#
|
||||
# The cord file is used for zero-downtime deployments. The healthcheck is augmented with a check
|
||||
# for the existance of the file. This allows us to delete the file and force the container to
|
||||
# become unhealthy, causing Traefik to stop routing traffic to it.
|
||||
#
|
||||
# Kamal mounts a volume at this location and creates the file before starting the container.
|
||||
# You can set the value to `false` to disable the cord file, but this loses the zero-downtime
|
||||
# guarantee.
|
||||
#
|
||||
# The default value is `/tmp/kamal-cord`
|
||||
cord: /cord
|
||||
|
||||
# Log lines
|
||||
#
|
||||
# Number of lines to log from the container when the healthcheck fails, defaults to `50`
|
||||
log_lines: 100
|
||||
@@ -1,51 +1,12 @@
|
||||
# Proxy
|
||||
#
|
||||
# **Experimental** [kamal-proxy](http://github.com/basecamp/kamal-proxy) is a
|
||||
# custom built specifically for Kamal. It will replace Traefik in Kamal v2.0,
|
||||
# but currently is available as an experimental feature.
|
||||
#
|
||||
# When this is enabled, the proxy will be started on the hosts listed under the hosts key.
|
||||
# In addition, the kamal traefik command will be disabled and replaced by kamal proxy.
|
||||
#
|
||||
# The kamal proxy command works identically to kamal traefik on hosts that have not
|
||||
# been included. It will also handle switching between Traefik and kamal-proxy when you
|
||||
# run kamal proxy reboot.
|
||||
|
||||
# Limitations
|
||||
#
|
||||
# Currently the proxy will run on ports 80 and 443 and will bind to those
|
||||
# ports on the host.
|
||||
#
|
||||
# There is no way to set custom options for `docker run` when booting the proxy.
|
||||
#
|
||||
# If you have custom Traefik configuration via labels or boot arguments they may
|
||||
# not have an equivalent in kamal-proxy.
|
||||
|
||||
# Proxy settings
|
||||
#
|
||||
# The proxy is configured in the root configuration under `traefik`. These are
|
||||
# The proxy is configured in the root configuration under `proxy`. These are
|
||||
# options that are set when deploying the application, not when booting the proxy
|
||||
#
|
||||
# They are application specific, so are not shared when multiple applications
|
||||
# with the same proxy.
|
||||
# run on the same proxy.
|
||||
proxy:
|
||||
|
||||
# Enabled
|
||||
#
|
||||
# Whether to enable experimental proxy support. Defaults to false
|
||||
enabled: true
|
||||
|
||||
# Hosts
|
||||
#
|
||||
# The hosts to run the proxy on, instead of Traefik
|
||||
# This is a temporary setting and will be removed when we full switch to kamal-proxy
|
||||
#
|
||||
# If you run `kamal traefik reboot`, then the proxy will be started on these hosts
|
||||
# in place of traefik.
|
||||
hosts:
|
||||
- 10.0.0.1
|
||||
- 10.0.0.2
|
||||
|
||||
# Host
|
||||
#
|
||||
# This is the host that will be used to serve the app. By setting this you can run
|
||||
|
||||
@@ -26,7 +26,7 @@ servers:
|
||||
#
|
||||
# When there are other options to set, the list of hosts goes under the `hosts` key
|
||||
#
|
||||
# By default only the primary role uses Traefik, but you can set `traefik` to change
|
||||
# By default only the primary role uses a proxy, but you can set `proxy` to change
|
||||
# it.
|
||||
#
|
||||
# You can also set a custom cmd to run in the container, and overwrite other settings
|
||||
@@ -35,13 +35,11 @@ servers:
|
||||
hosts:
|
||||
- 172.1.0.3
|
||||
- 172.1.0.4: experiment1
|
||||
traefik: true
|
||||
proxy: true
|
||||
cmd: "bin/jobs"
|
||||
options:
|
||||
memory: 2g
|
||||
cpus: 4
|
||||
healthcheck:
|
||||
...
|
||||
logging:
|
||||
...
|
||||
labels:
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
# Traefik
|
||||
#
|
||||
# Traefik is a reverse proxy, used by Kamal for zero-downtime deployments.
|
||||
#
|
||||
# We start an instance on the hosts in it's own container.
|
||||
#
|
||||
# During a deployment:
|
||||
# 1. We start a new container which Traefik automatically detects due to the labels we have applied
|
||||
# 2. Traefik starts routing traffic to the new container
|
||||
# 3. We force the old container to fail it's healthcheck, causing Traefik to stop routing traffic to it
|
||||
# 4. We stop the old container
|
||||
|
||||
# Traefik settings
|
||||
#
|
||||
# Traekik is configured in the root configuration under `traefik`.
|
||||
traefik:
|
||||
|
||||
# Image
|
||||
#
|
||||
# The Traefik image to use, defaults to `traefik:v2.10`
|
||||
image: traefik:v2.9
|
||||
|
||||
# Host port
|
||||
#
|
||||
# The host port to publish the Traefik container on, defaults to `80`
|
||||
host_port: "8080"
|
||||
|
||||
# Disabling publishing
|
||||
#
|
||||
# To avoid publishing the Traefik container, set this to `false`
|
||||
publish: false
|
||||
|
||||
# Labels
|
||||
#
|
||||
# Additional labels to apply to the Traefik container
|
||||
labels:
|
||||
traefik.http.routers.catchall.entryPoints: http
|
||||
traefik.http.routers.catchall.rule: PathPrefix(`/`)
|
||||
traefik.http.routers.catchall.service: unavailable
|
||||
traefik.http.routers.catchall.priority: "1"
|
||||
traefik.http.services.unavailable.loadbalancer.server.port: "0"
|
||||
|
||||
# Arguments
|
||||
#
|
||||
# Additional arguments to pass to the Traefik container
|
||||
args:
|
||||
entryPoints.http.address: ":80"
|
||||
entryPoints.http.forwardedHeaders.insecure: true
|
||||
accesslog: true
|
||||
accesslog.format: json
|
||||
|
||||
# Options
|
||||
#
|
||||
# Additional options to pass to `docker run`
|
||||
options:
|
||||
cpus: 2
|
||||
|
||||
# Environment variables
|
||||
#
|
||||
# See kamal docs env
|
||||
env:
|
||||
...
|
||||
@@ -1,63 +0,0 @@
|
||||
class Kamal::Configuration::Healthcheck
|
||||
include Kamal::Configuration::Validation
|
||||
|
||||
attr_reader :healthcheck_config
|
||||
|
||||
def initialize(healthcheck_config:, context: "healthcheck")
|
||||
@healthcheck_config = healthcheck_config || {}
|
||||
validate! @healthcheck_config, context: context
|
||||
end
|
||||
|
||||
def merge(other)
|
||||
self.class.new healthcheck_config: healthcheck_config.deep_merge(other.healthcheck_config)
|
||||
end
|
||||
|
||||
def cmd
|
||||
healthcheck_config.fetch("cmd", http_health_check)
|
||||
end
|
||||
|
||||
def port
|
||||
healthcheck_config.fetch("port", 3000)
|
||||
end
|
||||
|
||||
def path
|
||||
healthcheck_config.fetch("path", "/up")
|
||||
end
|
||||
|
||||
def max_attempts
|
||||
healthcheck_config.fetch("max_attempts", 7)
|
||||
end
|
||||
|
||||
def interval
|
||||
healthcheck_config.fetch("interval", "1s")
|
||||
end
|
||||
|
||||
def cord
|
||||
healthcheck_config.fetch("cord", "/tmp/kamal-cord")
|
||||
end
|
||||
|
||||
def log_lines
|
||||
healthcheck_config.fetch("log_lines", 50)
|
||||
end
|
||||
|
||||
def set_port_or_path?
|
||||
healthcheck_config["port"].present? || healthcheck_config["path"].present?
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
"cmd" => cmd,
|
||||
"interval" => interval,
|
||||
"max_attempts" => max_attempts,
|
||||
"port" => port,
|
||||
"path" => path,
|
||||
"cord" => cord,
|
||||
"log_lines" => log_lines
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
def http_health_check
|
||||
"curl -f #{URI.join("http://localhost:#{port}", path)} || exit 1" if path.present? || port.present?
|
||||
end
|
||||
end
|
||||
@@ -14,18 +14,6 @@ class Kamal::Configuration::Proxy
|
||||
validate! proxy_config, with: Kamal::Configuration::Validator::Proxy
|
||||
end
|
||||
|
||||
def enabled?
|
||||
!!proxy_config.fetch("enabled", false)
|
||||
end
|
||||
|
||||
def hosts
|
||||
if enabled?
|
||||
proxy_config.fetch("hosts", [])
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def app_port
|
||||
proxy_config.fetch("app_port", 80)
|
||||
end
|
||||
@@ -52,9 +40,9 @@ class Kamal::Configuration::Proxy
|
||||
tls: proxy_config["ssl"],
|
||||
"deploy-timeout": proxy_config["deploy_timeout"],
|
||||
"drain-timeout": proxy_config["drain_timeout"],
|
||||
"health-check-interval": proxy_config.dig("health_check", "interval"),
|
||||
"health-check-timeout": proxy_config.dig("health_check", "timeout"),
|
||||
"health-check-path": proxy_config.dig("health_check", "path"),
|
||||
"health-check-interval": proxy_config.dig("healthcheck", "interval"),
|
||||
"health-check-timeout": proxy_config.dig("healthcheck", "timeout"),
|
||||
"health-check-path": proxy_config.dig("healthcheck", "path"),
|
||||
"target-timeout": proxy_config["response_timeout"],
|
||||
"buffer-requests": proxy_config.fetch("buffering", { "requests": true }).fetch("requests", true),
|
||||
"buffer-responses": proxy_config.fetch("buffering", { "responses": true }).fetch("responses", true),
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
class Kamal::Configuration::Role
|
||||
include Kamal::Configuration::Validation
|
||||
|
||||
CORD_FILE = "cord"
|
||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||
|
||||
attr_reader :name, :config, :specialized_env, :specialized_logging, :specialized_healthcheck
|
||||
attr_reader :name, :config, :specialized_env, :specialized_logging
|
||||
|
||||
alias to_s name
|
||||
|
||||
@@ -24,10 +23,6 @@ class Kamal::Configuration::Role
|
||||
@specialized_logging = Kamal::Configuration::Logging.new \
|
||||
logging_config: specializations.fetch("logging", {}),
|
||||
context: "servers/#{name}/logging"
|
||||
|
||||
@specialized_healthcheck = Kamal::Configuration::Healthcheck.new \
|
||||
healthcheck_config: specializations.fetch("healthcheck", {}),
|
||||
context: "servers/#{name}/healthcheck"
|
||||
end
|
||||
|
||||
def primary_host
|
||||
@@ -55,10 +50,6 @@ class Kamal::Configuration::Role
|
||||
end
|
||||
|
||||
def labels
|
||||
default_labels.merge(traefik_labels).merge(custom_labels)
|
||||
end
|
||||
|
||||
def labels_for_proxy
|
||||
default_labels.merge(custom_labels)
|
||||
end
|
||||
|
||||
@@ -66,10 +57,6 @@ class Kamal::Configuration::Role
|
||||
argumentize "--label", labels
|
||||
end
|
||||
|
||||
def label_args_for_proxy
|
||||
argumentize "--label", labels_for_proxy
|
||||
end
|
||||
|
||||
def logging_args
|
||||
logging.args
|
||||
end
|
||||
@@ -105,38 +92,11 @@ class Kamal::Configuration::Role
|
||||
end
|
||||
|
||||
|
||||
def health_check_args(cord: true)
|
||||
if running_traefik? || healthcheck.set_port_or_path?
|
||||
if cord && uses_cord?
|
||||
optionize({ "health-cmd" => health_check_cmd_with_cord, "health-interval" => healthcheck.interval })
|
||||
.concat(cord_volume.docker_args)
|
||||
else
|
||||
optionize({ "health-cmd" => healthcheck.cmd, "health-interval" => healthcheck.interval })
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def healthcheck
|
||||
@healthcheck ||=
|
||||
if running_traefik?
|
||||
config.healthcheck.merge(specialized_healthcheck)
|
||||
else
|
||||
specialized_healthcheck
|
||||
end
|
||||
end
|
||||
|
||||
def health_check_cmd_with_cord
|
||||
"(#{healthcheck.cmd}) && (stat #{cord_container_file} > /dev/null || exit 1)"
|
||||
end
|
||||
|
||||
|
||||
def running_traefik?
|
||||
if specializations["traefik"].nil?
|
||||
def running_proxy?
|
||||
if specializations["proxy"].nil?
|
||||
primary?
|
||||
else
|
||||
specializations["traefik"]
|
||||
specializations["proxy"]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -145,35 +105,6 @@ class Kamal::Configuration::Role
|
||||
end
|
||||
|
||||
|
||||
def uses_cord?
|
||||
running_traefik? && cord_volume && healthcheck.cmd.present?
|
||||
end
|
||||
|
||||
def cord_host_directory
|
||||
File.join config.run_directory_as_docker_volume, "cords", [ container_prefix, config.run_id ].join("-")
|
||||
end
|
||||
|
||||
def cord_volume
|
||||
if (cord = healthcheck.cord)
|
||||
@cord_volume ||= Kamal::Configuration::Volume.new \
|
||||
host_path: File.join(config.run_directory, "cords", [ container_prefix, config.run_id ].join("-")),
|
||||
container_path: cord
|
||||
end
|
||||
end
|
||||
|
||||
def cord_host_file
|
||||
File.join cord_volume.host_path, CORD_FILE
|
||||
end
|
||||
|
||||
def cord_container_directory
|
||||
health_check_options.fetch("cord", nil)
|
||||
end
|
||||
|
||||
def cord_container_file
|
||||
File.join cord_volume.container_path, CORD_FILE
|
||||
end
|
||||
|
||||
|
||||
def container_name(version = nil)
|
||||
[ container_prefix, version || config.version ].compact.join("-")
|
||||
end
|
||||
@@ -188,7 +119,7 @@ class Kamal::Configuration::Role
|
||||
end
|
||||
|
||||
def assets?
|
||||
asset_path.present? && running_traefik?
|
||||
asset_path.present? && running_proxy?
|
||||
end
|
||||
|
||||
def asset_volume(version = nil)
|
||||
@@ -241,27 +172,6 @@ class Kamal::Configuration::Role
|
||||
end
|
||||
end
|
||||
|
||||
def traefik_labels
|
||||
if running_traefik?
|
||||
{
|
||||
# Setting a service property ensures that the generated service name will be consistent between versions
|
||||
"traefik.http.services.#{traefik_service}.loadbalancer.server.scheme" => "http",
|
||||
|
||||
"traefik.http.routers.#{traefik_service}.rule" => "PathPrefix(`/`)",
|
||||
"traefik.http.routers.#{traefik_service}.priority" => "2",
|
||||
"traefik.http.middlewares.#{traefik_service}-retry.retry.attempts" => "5",
|
||||
"traefik.http.middlewares.#{traefik_service}-retry.retry.initialinterval" => "500ms",
|
||||
"traefik.http.routers.#{traefik_service}.middlewares" => "#{traefik_service}-retry@docker"
|
||||
}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def traefik_service
|
||||
container_prefix
|
||||
end
|
||||
|
||||
def custom_labels
|
||||
Hash.new.tap do |labels|
|
||||
labels.merge!(config.labels) if config.labels.present?
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
class Kamal::Configuration::Traefik
|
||||
delegate :argumentize, to: Kamal::Utils
|
||||
|
||||
DEFAULT_IMAGE = "traefik:v2.10"
|
||||
CONTAINER_PORT = 80
|
||||
DEFAULT_ARGS = {
|
||||
"log.level" => "DEBUG"
|
||||
}
|
||||
DEFAULT_LABELS = {
|
||||
# These ensure we serve a 502 rather than a 404 if no containers are available
|
||||
"traefik.http.routers.catchall.entryPoints" => "http",
|
||||
"traefik.http.routers.catchall.rule" => "PathPrefix(`/`)",
|
||||
"traefik.http.routers.catchall.service" => "unavailable",
|
||||
"traefik.http.routers.catchall.priority" => 1,
|
||||
"traefik.http.services.unavailable.loadbalancer.server.port" => "0"
|
||||
}
|
||||
|
||||
include Kamal::Configuration::Validation
|
||||
|
||||
attr_reader :config, :traefik_config
|
||||
|
||||
def initialize(config:)
|
||||
@config = config
|
||||
@traefik_config = config.raw_config.traefik || {}
|
||||
validate! traefik_config
|
||||
end
|
||||
|
||||
def publish?
|
||||
traefik_config["publish"] != false
|
||||
end
|
||||
|
||||
def labels
|
||||
DEFAULT_LABELS.merge(traefik_config["labels"] || {})
|
||||
end
|
||||
|
||||
def env
|
||||
Kamal::Configuration::Env.new \
|
||||
config: traefik_config.fetch("env", {}),
|
||||
secrets: config.secrets,
|
||||
context: "traefik/env"
|
||||
end
|
||||
|
||||
def host_port
|
||||
traefik_config.fetch("host_port", CONTAINER_PORT)
|
||||
end
|
||||
|
||||
def options
|
||||
traefik_config.fetch("options", {})
|
||||
end
|
||||
|
||||
def port
|
||||
"#{host_port}:#{CONTAINER_PORT}"
|
||||
end
|
||||
|
||||
def args
|
||||
DEFAULT_ARGS.merge(traefik_config.fetch("args", {}))
|
||||
end
|
||||
|
||||
def image
|
||||
traefik_config.fetch("image", DEFAULT_IMAGE)
|
||||
end
|
||||
|
||||
def env_args
|
||||
[ *env.clear_args, *argumentize("--env-file", secrets_path) ]
|
||||
end
|
||||
|
||||
def env_directory
|
||||
File.join(config.env_directory, "traefik")
|
||||
end
|
||||
|
||||
def secrets_io
|
||||
env.secrets_io
|
||||
end
|
||||
|
||||
def secrets_path
|
||||
File.join(config.env_directory, "traefik", "traefik.env")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user