73 lines
2.1 KiB
Ruby
73 lines
2.1 KiB
Ruby
class Kamal::Commands::Proxy < Kamal::Commands::Base
|
|
delegate :argumentize, :optionize, to: Kamal::Utils
|
|
|
|
def run
|
|
docker :run,
|
|
"--name", container_name,
|
|
"--network", "kamal",
|
|
"--detach",
|
|
"--restart", "unless-stopped",
|
|
*config.proxy_publish_args,
|
|
"--volume", "kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy",
|
|
*config.logging_args,
|
|
config.proxy_image
|
|
end
|
|
|
|
def start
|
|
docker :container, :start, container_name
|
|
end
|
|
|
|
def stop(name: container_name)
|
|
docker :container, :stop, name
|
|
end
|
|
|
|
def start_or_run
|
|
combine start, run, by: "||"
|
|
end
|
|
|
|
def info
|
|
docker :ps, "--filter", "name=^#{container_name}$"
|
|
end
|
|
|
|
def version
|
|
pipe \
|
|
docker(:inspect, container_name, "--format '{{.Config.Image}}'"),
|
|
[ :cut, "-d:", "-f2" ]
|
|
end
|
|
|
|
def logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil)
|
|
pipe \
|
|
docker(:logs, container_name, ("--since #{since}" if since), ("--tail #{lines}" if lines), ("--timestamps" if timestamps), "2>&1"),
|
|
("grep '#{grep}'#{" #{grep_options}" if grep_options}" if grep)
|
|
end
|
|
|
|
def follow_logs(host:, timestamps: true, grep: nil, grep_options: nil)
|
|
run_over_ssh pipe(
|
|
docker(:logs, container_name, ("--timestamps" if timestamps), "--tail", "10", "--follow", "2>&1"),
|
|
(%(grep "#{grep}"#{" #{grep_options}" if grep_options}) if grep)
|
|
).join(" "), host: host
|
|
end
|
|
|
|
def remove_container
|
|
docker :container, :prune, "--force", "--filter", "label=org.opencontainers.image.title=kamal-proxy"
|
|
end
|
|
|
|
def remove_image
|
|
docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=kamal-proxy"
|
|
end
|
|
|
|
def cleanup_traefik
|
|
chain \
|
|
docker(:container, :stop, "traefik"),
|
|
combine(
|
|
docker(:container, :prune, "--force", "--filter", "label=org.opencontainers.image.title=Traefik"),
|
|
docker(:image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=Traefik")
|
|
)
|
|
end
|
|
|
|
private
|
|
def container_name
|
|
config.proxy_container_name
|
|
end
|
|
end
|