Compare commits
98 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c93588713b | ||
|
|
d47912572c | ||
|
|
00061ce7aa | ||
|
|
9c4747ec0c | ||
|
|
8bb596e216 | ||
|
|
699bcc0d27 | ||
|
|
6aacd1f9e2 | ||
|
|
20e71d91c0 | ||
|
|
866303a59b | ||
|
|
53bfefeb2f | ||
|
|
f3b7569032 | ||
|
|
e5457cf7b4 | ||
|
|
cee449c269 | ||
|
|
786454f2ee | ||
|
|
827e18480d | ||
|
|
9f9c9ccbde | ||
|
|
981d391d4d | ||
|
|
900041001a | ||
|
|
43672ec9a5 | ||
|
|
5481fbb973 | ||
|
|
49afdbb09a | ||
|
|
5f58575b62 | ||
|
|
cb49d7dada | ||
|
|
3d26fa8ddd | ||
|
|
ea9f8b488d | ||
|
|
83472af32c | ||
|
|
e99e1955b8 | ||
|
|
30e0c44396 | ||
|
|
20d6e5365e | ||
|
|
72ace2bf0b | ||
|
|
ba40d026d0 | ||
|
|
0f13600ba3 | ||
|
|
bbf952952d | ||
|
|
474b76cf47 | ||
|
|
3ecfb3744f | ||
|
|
c985fa33d1 | ||
|
|
e8b9f8907f | ||
|
|
4966d52919 | ||
|
|
52bb40add0 | ||
|
|
73a9276cdd | ||
|
|
8c0784ed4a | ||
|
|
089a2d3bba | ||
|
|
bd76d23916 | ||
|
|
fa37fcd10c | ||
|
|
f5dc0858b0 | ||
|
|
9dddb140b1 | ||
|
|
26b1d57c90 | ||
|
|
b94199415f | ||
|
|
f69c45b7ea | ||
|
|
32a2ae5b2c | ||
|
|
37544a6383 | ||
|
|
a1bc6d61af | ||
|
|
5c32be10f1 | ||
|
|
dc5af03593 | ||
|
|
1abd029ea0 | ||
|
|
c4d0d3e5eb | ||
|
|
46e7cf8e78 | ||
|
|
c7cfc074b6 | ||
|
|
c10f43e365 | ||
|
|
8e2184d65e | ||
|
|
2be397b679 | ||
|
|
cc8c508556 | ||
|
|
3b16e047c5 | ||
|
|
6563393d9a | ||
|
|
91f350fcce | ||
|
|
e4e9664049 | ||
|
|
1acef5221f | ||
|
|
788a57e85e | ||
|
|
f9a934a01f | ||
|
|
f286fdc374 | ||
|
|
828cca322b | ||
|
|
cb030e8751 | ||
|
|
6892abb4be | ||
|
|
bcfd0ca88a | ||
|
|
2e8071a5b3 | ||
|
|
200e2686fd | ||
|
|
db94789dc1 | ||
|
|
2bffc3bc74 | ||
|
|
064ace0598 | ||
|
|
a02af74dda | ||
|
|
5ef384d666 | ||
|
|
b94dfe193b | ||
|
|
bc6c027315 | ||
|
|
1c2a45817a | ||
|
|
b411356409 | ||
|
|
77e72e34ce | ||
|
|
ad04bb7556 | ||
|
|
1ec69d3764 | ||
|
|
2d1a0dc9ba | ||
|
|
c984db152f | ||
|
|
aea55480ad | ||
|
|
5a09aa12ba | ||
|
|
0d709a3fdb | ||
|
|
414d29ae4e | ||
|
|
f8d8319c2f | ||
|
|
f6a9d54902 | ||
|
|
b2fd5744fb | ||
|
|
cbd99306eb |
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
@@ -5,6 +5,21 @@ on:
|
|||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
|
rubocop:
|
||||||
|
name: RuboCop
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
BUNDLE_ONLY: rubocop
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Ruby and install gems
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 3.3.0
|
||||||
|
bundler-cache: true
|
||||||
|
- name: Run Rubocop
|
||||||
|
run: bundle exec rubocop --parallel
|
||||||
tests:
|
tests:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|||||||
2
.rubocop.yml
Normal file
2
.rubocop.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
inherit_gem:
|
||||||
|
rubocop-rails-omakase: rubocop.yml
|
||||||
6
Gemfile
6
Gemfile
@@ -1,4 +1,8 @@
|
|||||||
source 'https://rubygems.org'
|
source "https://rubygems.org"
|
||||||
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
|
group :rubocop do
|
||||||
|
gem "rubocop-rails-omakase", require: false
|
||||||
|
end
|
||||||
|
|||||||
44
Gemfile.lock
44
Gemfile.lock
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
kamal (1.3.1)
|
kamal (1.4.0)
|
||||||
activesupport (>= 7.0)
|
activesupport (>= 7.0)
|
||||||
base64 (~> 0.2)
|
base64 (~> 0.2)
|
||||||
bcrypt_pbkdf (~> 1.0)
|
bcrypt_pbkdf (~> 1.0)
|
||||||
@@ -42,6 +42,7 @@ GEM
|
|||||||
minitest (>= 5.1)
|
minitest (>= 5.1)
|
||||||
mutex_m
|
mutex_m
|
||||||
tzinfo (~> 2.0)
|
tzinfo (~> 2.0)
|
||||||
|
ast (2.4.2)
|
||||||
base64 (0.2.0)
|
base64 (0.2.0)
|
||||||
bcrypt_pbkdf (1.1.0)
|
bcrypt_pbkdf (1.1.0)
|
||||||
bigdecimal (3.1.5)
|
bigdecimal (3.1.5)
|
||||||
@@ -63,6 +64,8 @@ GEM
|
|||||||
irb (1.11.0)
|
irb (1.11.0)
|
||||||
rdoc
|
rdoc
|
||||||
reline (>= 0.3.8)
|
reline (>= 0.3.8)
|
||||||
|
json (2.7.1)
|
||||||
|
language_server-protocol (3.17.0.3)
|
||||||
loofah (2.22.0)
|
loofah (2.22.0)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.12.0)
|
nokogiri (>= 1.12.0)
|
||||||
@@ -79,6 +82,10 @@ GEM
|
|||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.16.0-x86_64-linux)
|
nokogiri (1.16.0-x86_64-linux)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
|
parallel (1.24.0)
|
||||||
|
parser (3.3.0.5)
|
||||||
|
ast (~> 2.4.1)
|
||||||
|
racc
|
||||||
psych (5.1.2)
|
psych (5.1.2)
|
||||||
stringio
|
stringio
|
||||||
racc (1.7.3)
|
racc (1.7.3)
|
||||||
@@ -105,11 +112,44 @@ GEM
|
|||||||
rake (>= 12.2)
|
rake (>= 12.2)
|
||||||
thor (~> 1.0, >= 1.2.2)
|
thor (~> 1.0, >= 1.2.2)
|
||||||
zeitwerk (~> 2.6)
|
zeitwerk (~> 2.6)
|
||||||
|
rainbow (3.1.1)
|
||||||
rake (13.1.0)
|
rake (13.1.0)
|
||||||
rdoc (6.6.2)
|
rdoc (6.6.2)
|
||||||
psych (>= 4.0.0)
|
psych (>= 4.0.0)
|
||||||
|
regexp_parser (2.9.0)
|
||||||
reline (0.4.2)
|
reline (0.4.2)
|
||||||
io-console (~> 0.5)
|
io-console (~> 0.5)
|
||||||
|
rexml (3.2.6)
|
||||||
|
rubocop (1.62.1)
|
||||||
|
json (~> 2.3)
|
||||||
|
language_server-protocol (>= 3.17.0)
|
||||||
|
parallel (~> 1.10)
|
||||||
|
parser (>= 3.3.0.2)
|
||||||
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
|
regexp_parser (>= 1.8, < 3.0)
|
||||||
|
rexml (>= 3.2.5, < 4.0)
|
||||||
|
rubocop-ast (>= 1.31.1, < 2.0)
|
||||||
|
ruby-progressbar (~> 1.7)
|
||||||
|
unicode-display_width (>= 2.4.0, < 3.0)
|
||||||
|
rubocop-ast (1.31.2)
|
||||||
|
parser (>= 3.3.0.4)
|
||||||
|
rubocop-minitest (0.35.0)
|
||||||
|
rubocop (>= 1.61, < 2.0)
|
||||||
|
rubocop-ast (>= 1.31.1, < 2.0)
|
||||||
|
rubocop-performance (1.20.2)
|
||||||
|
rubocop (>= 1.48.1, < 2.0)
|
||||||
|
rubocop-ast (>= 1.30.0, < 2.0)
|
||||||
|
rubocop-rails (2.24.0)
|
||||||
|
activesupport (>= 4.2.0)
|
||||||
|
rack (>= 1.1)
|
||||||
|
rubocop (>= 1.33.0, < 2.0)
|
||||||
|
rubocop-ast (>= 1.31.1, < 2.0)
|
||||||
|
rubocop-rails-omakase (1.0.0)
|
||||||
|
rubocop
|
||||||
|
rubocop-minitest
|
||||||
|
rubocop-performance
|
||||||
|
rubocop-rails
|
||||||
|
ruby-progressbar (1.13.0)
|
||||||
ruby2_keywords (0.0.5)
|
ruby2_keywords (0.0.5)
|
||||||
sshkit (1.21.7)
|
sshkit (1.21.7)
|
||||||
mutex_m
|
mutex_m
|
||||||
@@ -119,6 +159,7 @@ GEM
|
|||||||
thor (1.3.0)
|
thor (1.3.0)
|
||||||
tzinfo (2.0.6)
|
tzinfo (2.0.6)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
|
unicode-display_width (2.5.0)
|
||||||
webrick (1.8.1)
|
webrick (1.8.1)
|
||||||
zeitwerk (2.6.12)
|
zeitwerk (2.6.12)
|
||||||
|
|
||||||
@@ -132,6 +173,7 @@ DEPENDENCIES
|
|||||||
kamal!
|
kamal!
|
||||||
mocha
|
mocha
|
||||||
railties
|
railties
|
||||||
|
rubocop-rails-omakase
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.4.3
|
2.4.3
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Kamal: Deploy web apps anywhere
|
# Kamal: Deploy web apps anywhere
|
||||||
|
|
||||||
From bare metal to cloud VMs, deploy web apps anywhere with zero downtime. Kamal has the dynamic reverse-proxy Traefik hold requests while a new app container is started and the old one is stopped. Works seamlessly across multiple hosts, using SSHKit to execute commands. Originally built for Rails apps, Kamal will work with any type of web app that can be containerized with Docker.
|
From bare metal to cloud VMs, deploy web apps anywhere with zero downtime. Kamal uses mproxy for zero-downtime deployments. Works seamlessly across multiple hosts, using SSHKit to execute commands. Originally built for Rails apps, Kamal will work with any type of web app that can be containerized with Docker.
|
||||||
|
|
||||||
➡️ See [kamal-deploy.org](https://kamal-deploy.org) for documentation on [installation](https://kamal-deploy.org/docs/installation), [configuration](https://kamal-deploy.org/docs/configuration), and [commands](https://kamal-deploy.org/docs/commands).
|
➡️ See [kamal-deploy.org](https://kamal-deploy.org) for documentation on [installation](https://kamal-deploy.org/docs/installation), [configuration](https://kamal-deploy.org/docs/configuration), and [commands](https://kamal-deploy.org/docs/commands).
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
if name == "all"
|
if name == "all"
|
||||||
KAMAL.accessory_names.each { |accessory_name| boot(accessory_name) }
|
KAMAL.accessory_names.each { |accessory_name| boot(accessory_name) }
|
||||||
else
|
else
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
directories(name)
|
directories(name)
|
||||||
upload(name)
|
upload(name)
|
||||||
|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.registry.login if login
|
execute *KAMAL.registry.login if login
|
||||||
execute *KAMAL.auditor.record("Booted #{name} accessory"), verbosity: :debug
|
execute *KAMAL.auditor.record("Booted #{name} accessory"), verbosity: :debug
|
||||||
execute *accessory.run
|
execute *accessory.run
|
||||||
@@ -22,8 +22,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
desc "upload [NAME]", "Upload accessory files to host", hide: true
|
desc "upload [NAME]", "Upload accessory files to host", hide: true
|
||||||
def upload(name)
|
def upload(name)
|
||||||
mutating do
|
mutating do
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
accessory.files.each do |(local, remote)|
|
accessory.files.each do |(local, remote)|
|
||||||
accessory.ensure_local_file_present(local)
|
accessory.ensure_local_file_present(local)
|
||||||
|
|
||||||
@@ -39,8 +39,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
desc "directories [NAME]", "Create accessory directories on host", hide: true
|
desc "directories [NAME]", "Create accessory directories on host", hide: true
|
||||||
def directories(name)
|
def directories(name)
|
||||||
mutating do
|
mutating do
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
accessory.directories.keys.each do |host_path|
|
accessory.directories.keys.each do |host_path|
|
||||||
execute *accessory.make_directory(host_path)
|
execute *accessory.make_directory(host_path)
|
||||||
end
|
end
|
||||||
@@ -55,8 +55,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
if name == "all"
|
if name == "all"
|
||||||
KAMAL.accessory_names.each { |accessory_name| reboot(accessory_name) }
|
KAMAL.accessory_names.each { |accessory_name| reboot(accessory_name) }
|
||||||
else
|
else
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.registry.login
|
execute *KAMAL.registry.login
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -71,8 +71,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
desc "start [NAME]", "Start existing accessory container on host"
|
desc "start [NAME]", "Start existing accessory container on host"
|
||||||
def start(name)
|
def start(name)
|
||||||
mutating do
|
mutating do
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.auditor.record("Started #{name} accessory"), verbosity: :debug
|
execute *KAMAL.auditor.record("Started #{name} accessory"), verbosity: :debug
|
||||||
execute *accessory.start
|
execute *accessory.start
|
||||||
end
|
end
|
||||||
@@ -83,8 +83,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
desc "stop [NAME]", "Stop existing accessory container on host"
|
desc "stop [NAME]", "Stop existing accessory container on host"
|
||||||
def stop(name)
|
def stop(name)
|
||||||
mutating do
|
mutating do
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.auditor.record("Stopped #{name} accessory"), verbosity: :debug
|
execute *KAMAL.auditor.record("Stopped #{name} accessory"), verbosity: :debug
|
||||||
execute *accessory.stop, raise_on_non_zero_exit: false
|
execute *accessory.stop, raise_on_non_zero_exit: false
|
||||||
end
|
end
|
||||||
@@ -107,8 +107,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
if name == "all"
|
if name == "all"
|
||||||
KAMAL.accessory_names.each { |accessory_name| details(accessory_name) }
|
KAMAL.accessory_names.each { |accessory_name| details(accessory_name) }
|
||||||
else
|
else
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) { puts capture_with_info(*accessory.info) }
|
on(hosts) { puts capture_with_info(*accessory.info) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -117,7 +117,7 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
option :interactive, aliases: "-i", type: :boolean, default: false, desc: "Execute command over ssh for an interactive shell (use for console/bash)"
|
option :interactive, aliases: "-i", type: :boolean, default: false, desc: "Execute command over ssh for an interactive shell (use for console/bash)"
|
||||||
option :reuse, type: :boolean, default: false, desc: "Reuse currently running container instead of starting a new one"
|
option :reuse, type: :boolean, default: false, desc: "Reuse currently running container instead of starting a new one"
|
||||||
def exec(name, cmd)
|
def exec(name, cmd)
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
case
|
case
|
||||||
when options[:interactive] && options[:reuse]
|
when options[:interactive] && options[:reuse]
|
||||||
say "Launching interactive command with via SSH from existing container...", :magenta
|
say "Launching interactive command with via SSH from existing container...", :magenta
|
||||||
@@ -129,14 +129,14 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
|
|
||||||
when options[:reuse]
|
when options[:reuse]
|
||||||
say "Launching command from existing container...", :magenta
|
say "Launching command from existing container...", :magenta
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
|
||||||
capture_with_info(*accessory.execute_in_existing_container(cmd))
|
capture_with_info(*accessory.execute_in_existing_container(cmd))
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
say "Launching command from new container...", :magenta
|
say "Launching command from new container...", :magenta
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
|
||||||
capture_with_info(*accessory.execute_in_new_container(cmd))
|
capture_with_info(*accessory.execute_in_new_container(cmd))
|
||||||
end
|
end
|
||||||
@@ -150,12 +150,12 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
||||||
option :follow, aliases: "-f", desc: "Follow logs on primary server (or specific host set by --hosts)"
|
option :follow, aliases: "-f", desc: "Follow logs on primary server (or specific host set by --hosts)"
|
||||||
def logs(name)
|
def logs(name)
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
grep = options[:grep]
|
grep = options[:grep]
|
||||||
|
|
||||||
if options[:follow]
|
if options[:follow]
|
||||||
run_locally do
|
run_locally do
|
||||||
info "Following logs on #{accessory.hosts}..."
|
info "Following logs on #{hosts}..."
|
||||||
info accessory.follow_logs(grep: grep)
|
info accessory.follow_logs(grep: grep)
|
||||||
exec accessory.follow_logs(grep: grep)
|
exec accessory.follow_logs(grep: grep)
|
||||||
end
|
end
|
||||||
@@ -163,7 +163,7 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
since = options[:since]
|
since = options[:since]
|
||||||
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
||||||
|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
puts capture_with_info(*accessory.logs(since: since, lines: lines, grep: grep))
|
puts capture_with_info(*accessory.logs(since: since, lines: lines, grep: grep))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -177,7 +177,7 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
if name == "all"
|
if name == "all"
|
||||||
KAMAL.accessory_names.each { |accessory_name| remove(accessory_name) }
|
KAMAL.accessory_names.each { |accessory_name| remove(accessory_name) }
|
||||||
else
|
else
|
||||||
if options[:confirmed] || ask("This will remove all containers, images and data directories for #{name}. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
|
confirming "This will remove all containers, images and data directories for #{name}. Are you sure?" do
|
||||||
with_accessory(name) do
|
with_accessory(name) do
|
||||||
stop(name)
|
stop(name)
|
||||||
remove_container(name)
|
remove_container(name)
|
||||||
@@ -192,8 +192,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
desc "remove_container [NAME]", "Remove accessory container from host", hide: true
|
desc "remove_container [NAME]", "Remove accessory container from host", hide: true
|
||||||
def remove_container(name)
|
def remove_container(name)
|
||||||
mutating do
|
mutating do
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.auditor.record("Remove #{name} accessory container"), verbosity: :debug
|
execute *KAMAL.auditor.record("Remove #{name} accessory container"), verbosity: :debug
|
||||||
execute *accessory.remove_container
|
execute *accessory.remove_container
|
||||||
end
|
end
|
||||||
@@ -204,8 +204,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
desc "remove_image [NAME]", "Remove accessory image from host", hide: true
|
desc "remove_image [NAME]", "Remove accessory image from host", hide: true
|
||||||
def remove_image(name)
|
def remove_image(name)
|
||||||
mutating do
|
mutating do
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.auditor.record("Removed #{name} accessory image"), verbosity: :debug
|
execute *KAMAL.auditor.record("Removed #{name} accessory image"), verbosity: :debug
|
||||||
execute *accessory.remove_image
|
execute *accessory.remove_image
|
||||||
end
|
end
|
||||||
@@ -216,8 +216,8 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
desc "remove_service_directory [NAME]", "Remove accessory directory used for uploaded files and data directories from host", hide: true
|
desc "remove_service_directory [NAME]", "Remove accessory directory used for uploaded files and data directories from host", hide: true
|
||||||
def remove_service_directory(name)
|
def remove_service_directory(name)
|
||||||
mutating do
|
mutating do
|
||||||
with_accessory(name) do |accessory|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(accessory.hosts) do
|
on(hosts) do
|
||||||
execute *accessory.remove_service_directory
|
execute *accessory.remove_service_directory
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -226,8 +226,9 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
def with_accessory(name)
|
def with_accessory(name)
|
||||||
if accessory = KAMAL.accessory(name)
|
if KAMAL.config.accessory(name)
|
||||||
yield accessory
|
accessory = KAMAL.accessory(name)
|
||||||
|
yield accessory, accessory_hosts(accessory)
|
||||||
else
|
else
|
||||||
error_on_missing_accessory(name)
|
error_on_missing_accessory(name)
|
||||||
end
|
end
|
||||||
@@ -240,4 +241,12 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
"No accessory by the name of '#{name}'" +
|
"No accessory by the name of '#{name}'" +
|
||||||
(options ? " (options: #{options.to_sentence})" : "")
|
(options ? " (options: #{options.to_sentence})" : "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accessory_hosts(accessory)
|
||||||
|
if KAMAL.specific_hosts&.any?
|
||||||
|
KAMAL.specific_hosts & accessory.hosts
|
||||||
|
else
|
||||||
|
accessory.hosts
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,58 +7,20 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|||||||
using_version(version_or_latest) do |version|
|
using_version(version_or_latest) do |version|
|
||||||
say "Start container with version #{version} using a #{KAMAL.config.readiness_delay}s readiness delay (or reboot if already running)...", :magenta
|
say "Start container with version #{version} using a #{KAMAL.config.readiness_delay}s readiness delay (or reboot if already running)...", :magenta
|
||||||
|
|
||||||
|
# Assets are prepared in a separate step to ensure they are on all hosts before booting
|
||||||
on(KAMAL.hosts) do
|
on(KAMAL.hosts) do
|
||||||
execute *KAMAL.auditor.record("Tagging #{KAMAL.config.absolute_image} as the latest image"), verbosity: :debug
|
execute *KAMAL.auditor.record("Tagging #{KAMAL.config.absolute_image} as the latest image"), verbosity: :debug
|
||||||
execute *KAMAL.app.tag_current_image_as_latest
|
execute *KAMAL.app.tag_current_image_as_latest
|
||||||
|
|
||||||
KAMAL.roles_on(host).each do |role|
|
KAMAL.roles_on(host).each do |role|
|
||||||
app = KAMAL.app(role: role)
|
Kamal::Cli::App::PrepareAssets.new(host, role, self).run
|
||||||
role_config = KAMAL.config.role(role)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if role_config.assets?
|
|
||||||
execute *app.extract_assets
|
|
||||||
old_version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
|
|
||||||
execute *app.sync_asset_volumes(old_version: old_version)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
on(KAMAL.hosts, **KAMAL.boot_strategy) do |host|
|
on(KAMAL.hosts, **KAMAL.boot_strategy) do |host|
|
||||||
KAMAL.roles_on(host).each do |role|
|
KAMAL.roles_on(host).each do |role|
|
||||||
app = KAMAL.app(role: role)
|
Kamal::Cli::App::Boot.new(host, role, version, self).run
|
||||||
auditor = KAMAL.auditor(role: role)
|
|
||||||
role_config = KAMAL.config.role(role)
|
|
||||||
|
|
||||||
if capture_with_info(*app.container_id_for_version(version), raise_on_non_zero_exit: false).present?
|
|
||||||
tmp_version = "#{version}_replaced_#{SecureRandom.hex(8)}"
|
|
||||||
info "Renaming container #{version} to #{tmp_version} as already deployed on #{host}"
|
|
||||||
execute *auditor.record("Renaming container #{version} to #{tmp_version}"), verbosity: :debug
|
|
||||||
execute *app.rename_container(version: version, new_version: tmp_version)
|
|
||||||
end
|
|
||||||
|
|
||||||
old_version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
|
|
||||||
|
|
||||||
execute *app.tie_cord(role_config.cord_host_file) if role_config.uses_cord?
|
|
||||||
|
|
||||||
execute *auditor.record("Booted app version #{version}"), verbosity: :debug
|
|
||||||
|
|
||||||
execute *app.run(hostname: "#{host}-#{SecureRandom.hex(6)}")
|
|
||||||
|
|
||||||
Kamal::Cli::Healthcheck::Poller.wait_for_healthy(pause_after_ready: true) { capture_with_info(*app.status(version: version)) }
|
|
||||||
|
|
||||||
if old_version.present?
|
|
||||||
if role_config.uses_cord?
|
|
||||||
cord = capture_with_info(*app.cord(version: old_version), raise_on_non_zero_exit: false).strip
|
|
||||||
if cord.present?
|
|
||||||
execute *app.cut_cord(cord)
|
|
||||||
Kamal::Cli::Healthcheck::Poller.wait_for_unhealthy(pause_after_ready: true) { capture_with_info(*app.status(version: old_version)) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
execute *app.stop(version: old_version), raise_on_non_zero_exit: false
|
|
||||||
|
|
||||||
execute *app.clean_up_assets if role_config.assets?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -73,8 +35,14 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|||||||
roles = KAMAL.roles_on(host)
|
roles = KAMAL.roles_on(host)
|
||||||
|
|
||||||
roles.each do |role|
|
roles.each do |role|
|
||||||
|
app = KAMAL.app(role: role)
|
||||||
execute *KAMAL.auditor.record("Started app version #{KAMAL.config.version}"), verbosity: :debug
|
execute *KAMAL.auditor.record("Started app version #{KAMAL.config.version}"), verbosity: :debug
|
||||||
execute *KAMAL.app(role: role).start, raise_on_non_zero_exit: false
|
execute *app.start, raise_on_non_zero_exit: false
|
||||||
|
|
||||||
|
if role.running_proxy?
|
||||||
|
version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
|
||||||
|
execute *KAMAL.proxy.deploy(app.container_name(version))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -87,8 +55,16 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|||||||
roles = KAMAL.roles_on(host)
|
roles = KAMAL.roles_on(host)
|
||||||
|
|
||||||
roles.each do |role|
|
roles.each do |role|
|
||||||
|
app = KAMAL.app(role: role)
|
||||||
|
version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
|
||||||
|
|
||||||
execute *KAMAL.auditor.record("Stopped app", role: role), verbosity: :debug
|
execute *KAMAL.auditor.record("Stopped app", role: role), verbosity: :debug
|
||||||
execute *KAMAL.app(role: role).stop, raise_on_non_zero_exit: false
|
|
||||||
|
if role.running_proxy?
|
||||||
|
execute *KAMAL.proxy.remove(app.container_name(version)), raise_on_non_zero_exit: false
|
||||||
|
end
|
||||||
|
|
||||||
|
execute *app.stop, raise_on_non_zero_exit: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -202,19 +178,20 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|||||||
# FIXME: Catch when app containers aren't running
|
# FIXME: Catch when app containers aren't running
|
||||||
|
|
||||||
grep = options[:grep]
|
grep = options[:grep]
|
||||||
|
since = options[:since]
|
||||||
if options[:follow]
|
if options[:follow]
|
||||||
|
lines = options[:lines].presence || ((since || grep) ? nil : 10) # Default to 10 lines if since or grep isn't set
|
||||||
|
|
||||||
run_locally do
|
run_locally do
|
||||||
info "Following logs on #{KAMAL.primary_host}..."
|
info "Following logs on #{KAMAL.primary_host}..."
|
||||||
|
|
||||||
KAMAL.specific_roles ||= [ "web" ]
|
KAMAL.specific_roles ||= [ "web" ]
|
||||||
role = KAMAL.roles_on(KAMAL.primary_host).first
|
role = KAMAL.roles_on(KAMAL.primary_host).first
|
||||||
|
|
||||||
info KAMAL.app(role: role).follow_logs(host: KAMAL.primary_host, grep: grep)
|
info KAMAL.app(role: role).follow_logs(host: KAMAL.primary_host, lines: lines, grep: grep)
|
||||||
exec KAMAL.app(role: role).follow_logs(host: KAMAL.primary_host, grep: grep)
|
exec KAMAL.app(role: role).follow_logs(host: KAMAL.primary_host, lines: lines, grep: grep)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
since = options[:since]
|
|
||||||
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
||||||
|
|
||||||
on(KAMAL.hosts) do |host|
|
on(KAMAL.hosts) do |host|
|
||||||
|
|||||||
59
lib/kamal/cli/app/boot.rb
Normal file
59
lib/kamal/cli/app/boot.rb
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
class Kamal::Cli::App::Boot
|
||||||
|
attr_reader :host, :role, :version, :sshkit
|
||||||
|
delegate :execute, :capture_with_info, :info, to: :sshkit
|
||||||
|
delegate :assets?, :running_proxy?, to: :role
|
||||||
|
|
||||||
|
def initialize(host, role, version, sshkit)
|
||||||
|
@host = host
|
||||||
|
@role = role
|
||||||
|
@version = version
|
||||||
|
@sshkit = sshkit
|
||||||
|
end
|
||||||
|
|
||||||
|
def run
|
||||||
|
old_version = old_version_renamed_if_clashing
|
||||||
|
|
||||||
|
start_new_version
|
||||||
|
|
||||||
|
if old_version
|
||||||
|
stop_old_version(old_version)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def app
|
||||||
|
@app ||= KAMAL.app(role: role)
|
||||||
|
end
|
||||||
|
|
||||||
|
def auditor
|
||||||
|
@auditor = KAMAL.auditor(role: role)
|
||||||
|
end
|
||||||
|
|
||||||
|
def audit(message)
|
||||||
|
execute *auditor.record(message), verbosity: :debug
|
||||||
|
end
|
||||||
|
|
||||||
|
def old_version_renamed_if_clashing
|
||||||
|
if capture_with_info(*app.container_id_for_version(version), raise_on_non_zero_exit: false).present?
|
||||||
|
renamed_version = "#{version}_replaced_#{SecureRandom.hex(8)}"
|
||||||
|
info "Renaming container #{version} to #{renamed_version} as already deployed on #{host}"
|
||||||
|
audit("Renaming container #{version} to #{renamed_version}")
|
||||||
|
execute *app.rename_container(version: version, new_version: renamed_version)
|
||||||
|
end
|
||||||
|
|
||||||
|
capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip.presence
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_new_version
|
||||||
|
audit "Booted app version #{version}"
|
||||||
|
execute *app.run(hostname: "#{host}-#{SecureRandom.hex(6)}")
|
||||||
|
if running_proxy?
|
||||||
|
execute *KAMAL.proxy.deploy("#{app.container_name(version)}:#{role.port}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop_old_version(version)
|
||||||
|
execute *app.stop(version: version), raise_on_non_zero_exit: false
|
||||||
|
execute *app.clean_up_assets if assets?
|
||||||
|
end
|
||||||
|
end
|
||||||
24
lib/kamal/cli/app/prepare_assets.rb
Normal file
24
lib/kamal/cli/app/prepare_assets.rb
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
class Kamal::Cli::App::PrepareAssets
|
||||||
|
attr_reader :host, :role, :sshkit
|
||||||
|
delegate :execute, :capture_with_info, :info, to: :sshkit
|
||||||
|
delegate :assets?, to: :role
|
||||||
|
|
||||||
|
def initialize(host, role, sshkit)
|
||||||
|
@host = host
|
||||||
|
@role = role
|
||||||
|
@sshkit = sshkit
|
||||||
|
end
|
||||||
|
|
||||||
|
def run
|
||||||
|
if assets?
|
||||||
|
execute *app.extract_assets
|
||||||
|
old_version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
|
||||||
|
execute *app.sync_asset_volumes(old_version: old_version)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def app
|
||||||
|
@app ||= KAMAL.app(role: role)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -73,7 +73,7 @@ module Kamal::Cli
|
|||||||
def print_runtime
|
def print_runtime
|
||||||
started_at = Time.now
|
started_at = Time.now
|
||||||
yield
|
yield
|
||||||
return Time.now - started_at
|
Time.now - started_at
|
||||||
ensure
|
ensure
|
||||||
runtime = Time.now - started_at
|
runtime = Time.now - started_at
|
||||||
puts " Finished all in #{sprintf("%.1f seconds", runtime)}"
|
puts " Finished all in #{sprintf("%.1f seconds", runtime)}"
|
||||||
@@ -84,7 +84,7 @@ module Kamal::Cli
|
|||||||
|
|
||||||
run_hook "pre-connect"
|
run_hook "pre-connect"
|
||||||
|
|
||||||
ensure_run_directory
|
ensure_run_and_locks_directory
|
||||||
|
|
||||||
acquire_lock
|
acquire_lock
|
||||||
|
|
||||||
@@ -103,6 +103,16 @@ module Kamal::Cli
|
|||||||
release_lock
|
release_lock
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def confirming(question)
|
||||||
|
return yield if options[:confirmed]
|
||||||
|
|
||||||
|
if ask(question, limited_to: %w[ y N ], default: "N") == "y"
|
||||||
|
yield
|
||||||
|
else
|
||||||
|
say "Aborted", :red
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def acquire_lock
|
def acquire_lock
|
||||||
raise_if_locked do
|
raise_if_locked do
|
||||||
say "Acquiring the deploy lock...", :magenta
|
say "Acquiring the deploy lock...", :magenta
|
||||||
@@ -123,8 +133,9 @@ module Kamal::Cli
|
|||||||
yield
|
yield
|
||||||
rescue SSHKit::Runner::ExecuteError => e
|
rescue SSHKit::Runner::ExecuteError => e
|
||||||
if e.message =~ /cannot create directory/
|
if e.message =~ /cannot create directory/
|
||||||
|
say "Deploy lock already in place!", :red
|
||||||
on(KAMAL.primary_host) { puts capture_with_debug(*KAMAL.lock.status) }
|
on(KAMAL.primary_host) { puts capture_with_debug(*KAMAL.lock.status) }
|
||||||
raise LockError, "Deploy lock found"
|
raise LockError, "Deploy lock found. Run 'kamal lock help' for more information"
|
||||||
else
|
else
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
@@ -175,10 +186,14 @@ module Kamal::Cli
|
|||||||
instance_variable_get("@_invocations").first
|
instance_variable_get("@_invocations").first
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_run_directory
|
def ensure_run_and_locks_directory
|
||||||
on(KAMAL.hosts) do
|
on(KAMAL.hosts) do
|
||||||
execute(*KAMAL.server.ensure_run_directory)
|
execute(*KAMAL.server.ensure_run_directory)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
on(KAMAL.primary_host) do
|
||||||
|
execute(*KAMAL.lock.ensure_locks_directory)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,22 +8,16 @@ class Kamal::Cli::Env < Kamal::Cli::Base
|
|||||||
execute *KAMAL.auditor.record("Pushed env files"), verbosity: :debug
|
execute *KAMAL.auditor.record("Pushed env files"), verbosity: :debug
|
||||||
|
|
||||||
KAMAL.roles_on(host).each do |role|
|
KAMAL.roles_on(host).each do |role|
|
||||||
role_config = KAMAL.config.role(role)
|
|
||||||
execute *KAMAL.app(role: role).make_env_directory
|
execute *KAMAL.app(role: role).make_env_directory
|
||||||
upload! StringIO.new(role_config.env_file), role_config.host_env_file_path, mode: 400
|
upload! role.env.secrets_io, role.env.secrets_file, mode: 400
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
on(KAMAL.traefik_hosts) do
|
|
||||||
execute *KAMAL.traefik.make_env_directory
|
|
||||||
upload! StringIO.new(KAMAL.traefik.env_file), KAMAL.traefik.host_env_file_path, mode: 400
|
|
||||||
end
|
|
||||||
|
|
||||||
on(KAMAL.accessory_hosts) do
|
on(KAMAL.accessory_hosts) do
|
||||||
KAMAL.accessories_on(host).each do |accessory|
|
KAMAL.accessories_on(host).each do |accessory|
|
||||||
accessory_config = KAMAL.config.accessory(accessory)
|
accessory_config = KAMAL.config.accessory(accessory)
|
||||||
execute *KAMAL.accessory(accessory).make_env_directory
|
execute *KAMAL.accessory(accessory).make_env_directory
|
||||||
upload! StringIO.new(accessory_config.env_file), accessory_config.host_env_file_path, mode: 400
|
upload! accessory_config.env.secrets_io, accessory_config.env.secrets_file, mode: 400
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -36,15 +30,10 @@ class Kamal::Cli::Env < Kamal::Cli::Base
|
|||||||
execute *KAMAL.auditor.record("Deleted env files"), verbosity: :debug
|
execute *KAMAL.auditor.record("Deleted env files"), verbosity: :debug
|
||||||
|
|
||||||
KAMAL.roles_on(host).each do |role|
|
KAMAL.roles_on(host).each do |role|
|
||||||
role_config = KAMAL.config.role(role)
|
|
||||||
execute *KAMAL.app(role: role).remove_env_file
|
execute *KAMAL.app(role: role).remove_env_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
on(KAMAL.traefik_hosts) do
|
|
||||||
execute *KAMAL.traefik.remove_env_file
|
|
||||||
end
|
|
||||||
|
|
||||||
on(KAMAL.accessory_hosts) do
|
on(KAMAL.accessory_hosts) do
|
||||||
KAMAL.accessories_on(host).each do |accessory|
|
KAMAL.accessories_on(host).each do |accessory|
|
||||||
accessory_config = KAMAL.config.accessory(accessory)
|
accessory_config = KAMAL.config.accessory(accessory)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Kamal::Cli::Healthcheck < Kamal::Cli::Base
|
|||||||
|
|
||||||
desc "perform", "Health check current app version"
|
desc "perform", "Health check current app version"
|
||||||
def perform
|
def perform
|
||||||
raise "The primary host is not configured to run Traefik" unless KAMAL.config.role(KAMAL.config.primary_role).running_traefik?
|
raise "The primary host is not configured to run a proxy" unless KAMAL.config.role(KAMAL.config.primary_role).running_proxy?
|
||||||
on(KAMAL.primary_host) do
|
on(KAMAL.primary_host) do
|
||||||
begin
|
begin
|
||||||
execute *KAMAL.healthcheck.run
|
execute *KAMAL.healthcheck.run
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
class Kamal::Cli::Main < Kamal::Cli::Base
|
class Kamal::Cli::Main < Kamal::Cli::Base
|
||||||
desc "setup", "Setup all accessories, push the env, and deploy app to servers"
|
desc "setup", "Setup all accessories, push the env, and deploy app to servers"
|
||||||
|
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push"
|
||||||
def setup
|
def setup
|
||||||
print_runtime do
|
print_runtime do
|
||||||
mutating do
|
mutating do
|
||||||
|
invoke_options = deploy_options
|
||||||
|
|
||||||
say "Ensure Docker is installed...", :magenta
|
say "Ensure Docker is installed...", :magenta
|
||||||
invoke "kamal:cli:server:bootstrap"
|
invoke "kamal:cli:server:bootstrap", [], invoke_options
|
||||||
|
|
||||||
say "Push env files...", :magenta
|
say "Push env files...", :magenta
|
||||||
invoke "kamal:cli:env:push"
|
invoke "kamal:cli:env:push", [], invoke_options
|
||||||
|
|
||||||
invoke "kamal:cli:accessory:boot", [ "all" ]
|
invoke "kamal:cli:accessory:boot", [ "all" ], invoke_options
|
||||||
deploy
|
deploy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -35,10 +38,10 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
|
|
||||||
run_hook "pre-deploy"
|
run_hook "pre-deploy"
|
||||||
|
|
||||||
say "Ensure Traefik is running...", :magenta
|
say "Ensure proxy is running...", :magenta
|
||||||
invoke "kamal:cli:traefik:boot", [], invoke_options
|
invoke "kamal:cli:proxy:boot", [], invoke_options
|
||||||
|
|
||||||
if KAMAL.config.role(KAMAL.config.primary_role).running_traefik?
|
if KAMAL.config.role(KAMAL.config.primary_role).running_proxy?
|
||||||
say "Ensure app can pass healthcheck...", :magenta
|
say "Ensure app can pass healthcheck...", :magenta
|
||||||
invoke "kamal:cli:healthcheck:perform", [], invoke_options
|
invoke "kamal:cli:healthcheck:perform", [], invoke_options
|
||||||
end
|
end
|
||||||
@@ -56,7 +59,7 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
run_hook "post-deploy", runtime: runtime.round
|
run_hook "post-deploy", runtime: runtime.round
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting proxy, pruning, and registry login"
|
||||||
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push"
|
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push"
|
||||||
def redeploy
|
def redeploy
|
||||||
runtime = print_runtime do
|
runtime = print_runtime do
|
||||||
@@ -112,7 +115,7 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
|
|
||||||
desc "details", "Show details about all containers"
|
desc "details", "Show details about all containers"
|
||||||
def details
|
def details
|
||||||
invoke "kamal:cli:traefik:details"
|
invoke "kamal:cli:proxy:details"
|
||||||
invoke "kamal:cli:app:details"
|
invoke "kamal:cli:app:details"
|
||||||
invoke "kamal:cli:accessory:details", [ "all" ]
|
invoke "kamal:cli:accessory:details", [ "all" ]
|
||||||
end
|
end
|
||||||
@@ -190,12 +193,12 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "remove", "Remove Traefik, app, accessories, and registry session from servers"
|
desc "remove", "Remove proxy, app, accessories, and registry session from servers"
|
||||||
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
||||||
def remove
|
def remove
|
||||||
mutating do
|
mutating do
|
||||||
if options[:confirmed] || ask("This will remove all containers and images. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
|
confirming "This will remove all containers and images. Are you sure?" do
|
||||||
invoke "kamal:cli:traefik:remove", [], options.without(:confirmed)
|
invoke "kamal:cli:proxy:remove", [], options.without(:confirmed)
|
||||||
invoke "kamal:cli:app:remove", [], options.without(:confirmed)
|
invoke "kamal:cli:app:remove", [], options.without(:confirmed)
|
||||||
invoke "kamal:cli:accessory:remove", [ "all" ], options
|
invoke "kamal:cli:accessory:remove", [ "all" ], options
|
||||||
invoke "kamal:cli:registry:logout", [], options.without(:confirmed)
|
invoke "kamal:cli:registry:logout", [], options.without(:confirmed)
|
||||||
@@ -235,8 +238,8 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
desc "server", "Bootstrap servers with curl and Docker"
|
desc "server", "Bootstrap servers with curl and Docker"
|
||||||
subcommand "server", Kamal::Cli::Server
|
subcommand "server", Kamal::Cli::Server
|
||||||
|
|
||||||
desc "traefik", "Manage Traefik load balancer"
|
desc "proxy", "Manage load balancer proxy"
|
||||||
subcommand "traefik", Kamal::Cli::Traefik
|
subcommand "proxy", Kamal::Cli::Proxy
|
||||||
|
|
||||||
private
|
private
|
||||||
def container_available?(version)
|
def container_available?(version)
|
||||||
|
|||||||
120
lib/kamal/cli/proxy.rb
Normal file
120
lib/kamal/cli/proxy.rb
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
class Kamal::Cli::Proxy < Kamal::Cli::Base
|
||||||
|
desc "boot", "Boot proxy on servers"
|
||||||
|
def boot
|
||||||
|
mutating do
|
||||||
|
on(KAMAL.proxy_hosts) do
|
||||||
|
execute *KAMAL.registry.login
|
||||||
|
execute *KAMAL.proxy.start_or_run
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "reboot", "Reboot proxy on servers (stop container, remove container, start new container)"
|
||||||
|
option :rolling, type: :boolean, default: false, desc: "Reboot proxy on hosts in sequence, rather than in parallel"
|
||||||
|
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
||||||
|
def reboot
|
||||||
|
confirming "This will cause a brief outage on each host. Are you sure?" do
|
||||||
|
mutating do
|
||||||
|
host_groups = options[:rolling] ? KAMAL.proxy_hosts : [ KAMAL.proxy_hosts ]
|
||||||
|
host_groups.each do |hosts|
|
||||||
|
host_list = Array(hosts).join(",")
|
||||||
|
run_hook "pre-proxy-reboot", hosts: host_list
|
||||||
|
on(hosts) do
|
||||||
|
execute *KAMAL.auditor.record("Rebooted proxy"), verbosity: :debug
|
||||||
|
execute *KAMAL.registry.login
|
||||||
|
execute *KAMAL.proxy.stop, raise_on_non_zero_exit: false
|
||||||
|
execute *KAMAL.proxy.remove_container
|
||||||
|
execute *KAMAL.proxy.run
|
||||||
|
end
|
||||||
|
run_hook "post-proxy-reboot", hosts: host_list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "start", "Start existing proxy container on servers"
|
||||||
|
def start
|
||||||
|
mutating do
|
||||||
|
on(KAMAL.proxy_hosts) do
|
||||||
|
execute *KAMAL.auditor.record("Started proxy"), verbosity: :debug
|
||||||
|
execute *KAMAL.proxy.start
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "stop", "Stop existing proxy container on servers"
|
||||||
|
def stop
|
||||||
|
mutating do
|
||||||
|
on(KAMAL.proxy_hosts) do
|
||||||
|
execute *KAMAL.auditor.record("Stopped proxy"), verbosity: :debug
|
||||||
|
execute *KAMAL.proxy.stop, raise_on_non_zero_exit: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "restart", "Restart existing proxy container on servers"
|
||||||
|
def restart
|
||||||
|
mutating do
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "details", "Show details about proxy container from servers"
|
||||||
|
def details
|
||||||
|
on(KAMAL.proxy_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.proxy.info), type: "Proxy" }
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "logs", "Show log lines from proxy on servers"
|
||||||
|
option :since, aliases: "-s", desc: "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)"
|
||||||
|
option :lines, type: :numeric, aliases: "-n", desc: "Number of log lines to pull from each server"
|
||||||
|
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
||||||
|
option :follow, aliases: "-f", desc: "Follow logs on primary server (or specific host set by --hosts)"
|
||||||
|
def logs
|
||||||
|
grep = options[:grep]
|
||||||
|
|
||||||
|
if options[:follow]
|
||||||
|
run_locally do
|
||||||
|
info "Following logs on #{KAMAL.primary_host}..."
|
||||||
|
info KAMAL.proxy.follow_logs(host: KAMAL.primary_host, grep: grep)
|
||||||
|
exec KAMAL.proxy.follow_logs(host: KAMAL.primary_host, grep: grep)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
since = options[:since]
|
||||||
|
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
||||||
|
|
||||||
|
on(KAMAL.proxy_hosts) do |host|
|
||||||
|
puts_by_host host, capture(*KAMAL.proxy.logs(since: since, lines: lines, grep: grep)), type: "Proxy"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "remove", "Remove proxy container and image from servers"
|
||||||
|
def remove
|
||||||
|
mutating do
|
||||||
|
stop
|
||||||
|
remove_container
|
||||||
|
remove_image
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "remove_container", "Remove proxy container from servers", hide: true
|
||||||
|
def remove_container
|
||||||
|
mutating do
|
||||||
|
on(KAMAL.proxy_hosts) do
|
||||||
|
execute *KAMAL.auditor.record("Removed proxy container"), verbosity: :debug
|
||||||
|
execute *KAMAL.proxy.remove_container
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "remove_image", "Remove proxy image from servers", hide: true
|
||||||
|
def remove_image
|
||||||
|
mutating do
|
||||||
|
on(KAMAL.proxy_hosts) do
|
||||||
|
execute *KAMAL.auditor.record("Removed proxy image"), verbosity: :debug
|
||||||
|
execute *KAMAL.proxy.remove_image
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -18,12 +18,16 @@ class Kamal::Cli::Prune < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "containers", "Prune all stopped containers, except the last 5"
|
desc "containers", "Prune all stopped containers, except the last n (default 5)"
|
||||||
|
option :retain, type: :numeric, default: nil, desc: "Number of containers to retain"
|
||||||
def containers
|
def containers
|
||||||
|
retain = options.fetch(:retain, KAMAL.config.retain_containers)
|
||||||
|
raise "retain must be at least 1" if retain < 1
|
||||||
|
|
||||||
mutating do
|
mutating do
|
||||||
on(KAMAL.hosts) do
|
on(KAMAL.hosts) do
|
||||||
execute *KAMAL.auditor.record("Pruned containers"), verbosity: :debug
|
execute *KAMAL.auditor.record("Pruned containers"), verbosity: :debug
|
||||||
execute *KAMAL.prune.app_containers
|
execute *KAMAL.prune.app_containers(retain: retain)
|
||||||
execute *KAMAL.prune.healthcheck_containers
|
execute *KAMAL.prune.healthcheck_containers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,10 +14,20 @@ class Kamal::Cli::Server < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
execute(*KAMAL.server.ensure_run_directory)
|
execute(*KAMAL.server.ensure_run_directory)
|
||||||
|
|
||||||
|
begin
|
||||||
|
execute(*KAMAL.docker.create_kamal_network)
|
||||||
|
rescue SSHKit::Command::Failed => e
|
||||||
|
if e.message !~ /network with name kamal already exists/
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if missing.any?
|
if missing.any?
|
||||||
raise "Docker is not installed on #{missing.join(", ")} and can't be automatically installed without having root access and the `curl` command available. Install Docker manually: https://docs.docker.com/engine/install/"
|
raise "Docker is not installed on #{missing.join(", ")} and can't be automatically installed without having root access and either `wget` or `curl`. Install Docker manually: https://docs.docker.com/engine/install/"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
run_hook "docker-setup"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -63,12 +63,6 @@ registry:
|
|||||||
# directories:
|
# directories:
|
||||||
# - data:/data
|
# - data:/data
|
||||||
|
|
||||||
# Configure custom arguments for Traefik
|
|
||||||
# traefik:
|
|
||||||
# args:
|
|
||||||
# accesslog: true
|
|
||||||
# accesslog.format: json
|
|
||||||
|
|
||||||
# Configure a custom healthcheck (default is /up on port 3000)
|
# Configure a custom healthcheck (default is /up on port 3000)
|
||||||
# healthcheck:
|
# healthcheck:
|
||||||
# path: /healthz
|
# path: /healthz
|
||||||
@@ -77,6 +71,10 @@ registry:
|
|||||||
# Bridge fingerprinted assets, like JS and CSS, between versions to avoid
|
# Bridge fingerprinted assets, like JS and CSS, between versions to avoid
|
||||||
# hitting 404 on in-flight requests. Combines all files from new and old
|
# hitting 404 on in-flight requests. Combines all files from new and old
|
||||||
# version inside the asset_path.
|
# version inside the asset_path.
|
||||||
|
#
|
||||||
|
# If your app is using the Sprockets gem, ensure it sets `config.assets.manifest`.
|
||||||
|
# See https://github.com/basecamp/kamal/issues/626 for details
|
||||||
|
#
|
||||||
# asset_path: /rails/public/assets
|
# asset_path: /rails/public/assets
|
||||||
|
|
||||||
# Configure rolling deploys by setting a wait time between batches of restarts.
|
# Configure rolling deploys by setting a wait time between batches of restarts.
|
||||||
|
|||||||
7
lib/kamal/cli/templates/sample_hooks/docker-setup.sample
Normal file
7
lib/kamal/cli/templates/sample_hooks/docker-setup.sample
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
# A sample docker-setup hook
|
||||||
|
#
|
||||||
|
# Sets up a Docker network which can then be used by the application’s containers
|
||||||
|
|
||||||
|
ssh user@example.com docker network create kamal
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "Rebooted Traefik on $KAMAL_HOSTS"
|
echo "Rebooted proxy on $KAMAL_HOSTS"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "Rebooting Traefik on $KAMAL_HOSTS..."
|
echo "Rebooting proxy on $KAMAL_HOSTS..."
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
class Kamal::Cli::Traefik < Kamal::Cli::Base
|
|
||||||
desc "boot", "Boot Traefik on servers"
|
|
||||||
def boot
|
|
||||||
mutating do
|
|
||||||
on(KAMAL.traefik_hosts) do
|
|
||||||
execute *KAMAL.registry.login
|
|
||||||
execute *KAMAL.traefik.start_or_run
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "reboot", "Reboot Traefik on servers (stop container, remove container, start new container)"
|
|
||||||
option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel"
|
|
||||||
def reboot
|
|
||||||
mutating do
|
|
||||||
host_groups = options[:rolling] ? KAMAL.traefik_hosts : [KAMAL.traefik_hosts]
|
|
||||||
host_groups.each do |hosts|
|
|
||||||
host_list = Array(hosts).join(",")
|
|
||||||
run_hook "pre-traefik-reboot", hosts: host_list
|
|
||||||
on(hosts) do
|
|
||||||
execute *KAMAL.auditor.record("Rebooted traefik"), verbosity: :debug
|
|
||||||
execute *KAMAL.registry.login
|
|
||||||
execute *KAMAL.traefik.stop
|
|
||||||
execute *KAMAL.traefik.remove_container
|
|
||||||
execute *KAMAL.traefik.run
|
|
||||||
end
|
|
||||||
run_hook "post-traefik-reboot", hosts: host_list
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "start", "Start existing Traefik container on servers"
|
|
||||||
def start
|
|
||||||
mutating do
|
|
||||||
on(KAMAL.traefik_hosts) do
|
|
||||||
execute *KAMAL.auditor.record("Started traefik"), verbosity: :debug
|
|
||||||
execute *KAMAL.traefik.start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "stop", "Stop existing Traefik container on servers"
|
|
||||||
def stop
|
|
||||||
mutating do
|
|
||||||
on(KAMAL.traefik_hosts) do
|
|
||||||
execute *KAMAL.auditor.record("Stopped traefik"), verbosity: :debug
|
|
||||||
execute *KAMAL.traefik.stop
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "restart", "Restart existing Traefik container on servers"
|
|
||||||
def restart
|
|
||||||
mutating do
|
|
||||||
stop
|
|
||||||
start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "details", "Show details about Traefik container from servers"
|
|
||||||
def details
|
|
||||||
on(KAMAL.traefik_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.traefik.info), type: "Traefik" }
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "logs", "Show log lines from Traefik on servers"
|
|
||||||
option :since, aliases: "-s", desc: "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)"
|
|
||||||
option :lines, type: :numeric, aliases: "-n", desc: "Number of log lines to pull from each server"
|
|
||||||
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
|
||||||
option :follow, aliases: "-f", desc: "Follow logs on primary server (or specific host set by --hosts)"
|
|
||||||
def logs
|
|
||||||
grep = options[:grep]
|
|
||||||
|
|
||||||
if options[:follow]
|
|
||||||
run_locally do
|
|
||||||
info "Following logs on #{KAMAL.primary_host}..."
|
|
||||||
info KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep)
|
|
||||||
exec KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
since = options[:since]
|
|
||||||
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
|
||||||
|
|
||||||
on(KAMAL.traefik_hosts) do |host|
|
|
||||||
puts_by_host host, capture(*KAMAL.traefik.logs(since: since, lines: lines, grep: grep)), type: "Traefik"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "remove", "Remove Traefik container and image from servers"
|
|
||||||
def remove
|
|
||||||
mutating do
|
|
||||||
stop
|
|
||||||
remove_container
|
|
||||||
remove_image
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "remove_container", "Remove Traefik container from servers", hide: true
|
|
||||||
def remove_container
|
|
||||||
mutating do
|
|
||||||
on(KAMAL.traefik_hosts) do
|
|
||||||
execute *KAMAL.auditor.record("Removed traefik container"), verbosity: :debug
|
|
||||||
execute *KAMAL.traefik.remove_container
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "remove_image", "Remove Traefik image from servers", hide: true
|
|
||||||
def remove_image
|
|
||||||
mutating do
|
|
||||||
on(KAMAL.traefik_hosts) do
|
|
||||||
execute *KAMAL.auditor.record("Removed traefik image"), verbosity: :debug
|
|
||||||
execute *KAMAL.traefik.remove_image
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -53,7 +53,7 @@ class Kamal::Commander
|
|||||||
|
|
||||||
def primary_host
|
def primary_host
|
||||||
# Given a list of specific roles, make an effort to match up with the primary_role
|
# Given a list of specific roles, make an effort to match up with the primary_role
|
||||||
specific_hosts&.first || specific_roles&.detect { |role| role.name == config.primary_role }&.primary_host || specific_roles&.first&.primary_host || config.primary_host
|
specific_hosts&.first || specific_roles&.detect { |role| role == config.primary_role }&.primary_host || specific_roles&.first&.primary_host || config.primary_host
|
||||||
end
|
end
|
||||||
|
|
||||||
def primary_role
|
def primary_role
|
||||||
@@ -73,11 +73,11 @@ class Kamal::Commander
|
|||||||
end
|
end
|
||||||
|
|
||||||
def roles_on(host)
|
def roles_on(host)
|
||||||
roles.select { |role| role.hosts.include?(host.to_s) }.map(&:name)
|
roles.select { |role| role.hosts.include?(host.to_s) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def traefik_hosts
|
def proxy_hosts
|
||||||
specific_hosts || config.traefik_hosts
|
specific_hosts || config.proxy_hosts
|
||||||
end
|
end
|
||||||
|
|
||||||
def accessory_hosts
|
def accessory_hosts
|
||||||
@@ -137,8 +137,8 @@ class Kamal::Commander
|
|||||||
@server ||= Kamal::Commands::Server.new(config)
|
@server ||= Kamal::Commands::Server.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def traefik
|
def proxy
|
||||||
@traefik ||= Kamal::Commands::Traefik.new(config)
|
@proxy ||= Kamal::Commands::Proxy.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -99,11 +99,11 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def make_env_directory
|
def make_env_directory
|
||||||
make_directory accessory_config.host_env_directory
|
make_directory accessory_config.env.secrets_directory
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_env_file
|
def remove_env_file
|
||||||
[:rm, "-f", accessory_config.host_env_file_path]
|
[ :rm, "-f", accessory_config.env.secrets_file ]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
class Kamal::Commands::App < Kamal::Commands::Base
|
class Kamal::Commands::App < Kamal::Commands::Base
|
||||||
include Assets, Containers, Cord, Execution, Images, Logging
|
include Assets, Containers, Execution, Images, Logging
|
||||||
|
|
||||||
ACTIVE_DOCKER_STATUSES = [ :running, :restarting ]
|
ACTIVE_DOCKER_STATUSES = [ :running, :restarting ]
|
||||||
|
|
||||||
attr_reader :role, :role_config
|
attr_reader :role, :role
|
||||||
|
|
||||||
def initialize(config, role: nil)
|
def initialize(config, role: nil)
|
||||||
super(config)
|
super(config)
|
||||||
@role = role
|
@role = role
|
||||||
@role_config = config.role(self.role)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(hostname: nil)
|
def run(hostname: nil)
|
||||||
@@ -16,18 +15,19 @@ class Kamal::Commands::App < Kamal::Commands::Base
|
|||||||
"--detach",
|
"--detach",
|
||||||
"--restart unless-stopped",
|
"--restart unless-stopped",
|
||||||
"--name", container_name,
|
"--name", container_name,
|
||||||
|
"--network kamal",
|
||||||
*([ "--hostname", hostname ] if hostname),
|
*([ "--hostname", hostname ] if hostname),
|
||||||
"-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
|
"-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
|
||||||
"-e", "KAMAL_VERSION=\"#{config.version}\"",
|
"-e", "KAMAL_VERSION=\"#{config.version}\"",
|
||||||
*role_config.env_args,
|
*role.env_args,
|
||||||
*role_config.health_check_args,
|
*role.health_check_args,
|
||||||
*config.logging_args,
|
*role.logging_args,
|
||||||
*config.volume_args,
|
*config.volume_args,
|
||||||
*role_config.asset_volume_args,
|
*role.asset_volume_args,
|
||||||
*role_config.label_args,
|
*role.label_args,
|
||||||
*role_config.option_args,
|
*role.option_args,
|
||||||
config.absolute_image,
|
config.absolute_image,
|
||||||
role_config.cmd
|
role.cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
@@ -57,6 +57,10 @@ class Kamal::Commands::App < Kamal::Commands::Base
|
|||||||
container_id_for(container_name: container_name(version), only_running: only_running)
|
container_id_for(container_name: container_name(version), only_running: only_running)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def container_name(version = nil)
|
||||||
|
[ role.container_prefix, version || config.version ].compact.join("-")
|
||||||
|
end
|
||||||
|
|
||||||
def current_running_version
|
def current_running_version
|
||||||
list_versions("--latest", statuses: ACTIVE_DOCKER_STATUSES)
|
list_versions("--latest", statuses: ACTIVE_DOCKER_STATUSES)
|
||||||
end
|
end
|
||||||
@@ -64,32 +68,24 @@ class Kamal::Commands::App < Kamal::Commands::Base
|
|||||||
def list_versions(*docker_args, statuses: nil)
|
def list_versions(*docker_args, statuses: nil)
|
||||||
pipe \
|
pipe \
|
||||||
docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
|
docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
|
||||||
%(while read line; do echo ${line##{role_config.container_prefix}-}; done) # Extract SHA from "service-role-dest-SHA"
|
%(while read line; do echo ${line##{role.container_prefix}-}; done) # Extract SHA from "service-role-dest-SHA"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def make_env_directory
|
def make_env_directory
|
||||||
make_directory role_config.host_env_directory
|
make_directory role.env.secrets_directory
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_env_file
|
def remove_env_file
|
||||||
[ :rm, "-f", role_config.host_env_file_path ]
|
[ :rm, "-f", role.env.secrets_file ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def container_name(version = nil)
|
|
||||||
[ role_config.container_prefix, version || config.version ].compact.join("-")
|
|
||||||
end
|
|
||||||
|
|
||||||
def filter_args(statuses: nil)
|
def filter_args(statuses: nil)
|
||||||
argumentize "--filter", filters(statuses: statuses)
|
argumentize "--filter", filters(statuses: statuses)
|
||||||
end
|
end
|
||||||
|
|
||||||
def service_role_dest
|
|
||||||
[ config.service, role, config.destination ].compact.join("-")
|
|
||||||
end
|
|
||||||
|
|
||||||
def filters(statuses: nil)
|
def filters(statuses: nil)
|
||||||
[ "label=service=#{config.service}" ].tap do |filters|
|
[ "label=service=#{config.service}" ].tap do |filters|
|
||||||
filters << "label=destination=#{config.destination}" if config.destination
|
filters << "label=destination=#{config.destination}" if config.destination
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
module Kamal::Commands::App::Assets
|
module Kamal::Commands::App::Assets
|
||||||
def extract_assets
|
def extract_assets
|
||||||
asset_container = "#{role_config.container_prefix}-assets"
|
asset_container = "#{role.container_prefix}-assets"
|
||||||
|
|
||||||
combine \
|
combine \
|
||||||
make_directory(role_config.asset_extracted_path),
|
make_directory(role.asset_extracted_path),
|
||||||
[ *docker(:stop, "-t 1", asset_container, "2> /dev/null"), "|| true" ],
|
[ *docker(:stop, "-t 1", asset_container, "2> /dev/null"), "|| true" ],
|
||||||
docker(:run, "--name", asset_container, "--detach", "--rm", config.latest_image, "sleep 1000000"),
|
docker(:run, "--name", asset_container, "--detach", "--rm", config.latest_image, "sleep 1000000"),
|
||||||
docker(:cp, "-L", "#{asset_container}:#{role_config.asset_path}/.", role_config.asset_extracted_path),
|
docker(:cp, "-L", "#{asset_container}:#{role.asset_path}/.", role.asset_extracted_path),
|
||||||
docker(:stop, "-t 1", asset_container),
|
docker(:stop, "-t 1", asset_container),
|
||||||
by: "&&"
|
by: "&&"
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_asset_volumes(old_version: nil)
|
def sync_asset_volumes(old_version: nil)
|
||||||
new_extracted_path, new_volume_path = role_config.asset_extracted_path(config.version), role_config.asset_volume.host_path
|
new_extracted_path, new_volume_path = role.asset_extracted_path(config.version), role.asset_volume.host_path
|
||||||
if old_version.present?
|
if old_version.present?
|
||||||
old_extracted_path, old_volume_path = role_config.asset_extracted_path(old_version), role_config.asset_volume(old_version).host_path
|
old_extracted_path, old_volume_path = role.asset_extracted_path(old_version), role.asset_volume(old_version).host_path
|
||||||
end
|
end
|
||||||
|
|
||||||
commands = [ make_directory(new_volume_path), copy_contents(new_extracted_path, new_volume_path) ]
|
commands = [ make_directory(new_volume_path), copy_contents(new_extracted_path, new_volume_path) ]
|
||||||
@@ -29,8 +29,8 @@ module Kamal::Commands::App::Assets
|
|||||||
|
|
||||||
def clean_up_assets
|
def clean_up_assets
|
||||||
chain \
|
chain \
|
||||||
find_and_remove_older_siblings(role_config.asset_extracted_path),
|
find_and_remove_older_siblings(role.asset_extracted_path),
|
||||||
find_and_remove_older_siblings(role_config.asset_volume_path)
|
find_and_remove_older_siblings(role.asset_volume_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -39,7 +39,7 @@ module Kamal::Commands::App::Assets
|
|||||||
:find,
|
:find,
|
||||||
Pathname.new(path).dirname.to_s,
|
Pathname.new(path).dirname.to_s,
|
||||||
"-maxdepth 1",
|
"-maxdepth 1",
|
||||||
"-name", "'#{role_config.container_prefix}-*'",
|
"-name", "'#{role.container_prefix}-*'",
|
||||||
"!", "-name", Pathname.new(path).basename.to_s,
|
"!", "-name", Pathname.new(path).basename.to_s,
|
||||||
"-exec rm -rf \"{}\" +"
|
"-exec rm -rf \"{}\" +"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
module Kamal::Commands::App::Cord
|
|
||||||
def cord(version:)
|
|
||||||
pipe \
|
|
||||||
docker(:inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", container_name(version)),
|
|
||||||
[:awk, "'$2 == \"#{role_config.cord_volume.container_path}\" {print $1}'"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def tie_cord(cord)
|
|
||||||
create_empty_file(cord)
|
|
||||||
end
|
|
||||||
|
|
||||||
def cut_cord(cord)
|
|
||||||
remove_directory(cord)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def create_empty_file(file)
|
|
||||||
chain \
|
|
||||||
make_directory_for(file),
|
|
||||||
[:touch, file]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -10,9 +10,9 @@ module Kamal::Commands::App::Execution
|
|||||||
docker :run,
|
docker :run,
|
||||||
("-it" if interactive),
|
("-it" if interactive),
|
||||||
"--rm",
|
"--rm",
|
||||||
*role_config&.env_args,
|
*role&.env_args,
|
||||||
*config.volume_args,
|
*config.volume_args,
|
||||||
*role_config&.option_args,
|
*role&.option_args,
|
||||||
config.absolute_image,
|
config.absolute_image,
|
||||||
*command
|
*command
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ module Kamal::Commands::App::Logging
|
|||||||
("grep '#{grep}'" if grep)
|
("grep '#{grep}'" if grep)
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow_logs(host:, grep: nil)
|
def follow_logs(host:, lines: nil, grep: nil)
|
||||||
run_over_ssh \
|
run_over_ssh \
|
||||||
pipe(
|
pipe(
|
||||||
current_running_container_id,
|
current_running_container_id,
|
||||||
"xargs docker logs --timestamps --tail 10 --follow 2>&1",
|
"xargs docker logs --timestamps#{" --tail #{lines}" if lines} --follow 2>&1",
|
||||||
(%(grep "#{grep}") if grep)
|
(%(grep "#{grep}") if grep)
|
||||||
),
|
),
|
||||||
host: host
|
host: host
|
||||||
|
|||||||
@@ -62,14 +62,26 @@ module Kamal::Commands
|
|||||||
combine *commands, by: ">"
|
combine *commands, by: ">"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def any(*commands)
|
||||||
|
combine *commands, by: "||"
|
||||||
|
end
|
||||||
|
|
||||||
def xargs(command)
|
def xargs(command)
|
||||||
[ :xargs, command ].flatten
|
[ :xargs, command ].flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def shell(command)
|
||||||
|
[ :sh, "-c", "'#{command.flatten.join(" ").gsub("'", "'\\''")}'" ]
|
||||||
|
end
|
||||||
|
|
||||||
def docker(*args)
|
def docker(*args)
|
||||||
args.compact.unshift :docker
|
args.compact.unshift :docker
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def git(*args)
|
||||||
|
args.compact.unshift :git
|
||||||
|
end
|
||||||
|
|
||||||
def tags(**details)
|
def tags(**details)
|
||||||
Kamal::Tags.from_config(config, **details)
|
Kamal::Tags.from_config(config, **details)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
|||||||
class BuilderError < StandardError; end
|
class BuilderError < StandardError; end
|
||||||
|
|
||||||
delegate :argumentize, to: Kamal::Utils
|
delegate :argumentize, to: Kamal::Utils
|
||||||
delegate :args, :secrets, :dockerfile, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, to: :builder_config
|
delegate :args, :secrets, :dockerfile, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, :ssh, :git_archive?, to: :builder_config
|
||||||
|
|
||||||
def clean
|
def clean
|
||||||
docker :image, :rm, "--force", config.absolute_image
|
docker :image, :rm, "--force", config.absolute_image
|
||||||
@@ -13,8 +13,18 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
|||||||
docker :pull, config.absolute_image
|
docker :pull, config.absolute_image
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def push
|
||||||
|
if git_archive?
|
||||||
|
pipe \
|
||||||
|
git(:archive, "--format=tar", :HEAD),
|
||||||
|
build_and_push
|
||||||
|
else
|
||||||
|
build_and_push
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def build_options
|
def build_options
|
||||||
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile ]
|
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_ssh ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_context
|
def build_context
|
||||||
@@ -24,7 +34,10 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
|||||||
def validate_image
|
def validate_image
|
||||||
pipe \
|
pipe \
|
||||||
docker(:inspect, "-f", "'{{ .Config.Labels.service }}'", config.absolute_image),
|
docker(:inspect, "-f", "'{{ .Config.Labels.service }}'", config.absolute_image),
|
||||||
[:grep, "-x", config.service, "||", "(echo \"Image #{config.absolute_image} is missing the `service` label\" && exit 1)"]
|
any(
|
||||||
|
[ :grep, "-x", config.service ],
|
||||||
|
"(echo \"Image #{config.absolute_image} is missing the 'service' label\" && exit 1)"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -60,6 +73,10 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_ssh
|
||||||
|
argumentize "--ssh", ssh if ssh.present?
|
||||||
|
end
|
||||||
|
|
||||||
def builder_config
|
def builder_config
|
||||||
config.builder
|
config.builder
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,15 +7,6 @@ class Kamal::Commands::Builder::Multiarch < Kamal::Commands::Builder::Base
|
|||||||
docker :buildx, :rm, builder_name
|
docker :buildx, :rm, builder_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def push
|
|
||||||
docker :buildx, :build,
|
|
||||||
"--push",
|
|
||||||
"--platform", "linux/amd64,linux/arm64",
|
|
||||||
"--builder", builder_name,
|
|
||||||
*build_options,
|
|
||||||
build_context
|
|
||||||
end
|
|
||||||
|
|
||||||
def info
|
def info
|
||||||
combine \
|
combine \
|
||||||
docker(:context, :ls),
|
docker(:context, :ls),
|
||||||
@@ -26,4 +17,21 @@ class Kamal::Commands::Builder::Multiarch < Kamal::Commands::Builder::Base
|
|||||||
def builder_name
|
def builder_name
|
||||||
"kamal-#{config.service}-multiarch"
|
"kamal-#{config.service}-multiarch"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def platform_names
|
||||||
|
if local_arch
|
||||||
|
"linux/#{local_arch}"
|
||||||
|
else
|
||||||
|
"linux/amd64,linux/arm64"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_and_push
|
||||||
|
docker :buildx, :build,
|
||||||
|
"--push",
|
||||||
|
"--platform", platform_names,
|
||||||
|
"--builder", builder_name,
|
||||||
|
*build_options,
|
||||||
|
build_context
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,14 +7,15 @@ class Kamal::Commands::Builder::Native < Kamal::Commands::Builder::Base
|
|||||||
# No-op on native without cache
|
# No-op on native without cache
|
||||||
end
|
end
|
||||||
|
|
||||||
def push
|
def info
|
||||||
|
# No-op on native
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def build_and_push
|
||||||
combine \
|
combine \
|
||||||
docker(:build, *build_options, build_context),
|
docker(:build, *build_options, build_context),
|
||||||
docker(:push, config.absolute_image),
|
docker(:push, config.absolute_image),
|
||||||
docker(:push, config.latest_image)
|
docker(:push, config.latest_image)
|
||||||
end
|
end
|
||||||
|
|
||||||
def info
|
|
||||||
# No-op on native
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ class Kamal::Commands::Builder::Native::Cached < Kamal::Commands::Builder::Nativ
|
|||||||
docker :buildx, :rm, builder_name
|
docker :buildx, :rm, builder_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def push
|
private
|
||||||
|
def build_and_push
|
||||||
docker :buildx, :build,
|
docker :buildx, :build,
|
||||||
"--push",
|
"--push",
|
||||||
*build_options,
|
*build_options,
|
||||||
|
|||||||
@@ -11,15 +11,6 @@ class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Nativ
|
|||||||
remove_buildx
|
remove_buildx
|
||||||
end
|
end
|
||||||
|
|
||||||
def push
|
|
||||||
docker :buildx, :build,
|
|
||||||
"--push",
|
|
||||||
"--platform", platform,
|
|
||||||
"--builder", builder_name,
|
|
||||||
*build_options,
|
|
||||||
build_context
|
|
||||||
end
|
|
||||||
|
|
||||||
def info
|
def info
|
||||||
chain \
|
chain \
|
||||||
docker(:context, :ls),
|
docker(:context, :ls),
|
||||||
@@ -56,4 +47,13 @@ class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Nativ
|
|||||||
def remove_buildx
|
def remove_buildx
|
||||||
docker :buildx, :rm, builder_name
|
docker :buildx, :rm, builder_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_and_push
|
||||||
|
docker :buildx, :build,
|
||||||
|
"--push",
|
||||||
|
"--platform", platform,
|
||||||
|
"--builder", builder_name,
|
||||||
|
*build_options,
|
||||||
|
build_context
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class Kamal::Commands::Docker < Kamal::Commands::Base
|
class Kamal::Commands::Docker < Kamal::Commands::Base
|
||||||
# Install Docker using the https://github.com/docker/docker-install convenience script.
|
# Install Docker using the https://github.com/docker/docker-install convenience script.
|
||||||
def install
|
def install
|
||||||
pipe [ :curl, "-fsSL", "https://get.docker.com" ], :sh
|
pipe get_docker, :sh
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks the Docker client version. Fails if Docker is not installed.
|
# Checks the Docker client version. Fails if Docker is not installed.
|
||||||
@@ -18,4 +18,17 @@ class Kamal::Commands::Docker < Kamal::Commands::Base
|
|||||||
def superuser?
|
def superuser?
|
||||||
[ '[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null' ]
|
[ '[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null' ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_kamal_network
|
||||||
|
docker :network, :create, :kamal
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def get_docker
|
||||||
|
shell \
|
||||||
|
any \
|
||||||
|
[ :curl, "-fsSL", "https://get.docker.com" ],
|
||||||
|
[ :wget, "-O -", "https://get.docker.com" ],
|
||||||
|
[ :echo, "\"exit 1\"" ]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class Kamal::Commands::Healthcheck < Kamal::Commands::Base
|
class Kamal::Commands::Healthcheck < Kamal::Commands::Base
|
||||||
|
|
||||||
def run
|
def run
|
||||||
primary = config.role(config.primary_role)
|
primary = config.role(config.primary_role)
|
||||||
|
|
||||||
@@ -10,7 +9,7 @@ class Kamal::Commands::Healthcheck < Kamal::Commands::Base
|
|||||||
"--label", "service=#{config.healthcheck_service}",
|
"--label", "service=#{config.healthcheck_service}",
|
||||||
"-e", "KAMAL_CONTAINER_NAME=\"#{config.healthcheck_service}\"",
|
"-e", "KAMAL_CONTAINER_NAME=\"#{config.healthcheck_service}\"",
|
||||||
*primary.env_args,
|
*primary.env_args,
|
||||||
*primary.health_check_args(cord: false),
|
*primary.health_check_args,
|
||||||
*config.volume_args,
|
*config.volume_args,
|
||||||
*primary.option_args,
|
*primary.option_args,
|
||||||
config.absolute_image,
|
config.absolute_image,
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ class Kamal::Commands::Lock < Kamal::Commands::Base
|
|||||||
read_lock_details
|
read_lock_details
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_locks_directory
|
||||||
|
[ :mkdir, "-p", locks_dir ]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def write_lock_details(message, version)
|
def write_lock_details(message, version)
|
||||||
write \
|
write \
|
||||||
@@ -40,12 +44,18 @@ class Kamal::Commands::Lock < Kamal::Commands::Base
|
|||||||
"/dev/null"
|
"/dev/null"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def locks_dir
|
||||||
|
File.join(config.run_directory, "locks")
|
||||||
|
end
|
||||||
|
|
||||||
def lock_dir
|
def lock_dir
|
||||||
"#{config.run_directory}/lock-#{config.service}"
|
dir_name = [ config.service, config.destination ].compact.join("-")
|
||||||
|
|
||||||
|
File.join(locks_dir, dir_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def lock_details_file
|
def lock_details_file
|
||||||
[lock_dir, :details].join("/")
|
File.join(lock_dir, "details")
|
||||||
end
|
end
|
||||||
|
|
||||||
def lock_details(message, version)
|
def lock_details(message, version)
|
||||||
|
|||||||
116
lib/kamal/commands/proxy.rb
Normal file
116
lib/kamal/commands/proxy.rb
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
class Kamal::Commands::Proxy < Kamal::Commands::Base
|
||||||
|
CONTAINER_PORT = 80
|
||||||
|
|
||||||
|
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||||
|
|
||||||
|
DEFAULT_IMAGE = "dmcbreen/mproxy:latest"
|
||||||
|
|
||||||
|
def run
|
||||||
|
docker :run,
|
||||||
|
"--name", container_name,
|
||||||
|
"--detach",
|
||||||
|
"--restart", "unless-stopped",
|
||||||
|
"--network kamal",
|
||||||
|
*publish_args,
|
||||||
|
"--volume", "/var/run/docker.sock:/var/run/docker.sock",
|
||||||
|
*config.logging_args,
|
||||||
|
*label_args,
|
||||||
|
*docker_options_args,
|
||||||
|
image,
|
||||||
|
*cmd_option_args
|
||||||
|
end
|
||||||
|
|
||||||
|
def start
|
||||||
|
docker :container, :start, container_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop
|
||||||
|
docker :container, :stop, container_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_or_run
|
||||||
|
combine start, run, by: "||"
|
||||||
|
end
|
||||||
|
|
||||||
|
def deploy(version)
|
||||||
|
docker :exec, container_name, :mproxy, :deploy, version
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove(version)
|
||||||
|
docker :exec, container_name, :mproxy, :remove, version
|
||||||
|
end
|
||||||
|
|
||||||
|
def info
|
||||||
|
docker :ps, "--filter", "name=^#{container_name}$"
|
||||||
|
end
|
||||||
|
|
||||||
|
def logs(since: nil, lines: nil, grep: nil)
|
||||||
|
pipe \
|
||||||
|
docker(:logs, container_name, (" --since #{since}" if since), (" --tail #{lines}" if lines), "--timestamps", "2>&1"),
|
||||||
|
("grep '#{grep}'" if grep)
|
||||||
|
end
|
||||||
|
|
||||||
|
def follow_logs(host:, grep: nil)
|
||||||
|
run_over_ssh pipe(
|
||||||
|
docker(:logs, container_name, "--timestamps", "--tail", "10", "--follow", "2>&1"),
|
||||||
|
(%(grep "#{grep}") if grep)
|
||||||
|
).join(" "), host: host
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_container
|
||||||
|
docker :container, :prune, "--force", "--filter", container_filter
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_image
|
||||||
|
docker :image, :prune, "--all", "--force", "--filter", image_filter
|
||||||
|
end
|
||||||
|
|
||||||
|
def port
|
||||||
|
"#{host_port}:#{CONTAINER_PORT}"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def container_filter
|
||||||
|
"label=org.opencontainers.image.title=mproxy"
|
||||||
|
end
|
||||||
|
|
||||||
|
def image_filter
|
||||||
|
"label=org.opencontainers.image.title=mproxy"
|
||||||
|
end
|
||||||
|
|
||||||
|
def publish_args
|
||||||
|
argumentize "--publish", port unless config.proxy["publish"] == false
|
||||||
|
end
|
||||||
|
|
||||||
|
def label_args
|
||||||
|
argumentize "--label", labels
|
||||||
|
end
|
||||||
|
|
||||||
|
def labels
|
||||||
|
config.proxy["labels"] || {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def image
|
||||||
|
config.proxy.fetch("image") { DEFAULT_IMAGE }
|
||||||
|
end
|
||||||
|
|
||||||
|
def docker_options_args
|
||||||
|
optionize(config.proxy["options"] || {})
|
||||||
|
end
|
||||||
|
|
||||||
|
def cmd_option_args
|
||||||
|
optionize cmd_args, with: "="
|
||||||
|
end
|
||||||
|
|
||||||
|
def cmd_args
|
||||||
|
config.proxy["args"] || {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def host_port
|
||||||
|
config.proxy["host_port"] || CONTAINER_PORT
|
||||||
|
end
|
||||||
|
|
||||||
|
def container_name
|
||||||
|
"mproxy"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -13,10 +13,10 @@ class Kamal::Commands::Prune < Kamal::Commands::Base
|
|||||||
"while read image tag; do docker rmi $tag; done"
|
"while read image tag; do docker rmi $tag; done"
|
||||||
end
|
end
|
||||||
|
|
||||||
def app_containers(keep_last: 5)
|
def app_containers(retain:)
|
||||||
pipe \
|
pipe \
|
||||||
docker(:ps, "-q", "-a", *service_filter, *stopped_containers_filters),
|
docker(:ps, "-q", "-a", *service_filter, *stopped_containers_filters),
|
||||||
"tail -n +#{keep_last + 1}",
|
"tail -n +#{retain + 1}",
|
||||||
"while read container_id; do docker rm $container_id; done"
|
"while read container_id; do docker rm $container_id; done"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ class Kamal::Commands::Registry < Kamal::Commands::Base
|
|||||||
delegate :registry, to: :config
|
delegate :registry, to: :config
|
||||||
|
|
||||||
def login
|
def login
|
||||||
docker :login, registry["server"], "-u", sensitive(lookup("username")), "-p", sensitive(lookup("password"))
|
docker :login,
|
||||||
|
registry["server"],
|
||||||
|
"-u", sensitive(Kamal::Utils.escape_shell_value(lookup("username"))),
|
||||||
|
"-p", sensitive(Kamal::Utils.escape_shell_value(lookup("password")))
|
||||||
end
|
end
|
||||||
|
|
||||||
def logout
|
def logout
|
||||||
|
|||||||
@@ -1,130 +0,0 @@
|
|||||||
class Kamal::Commands::Traefik < Kamal::Commands::Base
|
|
||||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
|
||||||
|
|
||||||
DEFAULT_IMAGE = "traefik:v2.9"
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
def run
|
|
||||||
docker :run, "--name traefik",
|
|
||||||
"--detach",
|
|
||||||
"--restart", "unless-stopped",
|
|
||||||
*publish_args,
|
|
||||||
"--volume", "/var/run/docker.sock:/var/run/docker.sock",
|
|
||||||
*env_args,
|
|
||||||
*config.logging_args,
|
|
||||||
*label_args,
|
|
||||||
*docker_options_args,
|
|
||||||
image,
|
|
||||||
"--providers.docker",
|
|
||||||
*cmd_option_args
|
|
||||||
end
|
|
||||||
|
|
||||||
def start
|
|
||||||
docker :container, :start, "traefik"
|
|
||||||
end
|
|
||||||
|
|
||||||
def stop
|
|
||||||
docker :container, :stop, "traefik"
|
|
||||||
end
|
|
||||||
|
|
||||||
def start_or_run
|
|
||||||
combine start, run, by: "||"
|
|
||||||
end
|
|
||||||
|
|
||||||
def info
|
|
||||||
docker :ps, "--filter", "name=^traefik$"
|
|
||||||
end
|
|
||||||
|
|
||||||
def logs(since: nil, lines: nil, grep: nil)
|
|
||||||
pipe \
|
|
||||||
docker(:logs, "traefik", (" --since #{since}" if since), (" --tail #{lines}" if lines), "--timestamps", "2>&1"),
|
|
||||||
("grep '#{grep}'" if grep)
|
|
||||||
end
|
|
||||||
|
|
||||||
def follow_logs(host:, grep: nil)
|
|
||||||
run_over_ssh pipe(
|
|
||||||
docker(:logs, "traefik", "--timestamps", "--tail", "10", "--follow", "2>&1"),
|
|
||||||
(%(grep "#{grep}") if grep)
|
|
||||||
).join(" "), host: host
|
|
||||||
end
|
|
||||||
|
|
||||||
def remove_container
|
|
||||||
docker :container, :prune, "--force", "--filter", "label=org.opencontainers.image.title=Traefik"
|
|
||||||
end
|
|
||||||
|
|
||||||
def remove_image
|
|
||||||
docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=Traefik"
|
|
||||||
end
|
|
||||||
|
|
||||||
def port
|
|
||||||
"#{host_port}:#{CONTAINER_PORT}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def env_file
|
|
||||||
Kamal::EnvFile.new(config.traefik.fetch("env", {}))
|
|
||||||
end
|
|
||||||
|
|
||||||
def host_env_file_path
|
|
||||||
File.join host_env_directory, "traefik.env"
|
|
||||||
end
|
|
||||||
|
|
||||||
def make_env_directory
|
|
||||||
make_directory(host_env_directory)
|
|
||||||
end
|
|
||||||
|
|
||||||
def remove_env_file
|
|
||||||
[:rm, "-f", host_env_file_path]
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def publish_args
|
|
||||||
argumentize "--publish", port unless config.traefik["publish"] == false
|
|
||||||
end
|
|
||||||
|
|
||||||
def label_args
|
|
||||||
argumentize "--label", labels
|
|
||||||
end
|
|
||||||
|
|
||||||
def env_args
|
|
||||||
argumentize "--env-file", host_env_file_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def host_env_directory
|
|
||||||
File.join config.host_env_directory, "traefik"
|
|
||||||
end
|
|
||||||
|
|
||||||
def labels
|
|
||||||
DEFAULT_LABELS.merge(config.traefik["labels"] || {})
|
|
||||||
end
|
|
||||||
|
|
||||||
def image
|
|
||||||
config.traefik.fetch("image") { DEFAULT_IMAGE }
|
|
||||||
end
|
|
||||||
|
|
||||||
def docker_options_args
|
|
||||||
optionize(config.traefik["options"] || {})
|
|
||||||
end
|
|
||||||
|
|
||||||
def cmd_option_args
|
|
||||||
if args = config.traefik["args"]
|
|
||||||
optionize DEFAULT_ARGS.merge(args), with: "="
|
|
||||||
else
|
|
||||||
optionize DEFAULT_ARGS, with: "="
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def host_port
|
|
||||||
config.traefik["host_port"] || CONTAINER_PORT
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -6,7 +6,7 @@ require "erb"
|
|||||||
require "net/ssh/proxy/jump"
|
require "net/ssh/proxy/jump"
|
||||||
|
|
||||||
class Kamal::Configuration
|
class Kamal::Configuration
|
||||||
delegate :service, :image, :servers, :env, :labels, :registry, :stop_wait_time, :hooks_path, to: :raw_config, allow_nil: true
|
delegate :service, :image, :port, :servers, :labels, :registry, :stop_wait_time, :hooks_path, :logging, to: :raw_config, allow_nil: true
|
||||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||||
|
|
||||||
attr_reader :destination, :raw_config
|
attr_reader :destination, :raw_config
|
||||||
@@ -92,19 +92,31 @@ class Kamal::Configuration
|
|||||||
end
|
end
|
||||||
|
|
||||||
def primary_host
|
def primary_host
|
||||||
role(primary_role)&.primary_host
|
primary_role&.primary_host
|
||||||
end
|
end
|
||||||
|
|
||||||
def traefik_roles
|
def primary_role_name
|
||||||
roles.select(&:running_traefik?)
|
raw_config.primary_role || "web"
|
||||||
end
|
end
|
||||||
|
|
||||||
def traefik_role_names
|
def primary_role
|
||||||
traefik_roles.flat_map(&:name)
|
role(primary_role_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def traefik_hosts
|
def allow_empty_roles?
|
||||||
traefik_roles.flat_map(&:hosts).uniq
|
raw_config.allow_empty_roles
|
||||||
|
end
|
||||||
|
|
||||||
|
def proxy_roles
|
||||||
|
roles.select(&:running_proxy?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def proxy_role_names
|
||||||
|
proxy_roles.flat_map(&:name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def proxy_hosts
|
||||||
|
proxy_roles.flat_map(&:hosts).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def repository
|
def repository
|
||||||
@@ -127,6 +139,10 @@ class Kamal::Configuration
|
|||||||
raw_config.require_destination
|
raw_config.require_destination
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def retain_containers
|
||||||
|
raw_config.retain_containers || 5
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def volume_args
|
def volume_args
|
||||||
if raw_config.volumes.present?
|
if raw_config.volumes.present?
|
||||||
@@ -137,9 +153,9 @@ class Kamal::Configuration
|
|||||||
end
|
end
|
||||||
|
|
||||||
def logging_args
|
def logging_args
|
||||||
if raw_config.logging.present?
|
if logging.present?
|
||||||
optionize({ "log-driver" => raw_config.logging["driver"] }.compact) +
|
optionize({ "log-driver" => logging["driver"] }.compact) +
|
||||||
argumentize("--log-opt", raw_config.logging["options"])
|
argumentize("--log-opt", logging["options"])
|
||||||
else
|
else
|
||||||
argumentize("--log-opt", { "max-size" => "10m" })
|
argumentize("--log-opt", { "max-size" => "10m" })
|
||||||
end
|
end
|
||||||
@@ -154,8 +170,8 @@ class Kamal::Configuration
|
|||||||
Kamal::Configuration::Builder.new(config: self)
|
Kamal::Configuration::Builder.new(config: self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def traefik
|
def proxy
|
||||||
raw_config.traefik || {}
|
raw_config.proxy || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def ssh
|
def ssh
|
||||||
@@ -168,7 +184,7 @@ class Kamal::Configuration
|
|||||||
|
|
||||||
|
|
||||||
def healthcheck
|
def healthcheck
|
||||||
{ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 }.merge(raw_config.healthcheck || {})
|
{ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "log_lines" => 50 }.merge(raw_config.healthcheck || {})
|
||||||
end
|
end
|
||||||
|
|
||||||
def healthcheck_service
|
def healthcheck_service
|
||||||
@@ -200,25 +216,22 @@ class Kamal::Configuration
|
|||||||
raw_config.hooks_path || ".kamal/hooks"
|
raw_config.hooks_path || ".kamal/hooks"
|
||||||
end
|
end
|
||||||
|
|
||||||
def host_env_directory
|
|
||||||
"#{run_directory}/env"
|
|
||||||
end
|
|
||||||
|
|
||||||
def asset_path
|
def asset_path
|
||||||
raw_config.asset_path
|
raw_config.asset_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def primary_role
|
|
||||||
raw_config.primary_role || "web"
|
def host_env_directory
|
||||||
|
"#{run_directory}/env"
|
||||||
end
|
end
|
||||||
|
|
||||||
def allow_empty_roles?
|
def env
|
||||||
raw_config.allow_empty_roles
|
raw_config.env || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def valid?
|
def valid?
|
||||||
ensure_destination_if_required && ensure_required_keys_present && ensure_valid_kamal_version
|
ensure_destination_if_required && ensure_required_keys_present && ensure_valid_kamal_version && ensure_retain_containers_valid && ensure_valid_service_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_h
|
def to_h
|
||||||
@@ -264,12 +277,12 @@ class Kamal::Configuration
|
|||||||
raise ArgumentError, "You must specify a password for the registry in config/deploy.yml (or set the ENV variable if that's used)"
|
raise ArgumentError, "You must specify a password for the registry in config/deploy.yml (or set the ENV variable if that's used)"
|
||||||
end
|
end
|
||||||
|
|
||||||
unless role_names.include?(primary_role)
|
unless role_names.include?(primary_role_name)
|
||||||
raise ArgumentError, "The primary_role #{primary_role} isn't defined"
|
raise ArgumentError, "The primary_role #{primary_role_name} isn't defined"
|
||||||
end
|
end
|
||||||
|
|
||||||
if role(primary_role).hosts.empty?
|
if primary_role.hosts.empty?
|
||||||
raise ArgumentError, "No servers specified for the #{primary_role} primary_role"
|
raise ArgumentError, "No servers specified for the #{primary_role.name} primary_role"
|
||||||
end
|
end
|
||||||
|
|
||||||
unless allow_empty_roles?
|
unless allow_empty_roles?
|
||||||
@@ -283,6 +296,12 @@ class Kamal::Configuration
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_valid_service_name
|
||||||
|
raise ArgumentError, "Service name can only include alphanumeric characters, hyphens, and underscores" unless raw_config[:service] =~ /^[a-z0-9_-]+$/
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def ensure_valid_kamal_version
|
def ensure_valid_kamal_version
|
||||||
if minimum_version && Gem::Version.new(minimum_version) > Gem::Version.new(Kamal::VERSION)
|
if minimum_version && Gem::Version.new(minimum_version) > Gem::Version.new(Kamal::VERSION)
|
||||||
raise ArgumentError, "Current version is #{Kamal::VERSION}, minimum required is #{minimum_version}"
|
raise ArgumentError, "Current version is #{Kamal::VERSION}, minimum required is #{minimum_version}"
|
||||||
@@ -291,6 +310,12 @@ class Kamal::Configuration
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_retain_containers_valid
|
||||||
|
raise ArgumentError, "Must retain at least 1 container" if retain_containers < 1
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def role_names
|
def role_names
|
||||||
raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort
|
raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort
|
||||||
@@ -299,7 +324,10 @@ class Kamal::Configuration
|
|||||||
def git_version
|
def git_version
|
||||||
@git_version ||=
|
@git_version ||=
|
||||||
if Kamal::Git.used?
|
if Kamal::Git.used?
|
||||||
[ Kamal::Git.revision, Kamal::Git.uncommitted_changes.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : "" ].join
|
if Kamal::Git.uncommitted_changes.present? && !builder.git_archive?
|
||||||
|
uncommitted_suffix = "_uncommitted_#{SecureRandom.hex(8)}"
|
||||||
|
end
|
||||||
|
[ Kamal::Git.revision, uncommitted_suffix ].compact.join
|
||||||
else
|
else
|
||||||
raise "Can't use commit hash as version, no git repository found in #{Dir.pwd}"
|
raise "Can't use commit hash as version, no git repository found in #{Dir.pwd}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class Kamal::Configuration::Accessory
|
|||||||
end
|
end
|
||||||
|
|
||||||
def service_name
|
def service_name
|
||||||
"#{config.service}-#{name}"
|
specifics["service"] || "#{config.service}-#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def image
|
def image
|
||||||
@@ -42,23 +42,13 @@ class Kamal::Configuration::Accessory
|
|||||||
end
|
end
|
||||||
|
|
||||||
def env
|
def env
|
||||||
specifics["env"] || {}
|
Kamal::Configuration::Env.from_config \
|
||||||
end
|
config: specifics.fetch("env", {}),
|
||||||
|
secrets_file: File.join(config.host_env_directory, "accessories", "#{service_name}.env")
|
||||||
def env_file
|
|
||||||
Kamal::EnvFile.new(env)
|
|
||||||
end
|
|
||||||
|
|
||||||
def host_env_directory
|
|
||||||
File.join config.host_env_directory, "accessories"
|
|
||||||
end
|
|
||||||
|
|
||||||
def host_env_file_path
|
|
||||||
File.join host_env_directory, "#{service_name}.env"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def env_args
|
def env_args
|
||||||
argumentize "--env-file", host_env_file_path
|
env.args
|
||||||
end
|
end
|
||||||
|
|
||||||
def files
|
def files
|
||||||
@@ -111,10 +101,10 @@ class Kamal::Configuration::Accessory
|
|||||||
end
|
end
|
||||||
|
|
||||||
def with_clear_env_loaded
|
def with_clear_env_loaded
|
||||||
(env["clear"] || env).each { |k, v| ENV[k] = v }
|
env.clear.each { |k, v| ENV[k] = v }
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
(env["clear"] || env).each { |k, v| ENV.delete(k) }
|
env.clear.each { |k, v| ENV.delete(k) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_dynamic_file(local_file)
|
def read_dynamic_file(local_file)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class Kamal::Configuration::Boot
|
|||||||
limit = @options["limit"]
|
limit = @options["limit"]
|
||||||
|
|
||||||
if limit.to_s.end_with?("%")
|
if limit.to_s.end_with?("%")
|
||||||
@host_count * limit.to_i / 100
|
[ @host_count * limit.to_i / 100, 1 ].max
|
||||||
else
|
else
|
||||||
limit
|
limit
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class Kamal::Configuration::Builder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def context
|
def context
|
||||||
@options["context"] || "."
|
@options["context"] || (git_archive? ? "-" : ".")
|
||||||
end
|
end
|
||||||
|
|
||||||
def local_arch
|
def local_arch
|
||||||
@@ -81,6 +81,14 @@ class Kamal::Configuration::Builder
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ssh
|
||||||
|
@options["ssh"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def git_archive?
|
||||||
|
Kamal::Git.used? && @options["context"].nil?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def valid?
|
def valid?
|
||||||
if @options["cache"] && @options["cache"]["type"]
|
if @options["cache"] && @options["cache"]["type"]
|
||||||
|
|||||||
40
lib/kamal/configuration/env.rb
Normal file
40
lib/kamal/configuration/env.rb
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
class Kamal::Configuration::Env
|
||||||
|
attr_reader :secrets_keys, :clear, :secrets_file
|
||||||
|
delegate :argumentize, to: Kamal::Utils
|
||||||
|
|
||||||
|
def self.from_config(config:, secrets_file: nil)
|
||||||
|
secrets_keys = config.fetch("secret", [])
|
||||||
|
clear = config.fetch("clear", config.key?("secret") ? {} : config)
|
||||||
|
|
||||||
|
new clear: clear, secrets_keys: secrets_keys, secrets_file: secrets_file
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(clear:, secrets_keys:, secrets_file:)
|
||||||
|
@clear = clear
|
||||||
|
@secrets_keys = secrets_keys
|
||||||
|
@secrets_file = secrets_file
|
||||||
|
end
|
||||||
|
|
||||||
|
def args
|
||||||
|
[ "--env-file", secrets_file, *argumentize("--env", clear) ]
|
||||||
|
end
|
||||||
|
|
||||||
|
def secrets_io
|
||||||
|
StringIO.new(Kamal::EnvFile.new(secrets).to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
def secrets
|
||||||
|
@secrets ||= secrets_keys.to_h { |key| [ key, ENV.fetch(key) ] }
|
||||||
|
end
|
||||||
|
|
||||||
|
def secrets_directory
|
||||||
|
File.dirname(secrets_file)
|
||||||
|
end
|
||||||
|
|
||||||
|
def merge(other)
|
||||||
|
self.class.new \
|
||||||
|
clear: @clear.merge(other.clear),
|
||||||
|
secrets_keys: @secrets_keys | other.secrets_keys,
|
||||||
|
secrets_file: secrets_file
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
class Kamal::Configuration::Role
|
class Kamal::Configuration::Role
|
||||||
CORD_FILE = "cord"
|
|
||||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||||
|
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
|
alias to_s name
|
||||||
|
|
||||||
def initialize(name, config:)
|
def initialize(name, config:)
|
||||||
@name, @config = name.inquiry, config
|
@name, @config = name.inquiry, config
|
||||||
@@ -16,6 +16,10 @@ class Kamal::Configuration::Role
|
|||||||
@hosts ||= extract_hosts_from_config
|
@hosts ||= extract_hosts_from_config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def port
|
||||||
|
specializations["port"] || config.port || "3000"
|
||||||
|
end
|
||||||
|
|
||||||
def cmd
|
def cmd
|
||||||
specializations["cmd"]
|
specializations["cmd"]
|
||||||
end
|
end
|
||||||
@@ -29,36 +33,32 @@ class Kamal::Configuration::Role
|
|||||||
end
|
end
|
||||||
|
|
||||||
def labels
|
def labels
|
||||||
default_labels.merge(traefik_labels).merge(custom_labels)
|
default_labels.merge(custom_labels)
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_args
|
def label_args
|
||||||
argumentize "--label", labels
|
argumentize "--label", labels
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def logging_args
|
||||||
|
args = config.logging || {}
|
||||||
|
args.deep_merge!(specializations["logging"]) if specializations["logging"].present?
|
||||||
|
|
||||||
|
if args.any?
|
||||||
|
optionize({ "log-driver" => args["driver"] }.compact) +
|
||||||
|
argumentize("--log-opt", args["options"])
|
||||||
|
else
|
||||||
|
config.logging_args
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def env
|
def env
|
||||||
if config.env && config.env["secret"]
|
@env ||= base_env.merge(specialized_env)
|
||||||
merged_env_with_secrets
|
|
||||||
else
|
|
||||||
merged_env
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def env_file
|
|
||||||
Kamal::EnvFile.new(env)
|
|
||||||
end
|
|
||||||
|
|
||||||
def host_env_directory
|
|
||||||
File.join config.host_env_directory, "roles"
|
|
||||||
end
|
|
||||||
|
|
||||||
def host_env_file_path
|
|
||||||
File.join host_env_directory, "#{[config.service, name, config.destination].compact.join("-")}.env"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def env_args
|
def env_args
|
||||||
argumentize "--env-file", host_env_file_path
|
env.args
|
||||||
end
|
end
|
||||||
|
|
||||||
def asset_volume_args
|
def asset_volume_args
|
||||||
@@ -66,14 +66,9 @@ class Kamal::Configuration::Role
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def health_check_args(cord: true)
|
def health_check_args
|
||||||
if health_check_cmd.present?
|
if health_check_cmd.present?
|
||||||
if cord && uses_cord?
|
|
||||||
optionize({ "health-cmd" => health_check_cmd_with_cord, "health-interval" => health_check_interval })
|
|
||||||
.concat(cord_volume.docker_args)
|
|
||||||
else
|
|
||||||
optionize({ "health-cmd" => health_check_cmd, "health-interval" => health_check_interval })
|
optionize({ "health-cmd" => health_check_cmd, "health-interval" => health_check_interval })
|
||||||
end
|
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
@@ -83,54 +78,21 @@ class Kamal::Configuration::Role
|
|||||||
health_check_options["cmd"] || http_health_check(port: health_check_options["port"], path: health_check_options["path"])
|
health_check_options["cmd"] || http_health_check(port: health_check_options["port"], path: health_check_options["path"])
|
||||||
end
|
end
|
||||||
|
|
||||||
def health_check_cmd_with_cord
|
|
||||||
"(#{health_check_cmd}) && (stat #{cord_container_file} > /dev/null || exit 1)"
|
|
||||||
end
|
|
||||||
|
|
||||||
def health_check_interval
|
def health_check_interval
|
||||||
health_check_options["interval"] || "1s"
|
health_check_options["interval"] || "1s"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def running_traefik?
|
def running_proxy?
|
||||||
if specializations["traefik"].nil?
|
if specializations["proxy"].nil?
|
||||||
primary?
|
primary?
|
||||||
else
|
else
|
||||||
specializations["traefik"]
|
specializations["proxy"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def primary?
|
def primary?
|
||||||
@config.primary_role == name
|
self == @config.primary_role
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def uses_cord?
|
|
||||||
running_traefik? && cord_volume && health_check_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 = health_check_options["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
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -148,7 +110,7 @@ class Kamal::Configuration::Role
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assets?
|
def assets?
|
||||||
asset_path.present? && running_traefik?
|
asset_path.present? && running_proxy?
|
||||||
end
|
end
|
||||||
|
|
||||||
def asset_volume(version = nil)
|
def asset_volume(version = nil)
|
||||||
@@ -179,32 +141,7 @@ class Kamal::Configuration::Role
|
|||||||
end
|
end
|
||||||
|
|
||||||
def default_labels
|
def default_labels
|
||||||
if config.destination
|
|
||||||
{ "service" => config.service, "role" => name, "destination" => config.destination }
|
{ "service" => config.service, "role" => name, "destination" => config.destination }
|
||||||
else
|
|
||||||
{ "service" => config.service, "role" => name }
|
|
||||||
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
|
|
||||||
[ config.service, name, config.destination ].compact.join("-")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_labels
|
def custom_labels
|
||||||
@@ -223,24 +160,14 @@ class Kamal::Configuration::Role
|
|||||||
end
|
end
|
||||||
|
|
||||||
def specialized_env
|
def specialized_env
|
||||||
specializations["env"] || {}
|
Kamal::Configuration::Env.from_config config: specializations.fetch("env", {})
|
||||||
end
|
|
||||||
|
|
||||||
def merged_env
|
|
||||||
config.env&.merge(specialized_env) || {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Secrets are stored in an array, which won't merge by default, so have to do it by hand.
|
# Secrets are stored in an array, which won't merge by default, so have to do it by hand.
|
||||||
def merged_env_with_secrets
|
def base_env
|
||||||
merged_env.tap do |new_env|
|
Kamal::Configuration::Env.from_config \
|
||||||
new_env["secret"] = Array(config.env["secret"]) + Array(specialized_env["secret"])
|
config: config.env,
|
||||||
|
secrets_file: File.join(config.host_env_directory, "roles", "#{container_prefix}.env")
|
||||||
# If there's no secret/clear split, everything is clear
|
|
||||||
clear_app_env = config.env["secret"] ? Array(config.env["clear"]) : Array(config.env["clear"] || config.env)
|
|
||||||
clear_role_env = specialized_env["secret"] ? Array(specialized_env["clear"]) : Array(specialized_env["clear"] || specialized_env)
|
|
||||||
|
|
||||||
new_env["clear"] = clear_app_env.to_h.merge(clear_role_env.to_h)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def http_health_check(port:, path:)
|
def http_health_check(port:, path:)
|
||||||
@@ -250,7 +177,7 @@ class Kamal::Configuration::Role
|
|||||||
def health_check_options
|
def health_check_options
|
||||||
@health_check_options ||= begin
|
@health_check_options ||= begin
|
||||||
options = specializations["healthcheck"] || {}
|
options = specializations["healthcheck"] || {}
|
||||||
options = config.healthcheck.merge(options) if running_traefik?
|
options = config.healthcheck.merge(options) if running_proxy?
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,19 +6,9 @@ class Kamal::EnvFile
|
|||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
env_file = StringIO.new.tap do |contents|
|
env_file = StringIO.new.tap do |contents|
|
||||||
if (secrets = @env["secret"]).present?
|
@env.each do |key, value|
|
||||||
@env.fetch("secret", @env)&.each do |key|
|
|
||||||
contents << docker_env_file_line(key, ENV.fetch(key))
|
|
||||||
end
|
|
||||||
|
|
||||||
@env["clear"]&.each do |key, value|
|
|
||||||
contents << docker_env_file_line(key, value)
|
contents << docker_env_file_line(key, value)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
@env.fetch("clear", @env)&.each do |key, value|
|
|
||||||
contents << docker_env_file_line(key, value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end.string
|
end.string
|
||||||
|
|
||||||
# Ensure the file has some contents to avoid the SSHKIT empty file warning
|
# Ensure the file has some contents to avoid the SSHKIT empty file warning
|
||||||
@@ -29,7 +19,7 @@ class Kamal::EnvFile
|
|||||||
|
|
||||||
private
|
private
|
||||||
def docker_env_file_line(key, value)
|
def docker_env_file_line(key, value)
|
||||||
"#{key.to_s}=#{escape_docker_env_file_value(value)}\n"
|
"#{key}=#{escape_docker_env_file_value(value)}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Escape a value to make it safe to dump in a docker file.
|
# Escape a value to make it safe to dump in a docker file.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
require "sshkit"
|
require "sshkit"
|
||||||
require "sshkit/dsl"
|
require "sshkit/dsl"
|
||||||
|
require "net/scp"
|
||||||
require "active_support/core_ext/hash/deep_merge"
|
require "active_support/core_ext/hash/deep_merge"
|
||||||
require "json"
|
require "json"
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ module Kamal::Utils
|
|||||||
Array(filters).select do |filter|
|
Array(filters).select do |filter|
|
||||||
matches += Array(items).select do |item|
|
matches += Array(items).select do |item|
|
||||||
# Only allow * for a wildcard
|
# Only allow * for a wildcard
|
||||||
pattern = Regexp.escape(filter).gsub('\*', '.*')
|
pattern = Regexp.escape(filter).gsub('\*', ".*")
|
||||||
# items are roles or hosts
|
# items are roles or hosts
|
||||||
(item.respond_to?(:name) ? item.name : item).match(/^#{pattern}$/)
|
(item.respond_to?(:name) ? item.name : item).match(/^#{pattern}$/)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Kamal
|
module Kamal
|
||||||
VERSION = "1.3.1"
|
VERSION = "1.4.0"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class CliAccessoryTest < CliTestCase
|
|||||||
|
|
||||||
run_command("boot", "mysql").tap do |output|
|
run_command("boot", "mysql").tap do |output|
|
||||||
assert_match /docker login.*on 1.1.1.3/, output
|
assert_match /docker login.*on 1.1.1.3/, output
|
||||||
assert_match "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 3306:3306 --env-file .kamal/env/accessories/app-mysql.env --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output
|
assert_match "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 3306:3306 --env-file .kamal/env/accessories/app-mysql.env --env MYSQL_ROOT_HOST=\"%\" --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ class CliAccessoryTest < CliTestCase
|
|||||||
assert_match /docker login.*on 1.1.1.3/, output
|
assert_match /docker login.*on 1.1.1.3/, output
|
||||||
assert_match /docker login.*on 1.1.1.1/, output
|
assert_match /docker login.*on 1.1.1.1/, output
|
||||||
assert_match /docker login.*on 1.1.1.2/, output
|
assert_match /docker login.*on 1.1.1.2/, output
|
||||||
assert_match "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 3306:3306 --env-file .kamal/env/accessories/app-mysql.env --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output
|
assert_match "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 3306:3306 --env-file .kamal/env/accessories/app-mysql.env --env MYSQL_ROOT_HOST=\"%\" --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output
|
||||||
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
||||||
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.2", output
|
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.2", output
|
||||||
end
|
end
|
||||||
@@ -79,6 +79,10 @@ class CliAccessoryTest < CliTestCase
|
|||||||
assert_match "docker ps --filter label=service=app-mysql", run_command("details", "mysql")
|
assert_match "docker ps --filter label=service=app-mysql", run_command("details", "mysql")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "details with non-existent accessory" do
|
||||||
|
assert_equal "No accessory by the name of 'hello' (options: mysql and redis)", stderred { run_command("details", "hello") }
|
||||||
|
end
|
||||||
|
|
||||||
test "details with all" do
|
test "details with all" do
|
||||||
run_command("details", "all").tap do |output|
|
run_command("details", "all").tap do |output|
|
||||||
assert_match "docker ps --filter label=service=app-mysql", output
|
assert_match "docker ps --filter label=service=app-mysql", output
|
||||||
@@ -148,6 +152,30 @@ class CliAccessoryTest < CliTestCase
|
|||||||
assert_match "rm -rf app-mysql", run_command("remove_service_directory", "mysql")
|
assert_match "rm -rf app-mysql", run_command("remove_service_directory", "mysql")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "hosts param respected" do
|
||||||
|
Kamal::Cli::Accessory.any_instance.expects(:directories).with("redis")
|
||||||
|
Kamal::Cli::Accessory.any_instance.expects(:upload).with("redis")
|
||||||
|
|
||||||
|
run_command("boot", "redis", "--hosts", "1.1.1.1").tap do |output|
|
||||||
|
assert_match /docker login.*on 1.1.1.1/, output
|
||||||
|
assert_no_match /docker login.*on 1.1.1.2/, output
|
||||||
|
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
||||||
|
assert_no_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.2", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "hosts param intersected with configuration" do
|
||||||
|
Kamal::Cli::Accessory.any_instance.expects(:directories).with("redis")
|
||||||
|
Kamal::Cli::Accessory.any_instance.expects(:upload).with("redis")
|
||||||
|
|
||||||
|
run_command("boot", "redis", "--hosts", "1.1.1.1,1.1.1.3").tap do |output|
|
||||||
|
assert_match /docker login.*on 1.1.1.1/, output
|
||||||
|
assert_no_match /docker login.*on 1.1.1.3/, output
|
||||||
|
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
||||||
|
assert_no_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.3", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def run_command(*command)
|
def run_command(*command)
|
||||||
stdouted { Kamal::Cli::Accessory.start([ *command, "-c", "test/fixtures/deploy_with_accessories.yml" ]) }
|
stdouted { Kamal::Cli::Accessory.start([ *command, "-c", "test/fixtures/deploy_with_accessories.yml" ]) }
|
||||||
|
|||||||
@@ -5,39 +5,26 @@ class CliAppTest < CliTestCase
|
|||||||
stub_running
|
stub_running
|
||||||
run_command("boot").tap do |output|
|
run_command("boot").tap do |output|
|
||||||
assert_match "docker tag dhh/app:latest dhh/app:latest", output
|
assert_match "docker tag dhh/app:latest dhh/app:latest", output
|
||||||
assert_match /docker run --detach --restart unless-stopped --name app-web-latest --hostname 1.1.1.1-[0-9a-f]{12} /, output
|
assert_match /docker run --detach --restart unless-stopped --name app-web-latest --network kamal --hostname 1.1.1.1-[0-9a-f]{12} /, output
|
||||||
assert_match "docker container ls --all --filter name=^app-web-123$ --quiet | xargs docker stop", output
|
assert_match "docker container ls --all --filter name=^app-web-123$ --quiet | xargs docker stop", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "boot will rename if same version is already running" do
|
test "boot will rename if same version is already running" do
|
||||||
Object.any_instance.stubs(:sleep)
|
|
||||||
run_command("details") # Preheat Kamal const
|
run_command("details") # Preheat Kamal const
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", raise_on_non_zero_exit: false)
|
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", raise_on_non_zero_exit: false)
|
||||||
.returns("12345678") # running version
|
.returns("12345678") # running version
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running") # health check
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
|
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
|
||||||
.returns("123") # old version
|
.returns("123") # old version
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-123", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
|
|
||||||
.returns("cordfile") # old version
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-123$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("unhealthy") # old version unhealthy
|
|
||||||
|
|
||||||
run_command("boot").tap do |output|
|
run_command("boot").tap do |output|
|
||||||
assert_match /Renaming container .* to .* as already deployed on 1.1.1.1/, output # Rename
|
assert_match /Renaming container .* to .* as already deployed on 1.1.1.1/, output # Rename
|
||||||
assert_match /docker rename app-web-latest app-web-latest_replaced_[0-9a-f]{16}/, output
|
assert_match /docker rename app-web-latest app-web-latest_replaced_[0-9a-f]{16}/, output
|
||||||
assert_match /docker run --detach --restart unless-stopped --name app-web-latest --hostname 1.1.1.1-[0-9a-f]{12} /, output
|
assert_match /docker run --detach --restart unless-stopped --name app-web-latest --network kamal --hostname 1.1.1.1-[0-9a-f]{12} /, output
|
||||||
assert_match "docker container ls --all --filter name=^app-web-123$ --quiet | xargs docker stop", output
|
assert_match "docker container ls --all --filter name=^app-web-123$ --quiet | xargs docker stop", output
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
@@ -45,7 +32,7 @@ class CliAppTest < CliTestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "boot uses group strategy when specified" do
|
test "boot uses group strategy when specified" do
|
||||||
Kamal::Cli::App.any_instance.stubs(:on).with("1.1.1.1").twice # acquire & release lock
|
Kamal::Cli::App.any_instance.stubs(:on).with("1.1.1.1").times(3) # ensure locks dir, acquire & release lock
|
||||||
Kamal::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container
|
Kamal::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container
|
||||||
|
|
||||||
# Strategy is used when booting the containers
|
# Strategy is used when booting the containers
|
||||||
@@ -57,7 +44,7 @@ class CliAppTest < CliTestCase
|
|||||||
test "boot errors leave lock in place" do
|
test "boot errors leave lock in place" do
|
||||||
Kamal::Cli::App.any_instance.expects(:using_version).raises(RuntimeError)
|
Kamal::Cli::App.any_instance.expects(:using_version).raises(RuntimeError)
|
||||||
|
|
||||||
assert !KAMAL.holding_lock?
|
assert_not KAMAL.holding_lock?
|
||||||
assert_raises(RuntimeError) do
|
assert_raises(RuntimeError) do
|
||||||
stderred { run_command("boot") }
|
stderred { run_command("boot") }
|
||||||
end
|
end
|
||||||
@@ -70,23 +57,15 @@ class CliAppTest < CliTestCase
|
|||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", raise_on_non_zero_exit: false)
|
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", raise_on_non_zero_exit: false)
|
||||||
.returns("12345678") # running version
|
.returns("12345678") # running version
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running") # health check
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
|
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
|
||||||
.returns("123").twice # old version
|
.returns("123").twice # old version
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-123", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
|
|
||||||
.returns("") # old version
|
|
||||||
|
|
||||||
run_command("boot", config: :with_assets).tap do |output|
|
run_command("boot", config: :with_assets).tap do |output|
|
||||||
assert_match "docker tag dhh/app:latest dhh/app:latest", output
|
assert_match "docker tag dhh/app:latest dhh/app:latest", output
|
||||||
assert_match "/usr/bin/env mkdir -p .kamal/assets/volumes/app-web-latest ; cp -rnT .kamal/assets/extracted/app-web-latest .kamal/assets/volumes/app-web-latest ; cp -rnT .kamal/assets/extracted/app-web-latest .kamal/assets/volumes/app-web-123 || true ; cp -rnT .kamal/assets/extracted/app-web-123 .kamal/assets/volumes/app-web-latest || true", output
|
assert_match "/usr/bin/env mkdir -p .kamal/assets/volumes/app-web-latest ; cp -rnT .kamal/assets/extracted/app-web-latest .kamal/assets/volumes/app-web-latest ; cp -rnT .kamal/assets/extracted/app-web-latest .kamal/assets/volumes/app-web-123 || true ; cp -rnT .kamal/assets/extracted/app-web-123 .kamal/assets/volumes/app-web-latest || true", output
|
||||||
assert_match "/usr/bin/env mkdir -p .kamal/assets/extracted/app-web-latest && docker stop -t 1 app-web-assets 2> /dev/null || true && docker run --name app-web-assets --detach --rm dhh/app:latest sleep 1000000 && docker cp -L app-web-assets:/public/assets/. .kamal/assets/extracted/app-web-latest && docker stop -t 1 app-web-assets", output
|
assert_match "/usr/bin/env mkdir -p .kamal/assets/extracted/app-web-latest && docker stop -t 1 app-web-assets 2> /dev/null || true && docker run --name app-web-assets --detach --rm dhh/app:latest sleep 1000000 && docker cp -L app-web-assets:/public/assets/. .kamal/assets/extracted/app-web-latest && docker stop -t 1 app-web-assets", output
|
||||||
assert_match /docker run --detach --restart unless-stopped --name app-web-latest --hostname 1.1.1.1-[0-9a-f]{12} /, output
|
assert_match /docker run --detach --restart unless-stopped --name app-web-latest --network kamal --hostname 1.1.1.1-[0-9a-f]{12} /, output
|
||||||
assert_match "docker container ls --all --filter name=^app-web-123$ --quiet | xargs docker stop", output
|
assert_match "docker container ls --all --filter name=^app-web-123$ --quiet | xargs docker stop", output
|
||||||
assert_match "/usr/bin/env find .kamal/assets/extracted -maxdepth 1 -name 'app-web-*' ! -name app-web-latest -exec rm -rf \"{}\" + ; find .kamal/assets/volumes -maxdepth 1 -name 'app-web-*' ! -name app-web-latest -exec rm -rf \"{}\" +", output
|
assert_match "/usr/bin/env find .kamal/assets/extracted -maxdepth 1 -name 'app-web-*' ! -name app-web-latest -exec rm -rf \"{}\" + ; find .kamal/assets/volumes -maxdepth 1 -name 'app-web-*' ! -name app-web-latest -exec rm -rf \"{}\" +", output
|
||||||
end
|
end
|
||||||
@@ -237,13 +216,5 @@ class CliAppTest < CliTestCase
|
|||||||
Object.any_instance.stubs(:sleep)
|
Object.any_instance.stubs(:sleep)
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info).returns("123") # old version
|
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info).returns("123") # old version
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running") # health check
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-123$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("unhealthy") # health check
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class CliBuildTest < CliTestCase
|
|||||||
run_command("push").tap do |output|
|
run_command("push").tap do |output|
|
||||||
assert_hook_ran "pre-build", output, **hook_variables
|
assert_hook_ran "pre-build", output, **hook_variables
|
||||||
assert_match /docker --version && docker buildx version/, output
|
assert_match /docker --version && docker buildx version/, output
|
||||||
assert_match /docker buildx build --push --platform linux\/amd64,linux\/arm64 --builder kamal-app-multiarch -t dhh\/app:999 -t dhh\/app:latest --label service="app" --file Dockerfile \. as .*@localhost/, output
|
assert_match /git archive -tar HEAD | docker buildx build --push --platform linux\/amd64,linux\/arm64 --builder kamal-app-multiarch -t dhh\/app:999 -t dhh\/app:latest --label service="app" --file Dockerfile - as .*@localhost/, output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -25,7 +25,10 @@ class CliBuildTest < CliTestCase
|
|||||||
.with(:docker, "--version", "&&", :docker, :buildx, "version")
|
.with(:docker, "--version", "&&", :docker, :buildx, "version")
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |*args| args[0..1] == [:docker, :buildx] }
|
.with(:docker, :buildx, :create, "--use", "--name", "kamal-app-multiarch")
|
||||||
|
|
||||||
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
|
.with { |*args| p args[0..6]; args[0..6] == [ :git, :archive, "--format=tar", :HEAD, "|", :docker, :buildx ] }
|
||||||
.raises(SSHKit::Command::Failed.new("no builder"))
|
.raises(SSHKit::Command::Failed.new("no builder"))
|
||||||
.then
|
.then
|
||||||
.returns(true)
|
.returns(true)
|
||||||
@@ -57,7 +60,7 @@ class CliBuildTest < CliTestCase
|
|||||||
run_command("pull").tap do |output|
|
run_command("pull").tap do |output|
|
||||||
assert_match /docker image rm --force dhh\/app:999/, output
|
assert_match /docker image rm --force dhh\/app:999/, output
|
||||||
assert_match /docker pull dhh\/app:999/, output
|
assert_match /docker pull dhh\/app:999/, output
|
||||||
assert_match "docker inspect -f '{{ .Config.Labels.service }}' dhh/app:999 | grep -x app || (echo \"Image dhh/app:999 is missing the `service` label\" && exit 1)", output
|
assert_match "docker inspect -f '{{ .Config.Labels.service }}' dhh/app:999 | grep -x app || (echo \"Image dhh/app:999 is missing the 'service' label\" && exit 1)", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -31,9 +31,11 @@ class CliTestCase < ActiveSupport::TestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |*args| args == [ :mkdir, "-p", ".kamal" ] }
|
.with { |*args| args == [ :mkdir, "-p", ".kamal" ] }
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |arg1, arg2| arg1 == :mkdir && arg2 == ".kamal/lock-app" }
|
.with { |arg1, arg2, arg3| arg1 == :mkdir && arg2 == "-p" && arg3 == ".kamal/locks" }
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |arg1, arg2| arg1 == :rm && arg2 == ".kamal/lock-app/details" }
|
.with { |arg1, arg2| arg1 == :mkdir && arg2 == ".kamal/locks/app" }
|
||||||
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
|
.with { |arg1, arg2| arg1 == :rm && arg2 == ".kamal/locks/app/details" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_hook_ran(hook, output, version:, service_version:, hosts:, command:, subcommand: nil, runtime: nil)
|
def assert_hook_ran(hook, output, version:, service_version:, hosts:, command:, subcommand: nil, runtime: nil)
|
||||||
|
|||||||
@@ -4,16 +4,12 @@ class CliEnvTest < CliTestCase
|
|||||||
test "push" do
|
test "push" do
|
||||||
run_command("push").tap do |output|
|
run_command("push").tap do |output|
|
||||||
assert_match "Running /usr/bin/env mkdir -p .kamal/env/roles on 1.1.1.1", output
|
assert_match "Running /usr/bin/env mkdir -p .kamal/env/roles on 1.1.1.1", output
|
||||||
assert_match "Running /usr/bin/env mkdir -p .kamal/env/traefik on 1.1.1.1", output
|
|
||||||
assert_match "Running /usr/bin/env mkdir -p .kamal/env/accessories on 1.1.1.1", output
|
assert_match "Running /usr/bin/env mkdir -p .kamal/env/accessories on 1.1.1.1", output
|
||||||
assert_match "Running /usr/bin/env mkdir -p .kamal/env/roles on 1.1.1.1", output
|
assert_match "Running /usr/bin/env mkdir -p .kamal/env/roles on 1.1.1.1", output
|
||||||
assert_match "Running /usr/bin/env mkdir -p .kamal/env/traefik on 1.1.1.2", output
|
|
||||||
assert_match "Running /usr/bin/env mkdir -p .kamal/env/accessories on 1.1.1.1", output
|
assert_match "Running /usr/bin/env mkdir -p .kamal/env/accessories on 1.1.1.1", output
|
||||||
assert_match ".kamal/env/roles/app-web.env", output
|
assert_match ".kamal/env/roles/app-web.env", output
|
||||||
assert_match ".kamal/env/roles/app-workers.env", output
|
assert_match ".kamal/env/roles/app-workers.env", output
|
||||||
assert_match ".kamal/env/traefik/traefik.env", output
|
|
||||||
assert_match ".kamal/env/accessories/app-redis.env", output
|
assert_match ".kamal/env/accessories/app-redis.env", output
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -23,8 +19,6 @@ class CliEnvTest < CliTestCase
|
|||||||
assert_match "Running /usr/bin/env rm -f .kamal/env/roles/app-web.env on 1.1.1.2", output
|
assert_match "Running /usr/bin/env rm -f .kamal/env/roles/app-web.env on 1.1.1.2", output
|
||||||
assert_match "Running /usr/bin/env rm -f .kamal/env/roles/app-workers.env on 1.1.1.3", output
|
assert_match "Running /usr/bin/env rm -f .kamal/env/roles/app-workers.env on 1.1.1.3", output
|
||||||
assert_match "Running /usr/bin/env rm -f .kamal/env/roles/app-workers.env on 1.1.1.4", output
|
assert_match "Running /usr/bin/env rm -f .kamal/env/roles/app-workers.env on 1.1.1.4", output
|
||||||
assert_match "Running /usr/bin/env rm -f .kamal/env/traefik/traefik.env on 1.1.1.1", output
|
|
||||||
assert_match "Running /usr/bin/env rm -f .kamal/env/traefik/traefik.env on 1.1.1.2", output
|
|
||||||
assert_match "Running /usr/bin/env rm -f .kamal/env/accessories/app-redis.env on 1.1.1.1", output
|
assert_match "Running /usr/bin/env rm -f .kamal/env/accessories/app-redis.env on 1.1.1.1", output
|
||||||
assert_match "Running /usr/bin/env rm -f .kamal/env/accessories/app-redis.env on 1.1.1.2", output
|
assert_match "Running /usr/bin/env rm -f .kamal/env/accessories/app-redis.env on 1.1.1.2", output
|
||||||
assert_match "Running /usr/bin/env rm -f .kamal/env/accessories/app-mysql.env on 1.1.1.3", output
|
assert_match "Running /usr/bin/env rm -f .kamal/env/accessories/app-mysql.env on 1.1.1.3", output
|
||||||
|
|||||||
@@ -65,14 +65,14 @@ class CliHealthcheckTest < CliTestCase
|
|||||||
assert_match "container not ready (unhealthy)", exception.message
|
assert_match "container not ready (unhealthy)", exception.message
|
||||||
end
|
end
|
||||||
|
|
||||||
test "raises an exception if primary does not have traefik" do
|
test "raises an exception if primary does not have a proxy" do
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).never
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).never
|
||||||
|
|
||||||
exception = assert_raises do
|
exception = assert_raises do
|
||||||
run_command("perform", config_file: "test/fixtures/deploy_workers_only.yml")
|
run_command("perform", config_file: "test/fixtures/deploy_workers_only.yml")
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal "The primary host is not configured to run Traefik", exception.message
|
assert_equal "The primary host is not configured to run a proxy", exception.message
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require_relative "cli_test_case"
|
|||||||
class CliLockTest < CliTestCase
|
class CliLockTest < CliTestCase
|
||||||
test "status" do
|
test "status" do
|
||||||
run_command("status").tap do |output|
|
run_command("status").tap do |output|
|
||||||
assert_match "Running /usr/bin/env stat .kamal/lock-app > /dev/null && cat .kamal/lock-app/details | base64 -d on 1.1.1.1", output
|
assert_match "Running /usr/bin/env stat .kamal/locks/app > /dev/null && cat .kamal/locks/app/details | base64 -d on 1.1.1.1", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,47 @@ require_relative "cli_test_case"
|
|||||||
|
|
||||||
class CliMainTest < CliTestCase
|
class CliMainTest < CliTestCase
|
||||||
test "setup" do
|
test "setup" do
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:server:bootstrap")
|
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false }
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:env:push")
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:boot", [ "all" ])
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:server:bootstrap", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:env:push", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:boot", [ "all" ], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:deploy)
|
Kamal::Cli::Main.any_instance.expects(:deploy)
|
||||||
|
|
||||||
run_command("setup")
|
run_command("setup").tap do |output|
|
||||||
|
assert_match /Ensure Docker is installed.../, output
|
||||||
|
assert_match /Push env files.../, output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "setup with skip_push" do
|
||||||
|
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false }
|
||||||
|
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:server:bootstrap", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:env:push", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:boot", [ "all" ], invoke_options)
|
||||||
|
# deploy
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:pull", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:boot", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
||||||
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
|
||||||
|
|
||||||
|
run_command("setup", "--skip_push").tap do |output|
|
||||||
|
assert_match /Ensure Docker is installed.../, output
|
||||||
|
assert_match /Push env files.../, output
|
||||||
|
# deploy
|
||||||
|
assert_match /Acquiring the deploy lock/, output
|
||||||
|
assert_match /Log into image registry/, output
|
||||||
|
assert_match /Pull app image/, output
|
||||||
|
assert_match /Ensure proxy is running/, output
|
||||||
|
assert_match /Ensure app can pass healthcheck/, output
|
||||||
|
assert_match /Detect stale containers/, output
|
||||||
|
assert_match /Prune old containers and images/, output
|
||||||
|
assert_match /Releasing the deploy lock/, output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "deploy" do
|
test "deploy" do
|
||||||
@@ -15,7 +50,7 @@ class CliMainTest < CliTestCase
|
|||||||
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:boot", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
||||||
@@ -29,7 +64,7 @@ class CliMainTest < CliTestCase
|
|||||||
assert_match /Log into image registry/, output
|
assert_match /Log into image registry/, output
|
||||||
assert_match /Build and push app image/, output
|
assert_match /Build and push app image/, output
|
||||||
assert_hook_ran "pre-deploy", output, **hook_variables
|
assert_hook_ran "pre-deploy", output, **hook_variables
|
||||||
assert_match /Ensure Traefik is running/, output
|
assert_match /Ensure proxy is running/, output
|
||||||
assert_match /Ensure app can pass healthcheck/, output
|
assert_match /Ensure app can pass healthcheck/, output
|
||||||
assert_match /Detect stale containers/, output
|
assert_match /Detect stale containers/, output
|
||||||
assert_match /Prune old containers and images/, output
|
assert_match /Prune old containers and images/, output
|
||||||
@@ -42,7 +77,7 @@ class CliMainTest < CliTestCase
|
|||||||
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:pull", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:pull", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:boot", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
||||||
@@ -52,7 +87,7 @@ class CliMainTest < CliTestCase
|
|||||||
assert_match /Acquiring the deploy lock/, output
|
assert_match /Acquiring the deploy lock/, output
|
||||||
assert_match /Log into image registry/, output
|
assert_match /Log into image registry/, output
|
||||||
assert_match /Pull app image/, output
|
assert_match /Pull app image/, output
|
||||||
assert_match /Ensure Traefik is running/, output
|
assert_match /Ensure proxy is running/, output
|
||||||
assert_match /Ensure app can pass healthcheck/, output
|
assert_match /Ensure app can pass healthcheck/, output
|
||||||
assert_match /Detect stale containers/, output
|
assert_match /Detect stale containers/, output
|
||||||
assert_match /Prune old containers and images/, output
|
assert_match /Prune old containers and images/, output
|
||||||
@@ -67,11 +102,14 @@ class CliMainTest < CliTestCase
|
|||||||
.with { |*args| args == [ :mkdir, "-p", ".kamal" ] }
|
.with { |*args| args == [ :mkdir, "-p", ".kamal" ] }
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |*arg| arg[0..1] == [:mkdir, ".kamal/lock-app"] }
|
.with { |*args| args == [ :mkdir, "-p", ".kamal/locks" ] }
|
||||||
.raises(RuntimeError, "mkdir: cannot create directory ‘kamal_lock-app’: File exists")
|
|
||||||
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
|
.with { |*arg| arg[0..1] == [ :mkdir, ".kamal/locks/app" ] }
|
||||||
|
.raises(RuntimeError, "mkdir: cannot create directory ‘kamal/locks/app’: File exists")
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_debug)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_debug)
|
||||||
.with(:stat, ".kamal/lock-app", ">", "/dev/null", "&&", :cat, ".kamal/lock-app/details", "|", :base64, "-d")
|
.with(:stat, ".kamal/locks/app", ">", "/dev/null", "&&", :cat, ".kamal/locks/app/details", "|", :base64, "-d")
|
||||||
|
|
||||||
assert_raises(Kamal::Cli::LockError) do
|
assert_raises(Kamal::Cli::LockError) do
|
||||||
run_command("deploy")
|
run_command("deploy")
|
||||||
@@ -85,7 +123,10 @@ class CliMainTest < CliTestCase
|
|||||||
.with { |*args| args == [ :mkdir, "-p", ".kamal" ] }
|
.with { |*args| args == [ :mkdir, "-p", ".kamal" ] }
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |*arg| arg[0..1] == [:mkdir, ".kamal/lock-app"] }
|
.with { |*args| args == [ :mkdir, "-p", ".kamal/locks" ] }
|
||||||
|
|
||||||
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
|
.with { |*arg| arg[0..1] == [ :mkdir, ".kamal/locks/app" ] }
|
||||||
.raises(SocketError, "getaddrinfo: nodename nor servname provided, or not known")
|
.raises(SocketError, "getaddrinfo: nodename nor servname provided, or not known")
|
||||||
|
|
||||||
assert_raises(SSHKit::Runner::ExecuteError) do
|
assert_raises(SSHKit::Runner::ExecuteError) do
|
||||||
@@ -100,11 +141,11 @@ class CliMainTest < CliTestCase
|
|||||||
.with("kamal:cli:registry:login", [], invoke_options)
|
.with("kamal:cli:registry:login", [], invoke_options)
|
||||||
.raises(RuntimeError)
|
.raises(RuntimeError)
|
||||||
|
|
||||||
assert !KAMAL.holding_lock?
|
assert_not KAMAL.holding_lock?
|
||||||
assert_raises(RuntimeError) do
|
assert_raises(RuntimeError) do
|
||||||
stderred { run_command("deploy") }
|
stderred { run_command("deploy") }
|
||||||
end
|
end
|
||||||
assert !KAMAL.holding_lock?
|
assert_not KAMAL.holding_lock?
|
||||||
end
|
end
|
||||||
|
|
||||||
test "deploy with skipped hooks" do
|
test "deploy with skipped hooks" do
|
||||||
@@ -112,25 +153,25 @@ class CliMainTest < CliTestCase
|
|||||||
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:boot", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
|
||||||
|
|
||||||
run_command("deploy", "--skip_hooks") do
|
run_command("deploy", "--skip_hooks") do
|
||||||
refute_match /Running the post-deploy hook.../, output
|
assert_no_match /Running the post-deploy hook.../, output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "deploy without healthcheck if primary host doesn't have traefik" do
|
test "deploy without healthcheck if primary host doesn't have proxy" do
|
||||||
invoke_options = { "config_file" => "test/fixtures/deploy_workers_only.yml", "version" => "999", "skip_hooks" => false }
|
invoke_options = { "config_file" => "test/fixtures/deploy_workers_only.yml", "version" => "999", "skip_hooks" => false }
|
||||||
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options).never
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options).never
|
||||||
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:boot", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
|
||||||
@@ -143,7 +184,7 @@ class CliMainTest < CliTestCase
|
|||||||
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:boot", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true))
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
|
||||||
@@ -211,18 +252,8 @@ class CliMainTest < CliTestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=#{role}", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-#{role}-}; done", raise_on_non_zero_exit: false)
|
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=#{role}", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-#{role}-}; done", raise_on_non_zero_exit: false)
|
||||||
.returns("version-to-rollback\n").at_least_once
|
.returns("version-to-rollback\n").at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-#{role}-123$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running").at_least_once # health check
|
|
||||||
end
|
end
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-version-to-rollback", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
|
|
||||||
.returns("corddirectory").at_least_once # health check
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-version-to-rollback$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("unhealthy").at_least_once # health check
|
|
||||||
|
|
||||||
Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
|
Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
|
||||||
hook_variables = { version: 123, service_version: "app@123", hosts: "1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4", command: "rollback" }
|
hook_variables = { version: 123, service_version: "app@123", hosts: "1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4", command: "rollback" }
|
||||||
@@ -247,9 +278,6 @@ class CliMainTest < CliTestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
|
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
|
||||||
.returns("").at_least_once
|
.returns("").at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-123$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running").at_least_once # health check
|
|
||||||
|
|
||||||
run_command("rollback", "123").tap do |output|
|
run_command("rollback", "123").tap do |output|
|
||||||
assert_match "docker run --detach --restart unless-stopped --name app-web-123", output
|
assert_match "docker run --detach --restart unless-stopped --name app-web-123", output
|
||||||
@@ -258,7 +286,7 @@ class CliMainTest < CliTestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "details" do
|
test "details" do
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:details")
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:details")
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:details")
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:details")
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:details", [ "all" ])
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:details", [ "all" ])
|
||||||
|
|
||||||
@@ -423,9 +451,9 @@ class CliMainTest < CliTestCase
|
|||||||
|
|
||||||
test "remove with confirmation" do
|
test "remove with confirmation" do
|
||||||
run_command("remove", "-y", config_file: "deploy_with_accessories").tap do |output|
|
run_command("remove", "-y", config_file: "deploy_with_accessories").tap do |output|
|
||||||
assert_match /docker container stop traefik/, output
|
assert_match /docker container stop mproxy/, output
|
||||||
assert_match /docker container prune --force --filter label=org.opencontainers.image.title=Traefik/, output
|
assert_match /docker container prune --force --filter label=org.opencontainers.image.title=mproxy/, output
|
||||||
assert_match /docker image prune --all --force --filter label=org.opencontainers.image.title=Traefik/, output
|
assert_match /docker image prune --all --force --filter label=org.opencontainers.image.title=mproxy/, output
|
||||||
|
|
||||||
assert_match /docker ps --quiet --filter label=service=app | xargs docker stop/, output
|
assert_match /docker ps --quiet --filter label=service=app | xargs docker stop/, output
|
||||||
assert_match /docker container prune --force --filter label=service=app/, output
|
assert_match /docker container prune --force --filter label=service=app/, output
|
||||||
|
|||||||
96
test/cli/proxy_test.rb
Normal file
96
test/cli/proxy_test.rb
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
require_relative "cli_test_case"
|
||||||
|
|
||||||
|
class CliProxyTest < CliTestCase
|
||||||
|
test "boot" do
|
||||||
|
run_command("boot").tap do |output|
|
||||||
|
assert_match "docker login", output
|
||||||
|
assert_match "docker run --name mproxy --detach --restart unless-stopped --network kamal --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Kamal::Commands::Proxy::DEFAULT_IMAGE}", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reboot" do
|
||||||
|
Kamal::Commands::Registry.any_instance.expects(:login).twice
|
||||||
|
|
||||||
|
run_command("reboot", "-y").tap do |output|
|
||||||
|
assert_match "docker container stop mproxy", output
|
||||||
|
assert_match "docker container prune --force --filter label=org.opencontainers.image.title=mproxy", output
|
||||||
|
assert_match "docker run --name mproxy --detach --restart unless-stopped --network kamal --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Kamal::Commands::Proxy::DEFAULT_IMAGE}", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reboot --rolling" do
|
||||||
|
Object.any_instance.stubs(:sleep)
|
||||||
|
|
||||||
|
run_command("reboot", "--rolling", "-y").tap do |output|
|
||||||
|
assert_match "Running docker container prune --force --filter label=org.opencontainers.image.title=mproxy on 1.1.1.1", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "start" do
|
||||||
|
run_command("start").tap do |output|
|
||||||
|
assert_match "docker container start mproxy", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "stop" do
|
||||||
|
run_command("stop").tap do |output|
|
||||||
|
assert_match "docker container stop mproxy", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "restart" do
|
||||||
|
Kamal::Cli::Proxy.any_instance.expects(:stop)
|
||||||
|
Kamal::Cli::Proxy.any_instance.expects(:start)
|
||||||
|
|
||||||
|
run_command("restart")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "details" do
|
||||||
|
run_command("details").tap do |output|
|
||||||
|
assert_match "docker ps --filter name=^mproxy$", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logs" do
|
||||||
|
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
||||||
|
.with(:docker, :logs, "mproxy", " --tail 100", "--timestamps", "2>&1")
|
||||||
|
.returns("Log entry")
|
||||||
|
|
||||||
|
run_command("logs").tap do |output|
|
||||||
|
assert_match "Proxy Host: 1.1.1.1", output
|
||||||
|
assert_match "Log entry", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logs with follow" do
|
||||||
|
SSHKit::Backend::Abstract.any_instance.stubs(:exec)
|
||||||
|
.with("ssh -t root@1.1.1.1 -p 22 'docker logs mproxy --timestamps --tail 10 --follow 2>&1'")
|
||||||
|
|
||||||
|
assert_match "docker logs mproxy --timestamps --tail 10 --follow", run_command("logs", "--follow")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "remove" do
|
||||||
|
Kamal::Cli::Proxy.any_instance.expects(:stop)
|
||||||
|
Kamal::Cli::Proxy.any_instance.expects(:remove_container)
|
||||||
|
Kamal::Cli::Proxy.any_instance.expects(:remove_image)
|
||||||
|
|
||||||
|
run_command("remove")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "remove_container" do
|
||||||
|
run_command("remove_container").tap do |output|
|
||||||
|
assert_match "docker container prune --force --filter label=org.opencontainers.image.title=mproxy", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "remove_image" do
|
||||||
|
run_command("remove_image").tap do |output|
|
||||||
|
assert_match "docker image prune --all --force --filter label=org.opencontainers.image.title=mproxy", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def run_command(*command)
|
||||||
|
stdouted { Kamal::Cli::Proxy.start([ *command, "-c", "test/fixtures/deploy_with_accessories.yml" ]) }
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -20,6 +20,15 @@ class CliPruneTest < CliTestCase
|
|||||||
assert_match /docker ps -q -a --filter label=service=app --filter status=created --filter status=exited --filter status=dead | tail -n +6 | while read container_id; do docker rm $container_id; done on 1.1.1.\d/, output
|
assert_match /docker ps -q -a --filter label=service=app --filter status=created --filter status=exited --filter status=dead | tail -n +6 | while read container_id; do docker rm $container_id; done on 1.1.1.\d/, output
|
||||||
assert_match /docker container prune --force --filter label=service=healthcheck-app on 1.1.1.\d/, output
|
assert_match /docker container prune --force --filter label=service=healthcheck-app on 1.1.1.\d/, output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
run_command("containers", "--retain", "10").tap do |output|
|
||||||
|
assert_match /docker ps -q -a --filter label=service=app --filter status=created --filter status=exited --filter status=dead | tail -n +11 | while read container_id; do docker rm $container_id; done on 1.1.1.\d/, output
|
||||||
|
assert_match /docker container prune --force --filter label=service=healthcheck-app on 1.1.1.\d/, output
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raises(RuntimeError, "retain must be at least 1") do
|
||||||
|
run_command("containers", "--retain", "0")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ class CliServerTest < CliTestCase
|
|||||||
test "bootstrap already installed" do
|
test "bootstrap already installed" do
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(true).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(true).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
||||||
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, :network, :create, :kamal).returns("").at_least_once
|
||||||
|
|
||||||
assert_equal "", run_command("bootstrap")
|
assert_equal "", run_command("bootstrap")
|
||||||
end
|
end
|
||||||
@@ -12,6 +13,7 @@ class CliServerTest < CliTestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(false).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(false).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
||||||
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, :network, :create, :kamal).returns("").at_least_once
|
||||||
|
|
||||||
assert_raise RuntimeError, "Docker is not installed on 1.1.1.1, 1.1.1.3, 1.1.1.4, 1.1.1.2 and can't be automatically installed without having root access and the `curl` command available. Install Docker manually: https://docs.docker.com/engine/install/" do
|
assert_raise RuntimeError, "Docker is not installed on 1.1.1.1, 1.1.1.3, 1.1.1.4, 1.1.1.2 and can't be automatically installed without having root access and the `curl` command available. Install Docker manually: https://docs.docker.com/engine/install/" do
|
||||||
run_command("bootstrap")
|
run_command("bootstrap")
|
||||||
@@ -21,12 +23,16 @@ class CliServerTest < CliTestCase
|
|||||||
test "bootstrap install as root user" do
|
test "bootstrap install as root user" do
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(true).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(true).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:curl, "-fsSL", "https://get.docker.com", "|", :sh).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:sh, "-c", "'curl -fsSL https://get.docker.com || wget -O - https://get.docker.com || echo \"exit 1\"'", "|", :sh).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
||||||
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, :network, :create, :kamal).returns("").at_least_once
|
||||||
|
Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
|
||||||
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(".kamal/hooks/docker-setup", anything).at_least_once
|
||||||
|
|
||||||
run_command("bootstrap").tap do |output|
|
run_command("bootstrap").tap do |output|
|
||||||
("1.1.1.1".."1.1.1.4").map do |host|
|
("1.1.1.1".."1.1.1.4").map do |host|
|
||||||
assert_match "Missing Docker on #{host}. Installing…", output
|
assert_match "Missing Docker on #{host}. Installing…", output
|
||||||
|
assert_match "Running the docker-setup hook", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
require_relative "cli_test_case"
|
|
||||||
|
|
||||||
class CliTraefikTest < CliTestCase
|
|
||||||
test "boot" do
|
|
||||||
run_command("boot").tap do |output|
|
|
||||||
assert_match "docker login", output
|
|
||||||
assert_match "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{Kamal::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "reboot" do
|
|
||||||
Kamal::Commands::Registry.any_instance.expects(:login).twice
|
|
||||||
|
|
||||||
run_command("reboot").tap do |output|
|
|
||||||
assert_match "docker container stop traefik", output
|
|
||||||
assert_match "docker container prune --force --filter label=org.opencontainers.image.title=Traefik", output
|
|
||||||
assert_match "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{Kamal::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "reboot --rolling" do
|
|
||||||
Object.any_instance.stubs(:sleep)
|
|
||||||
|
|
||||||
run_command("reboot", "--rolling").tap do |output|
|
|
||||||
assert_match "Running docker container prune --force --filter label=org.opencontainers.image.title=Traefik on 1.1.1.1", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "start" do
|
|
||||||
run_command("start").tap do |output|
|
|
||||||
assert_match "docker container start traefik", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "stop" do
|
|
||||||
run_command("stop").tap do |output|
|
|
||||||
assert_match "docker container stop traefik", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "restart" do
|
|
||||||
Kamal::Cli::Traefik.any_instance.expects(:stop)
|
|
||||||
Kamal::Cli::Traefik.any_instance.expects(:start)
|
|
||||||
|
|
||||||
run_command("restart")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "details" do
|
|
||||||
run_command("details").tap do |output|
|
|
||||||
assert_match "docker ps --filter name=^traefik$", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "logs" do
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
|
||||||
.with(:docker, :logs, "traefik", " --tail 100", "--timestamps", "2>&1")
|
|
||||||
.returns("Log entry")
|
|
||||||
|
|
||||||
run_command("logs").tap do |output|
|
|
||||||
assert_match "Traefik Host: 1.1.1.1", output
|
|
||||||
assert_match "Log entry", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "logs with follow" do
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:exec)
|
|
||||||
.with("ssh -t root@1.1.1.1 -p 22 'docker logs traefik --timestamps --tail 10 --follow 2>&1'")
|
|
||||||
|
|
||||||
assert_match "docker logs traefik --timestamps --tail 10 --follow", run_command("logs", "--follow")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "remove" do
|
|
||||||
Kamal::Cli::Traefik.any_instance.expects(:stop)
|
|
||||||
Kamal::Cli::Traefik.any_instance.expects(:remove_container)
|
|
||||||
Kamal::Cli::Traefik.any_instance.expects(:remove_image)
|
|
||||||
|
|
||||||
run_command("remove")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "remove_container" do
|
|
||||||
run_command("remove_container").tap do |output|
|
|
||||||
assert_match "docker container prune --force --filter label=org.opencontainers.image.title=Traefik", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "remove_image" do
|
|
||||||
run_command("remove_image").tap do |output|
|
|
||||||
assert_match "docker image prune --all --force --filter label=org.opencontainers.image.title=Traefik", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def run_command(*command)
|
|
||||||
stdouted { Kamal::Cli::Traefik.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -83,14 +83,14 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "primary_role" do
|
test "primary_role" do
|
||||||
assert_equal "web", @kamal.primary_role
|
assert_equal "web", @kamal.primary_role.name
|
||||||
@kamal.specific_roles = "workers"
|
@kamal.specific_roles = "workers"
|
||||||
assert_equal "workers", @kamal.primary_role
|
assert_equal "workers", @kamal.primary_role.name
|
||||||
end
|
end
|
||||||
|
|
||||||
test "roles_on" do
|
test "roles_on" do
|
||||||
assert_equal [ "web" ], @kamal.roles_on("1.1.1.1")
|
assert_equal [ "web" ], @kamal.roles_on("1.1.1.1").map(&:name)
|
||||||
assert_equal [ "workers" ], @kamal.roles_on("1.1.1.3")
|
assert_equal [ "workers" ], @kamal.roles_on("1.1.1.3").map(&:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "default group strategy" do
|
test "default group strategy" do
|
||||||
@@ -109,12 +109,18 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
assert_equal({ in: :groups, limit: 1, wait: 2 }, @kamal.boot_strategy)
|
assert_equal({ in: :groups, limit: 1, wait: 2 }, @kamal.boot_strategy)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "percentage-based group strategy limit is at least 1" do
|
||||||
|
configure_with(:deploy_with_low_percentage_boot_strategy)
|
||||||
|
|
||||||
|
assert_equal({ in: :groups, limit: 1, wait: 2 }, @kamal.boot_strategy)
|
||||||
|
end
|
||||||
|
|
||||||
test "try to match the primary role from a list of specific roles" do
|
test "try to match the primary role from a list of specific roles" do
|
||||||
configure_with(:deploy_primary_web_role_override)
|
configure_with(:deploy_primary_web_role_override)
|
||||||
|
|
||||||
@kamal.specific_roles = [ "web_*" ]
|
@kamal.specific_roles = [ "web_*" ]
|
||||||
assert_equal [ "web_chicago", "web_tokyo" ], @kamal.roles.map(&:name)
|
assert_equal [ "web_chicago", "web_tokyo" ], @kamal.roles.map(&:name)
|
||||||
assert_equal "web_tokyo", @kamal.primary_role
|
assert_equal "web_tokyo", @kamal.primary_role.name
|
||||||
assert_equal "1.1.1.3", @kamal.primary_host
|
assert_equal "1.1.1.3", @kamal.primary_host
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"busybox" => {
|
"busybox" => {
|
||||||
|
"service" => "custom-busybox",
|
||||||
"image" => "busybox:latest",
|
"image" => "busybox:latest",
|
||||||
"host" => "1.1.1.7"
|
"host" => "1.1.1.7"
|
||||||
}
|
}
|
||||||
@@ -49,15 +50,15 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "run" do
|
test "run" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 3306:3306 --env-file .kamal/env/accessories/app-mysql.env --label service=\"app-mysql\" private.registry/mysql:8.0",
|
"docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 3306:3306 --env-file .kamal/env/accessories/app-mysql.env --env MYSQL_ROOT_HOST=\"%\" --label service=\"app-mysql\" private.registry/mysql:8.0",
|
||||||
new_command(:mysql).run.join(" ")
|
new_command(:mysql).run.join(" ")
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume /var/lib/redis:/data --label service=\"app-redis\" --label cache=\"true\" redis:latest",
|
"docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --env SOMETHING=\"else\" --volume /var/lib/redis:/data --label service=\"app-redis\" --label cache=\"true\" redis:latest",
|
||||||
new_command(:redis).run.join(" ")
|
new_command(:redis).run.join(" ")
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --name app-busybox --detach --restart unless-stopped --log-opt max-size=\"10m\" --env-file .kamal/env/accessories/app-busybox.env --label service=\"app-busybox\" busybox:latest",
|
"docker run --name custom-busybox --detach --restart unless-stopped --log-opt max-size=\"10m\" --env-file .kamal/env/accessories/custom-busybox.env --label service=\"custom-busybox\" busybox:latest",
|
||||||
new_command(:busybox).run.join(" ")
|
new_command(:busybox).run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
@config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } }
|
@config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } }
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --name app-busybox --detach --restart unless-stopped --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --env-file .kamal/env/accessories/app-busybox.env --label service=\"app-busybox\" busybox:latest",
|
"docker run --name custom-busybox --detach --restart unless-stopped --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --env-file .kamal/env/accessories/custom-busybox.env --label service=\"custom-busybox\" busybox:latest",
|
||||||
new_command(:busybox).run.join(" ")
|
new_command(:busybox).run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "execute in new container" do
|
test "execute in new container" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --rm --env-file .kamal/env/accessories/app-mysql.env private.registry/mysql:8.0 mysql -u root",
|
"docker run --rm --env-file .kamal/env/accessories/app-mysql.env --env MYSQL_ROOT_HOST=\"%\" private.registry/mysql:8.0 mysql -u root",
|
||||||
new_command(:mysql).execute_in_new_container("mysql", "-u", "root").join(" ")
|
new_command(:mysql).execute_in_new_container("mysql", "-u", "root").join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -102,14 +103,14 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "execute in new container over ssh" do
|
test "execute in new container over ssh" do
|
||||||
new_command(:mysql).stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
new_command(:mysql).stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
||||||
assert_match %r|docker run -it --rm --env-file .kamal/env/accessories/app-mysql.env private.registry/mysql:8.0 mysql -u root|,
|
assert_match %r{docker run -it --rm --env-file .kamal/env/accessories/app-mysql.env --env MYSQL_ROOT_HOST=\"%\" private.registry/mysql:8.0 mysql -u root},
|
||||||
new_command(:mysql).execute_in_new_container_over_ssh("mysql", "-u", "root")
|
new_command(:mysql).execute_in_new_container_over_ssh("mysql", "-u", "root")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "execute in existing container over ssh" do
|
test "execute in existing container over ssh" do
|
||||||
new_command(:mysql).stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
new_command(:mysql).stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
||||||
assert_match %r|docker exec -it app-mysql mysql -u root|,
|
assert_match %r{docker exec -it app-mysql mysql -u root},
|
||||||
new_command(:mysql).execute_in_existing_container_over_ssh("mysql", "-u", "root")
|
new_command(:mysql).execute_in_existing_container_over_ssh("mysql", "-u", "root")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "run" do
|
test "run" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"(curl -f http://localhost:3000/up || exit 1) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --name app-web-999 --network kamal -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label destination dhh/app:999",
|
||||||
new_command.run.join(" ")
|
new_command.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "run with hostname" do
|
test "run with hostname" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --name app-web-999 --hostname myhost -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"(curl -f http://localhost:3000/up || exit 1) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --name app-web-999 --network kamal --hostname myhost -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label destination dhh/app:999",
|
||||||
new_command.run(hostname: "myhost").join(" ")
|
new_command.run(hostname: "myhost").join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
@config[:volumes] = [ "/local/path:/container/path" ]
|
@config[:volumes] = [ "/local/path:/container/path" ]
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"(curl -f http://localhost:3000/up || exit 1) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-opt max-size=\"10m\" --volume /local/path:/container/path --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --name app-web-999 --network kamal -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --volume /local/path:/container/path --label service=\"app\" --label role=\"web\" --label destination dhh/app:999",
|
||||||
new_command.run.join(" ")
|
new_command.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
@config[:healthcheck] = { "path" => "/healthz" }
|
@config[:healthcheck] = { "path" => "/healthz" }
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"(curl -f http://localhost:3000/healthz || exit 1) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --name app-web-999 --network kamal -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"curl -f http://localhost:3000/healthz || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label destination dhh/app:999",
|
||||||
new_command.run.join(" ")
|
new_command.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
@config[:healthcheck] = { "cmd" => "/bin/up" }
|
@config[:healthcheck] = { "cmd" => "/bin/up" }
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"(/bin/up) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --name app-web-999 --network kamal -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"/bin/up\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label destination dhh/app:999",
|
||||||
new_command.run.join(" ")
|
new_command.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -52,14 +52,14 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "healthcheck" => { "cmd" => "/bin/healthy" } } }
|
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "healthcheck" => { "cmd" => "/bin/healthy" } } }
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"(/bin/healthy) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --name app-web-999 --network kamal -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"/bin/healthy\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label destination dhh/app:999",
|
||||||
new_command.run.join(" ")
|
new_command.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "run with custom options" do
|
test "run with custom options" do
|
||||||
@config[:servers] = { "web" => [ "1.1.1.1" ], "jobs" => { "hosts" => [ "1.1.1.2" ], "cmd" => "bin/jobs", "options" => { "mount" => "somewhere", "cap-add" => true } } }
|
@config[:servers] = { "web" => [ "1.1.1.1" ], "jobs" => { "hosts" => [ "1.1.1.2" ], "cmd" => "bin/jobs", "options" => { "mount" => "somewhere", "cap-add" => true } } }
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --name app-jobs-999 -e KAMAL_CONTAINER_NAME=\"app-jobs-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-jobs.env --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"jobs\" --mount \"somewhere\" --cap-add dhh/app:999 bin/jobs",
|
"docker run --detach --restart unless-stopped --name app-jobs-999 --network kamal -e KAMAL_CONTAINER_NAME=\"app-jobs-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-jobs.env --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"jobs\" --label destination --mount \"somewhere\" --cap-add dhh/app:999 bin/jobs",
|
||||||
new_command(role: "jobs").run.join(" ")
|
new_command(role: "jobs").run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -67,7 +67,16 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
@config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } }
|
@config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } }
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"(curl -f http://localhost:3000/up || exit 1) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --name app-web-999 --network kamal -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app\" --label role=\"web\" --label destination dhh/app:999",
|
||||||
|
new_command.run.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "run with role logging config" do
|
||||||
|
@config[:logging] = { "driver" => "local", "options" => { "max-size" => "10m", "max-file" => "3" } }
|
||||||
|
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "logging" => { "driver" => "local", "options" => { "max-size" => "100m" } } } }
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker run --detach --restart unless-stopped --name app-web-999 --network kamal -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app\" --label role=\"web\" --label destination dhh/app:999",
|
||||||
new_command.run.join(" ")
|
new_command.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -145,12 +154,20 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "follow logs" do
|
test "follow logs" do
|
||||||
assert_match \
|
assert_match \
|
||||||
"docker ps --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest | xargs docker logs --timestamps --tail 10 --follow 2>&1",
|
"docker ps --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest | xargs docker logs --timestamps --follow 2>&1",
|
||||||
new_command.follow_logs(host: "app-1")
|
new_command.follow_logs(host: "app-1")
|
||||||
|
|
||||||
assert_match \
|
assert_match \
|
||||||
"docker ps --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest | xargs docker logs --timestamps --tail 10 --follow 2>&1 | grep \"Completed\"",
|
"docker ps --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest | xargs docker logs --timestamps --follow 2>&1 | grep \"Completed\"",
|
||||||
new_command.follow_logs(host: "app-1", grep: "Completed")
|
new_command.follow_logs(host: "app-1", grep: "Completed")
|
||||||
|
|
||||||
|
assert_match \
|
||||||
|
"docker ps --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest | xargs docker logs --timestamps --tail 123 --follow 2>&1",
|
||||||
|
new_command.follow_logs(host: "app-1", lines: 123)
|
||||||
|
|
||||||
|
assert_match \
|
||||||
|
"docker ps --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest | xargs docker logs --timestamps --tail 123 --follow 2>&1 | grep \"Completed\"",
|
||||||
|
new_command.follow_logs(host: "app-1", lines: 123, grep: "Completed")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -174,18 +191,18 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "execute in new container over ssh" do
|
test "execute in new container over ssh" do
|
||||||
assert_match %r|docker run -it --rm --env-file .kamal/env/roles/app-web.env dhh/app:999 bin/rails c|,
|
assert_match %r{docker run -it --rm --env-file .kamal/env/roles/app-web.env dhh/app:999 bin/rails c},
|
||||||
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "execute in new container with custom options over ssh" do
|
test "execute in new container with custom options over ssh" do
|
||||||
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere", "cap-add" => true } } }
|
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere", "cap-add" => true } } }
|
||||||
assert_match %r|docker run -it --rm --env-file .kamal/env/roles/app-web.env --mount \"somewhere\" --cap-add dhh/app:999 bin/rails c|,
|
assert_match %r{docker run -it --rm --env-file .kamal/env/roles/app-web.env --mount \"somewhere\" --cap-add dhh/app:999 bin/rails c},
|
||||||
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "execute in existing container over ssh" do
|
test "execute in existing container over ssh" do
|
||||||
assert_match %r|docker exec -it app-web-999 bin/rails c|,
|
assert_match %r{docker exec -it app-web-999 bin/rails c},
|
||||||
new_command.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1")
|
new_command.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -336,20 +353,6 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
assert_equal "rm -f .kamal/env/roles/app-web.env", new_command.remove_env_file.join(" ")
|
assert_equal "rm -f .kamal/env/roles/app-web.env", new_command.remove_env_file.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "cord" do
|
|
||||||
assert_equal "docker inspect -f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}' app-web-123 | awk '$2 == \"/tmp/kamal-cord\" {print $1}'", new_command.cord(version: 123).join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "tie cord" do
|
|
||||||
assert_equal "mkdir -p . ; touch cordfile", new_command.tie_cord("cordfile").join(" ")
|
|
||||||
assert_equal "mkdir -p corddir ; touch corddir/cordfile", new_command.tie_cord("corddir/cordfile").join(" ")
|
|
||||||
assert_equal "mkdir -p /corddir ; touch /corddir/cordfile", new_command.tie_cord("/corddir/cordfile").join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "cut cord" do
|
|
||||||
assert_equal "rm -r corddir", new_command.cut_cord("corddir").join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "extract assets" do
|
test "extract assets" do
|
||||||
assert_equal [
|
assert_equal [
|
||||||
:mkdir, "-p", ".kamal/assets/extracted/app-web-999", "&&",
|
:mkdir, "-p", ".kamal/assets/extracted/app-web-999", "&&",
|
||||||
@@ -370,7 +373,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
:mkdir, "-p", ".kamal/assets/volumes/app-web-999", ";",
|
:mkdir, "-p", ".kamal/assets/volumes/app-web-999", ";",
|
||||||
:cp, "-rnT", ".kamal/assets/extracted/app-web-999", ".kamal/assets/volumes/app-web-999", ";",
|
:cp, "-rnT", ".kamal/assets/extracted/app-web-999", ".kamal/assets/volumes/app-web-999", ";",
|
||||||
:cp, "-rnT", ".kamal/assets/extracted/app-web-999", ".kamal/assets/volumes/app-web-998", "|| true", ";",
|
:cp, "-rnT", ".kamal/assets/extracted/app-web-999", ".kamal/assets/volumes/app-web-998", "|| true", ";",
|
||||||
:cp, "-rnT", ".kamal/assets/extracted/app-web-998", ".kamal/assets/volumes/app-web-999", "|| true",
|
:cp, "-rnT", ".kamal/assets/extracted/app-web-998", ".kamal/assets/volumes/app-web-999", "|| true"
|
||||||
], new_command(asset_path: "/public/assets").sync_asset_volumes(old_version: 998)
|
], new_command(asset_path: "/public/assets").sync_asset_volumes(old_version: 998)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -383,6 +386,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
private
|
private
|
||||||
def new_command(role: "web", **additional_config)
|
def new_command(role: "web", **additional_config)
|
||||||
Kamal::Commands::App.new(Kamal::Configuration.new(@config.merge(additional_config), destination: @destination, version: "999"), role: role)
|
config = Kamal::Configuration.new(@config.merge(additional_config), destination: @destination, version: "999")
|
||||||
|
Kamal::Commands::App.new(config, role: config.role(role))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
builder = new_builder_command(builder: { "cache" => { "type" => "gha" } })
|
builder = new_builder_command(builder: { "cache" => { "type" => "gha" } })
|
||||||
assert_equal "multiarch", builder.name
|
assert_equal "multiarch", builder.name
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
|
"git archive --format=tar HEAD | docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile -",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
builder = new_builder_command(builder: { "multiarch" => false })
|
builder = new_builder_command(builder: { "multiarch" => false })
|
||||||
assert_equal "native", builder.name
|
assert_equal "native", builder.name
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile . && docker push dhh/app:123 && docker push dhh/app:latest",
|
"git archive --format=tar HEAD | docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile - && docker push dhh/app:123 && docker push dhh/app:latest",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
builder = new_builder_command(builder: { "multiarch" => false, "cache" => { "type" => "gha" } })
|
builder = new_builder_command(builder: { "multiarch" => false, "cache" => { "type" => "gha" } })
|
||||||
assert_equal "native/cached", builder.name
|
assert_equal "native/cached", builder.name
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker buildx build --push -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
|
"git archive --format=tar HEAD | docker buildx build --push -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile -",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -33,7 +33,15 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
builder = new_builder_command(builder: { "local" => {}, "remote" => {}, "cache" => { "type" => "gha" } })
|
builder = new_builder_command(builder: { "local" => {}, "remote" => {}, "cache" => { "type" => "gha" } })
|
||||||
assert_equal "multiarch/remote", builder.name
|
assert_equal "multiarch/remote", builder.name
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
|
"git archive --format=tar HEAD | docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile -",
|
||||||
|
builder.push.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "target multiarch local when arch is set" do
|
||||||
|
builder = new_builder_command(builder: { "local" => { "arch" => "amd64" } })
|
||||||
|
assert_equal "multiarch", builder.name
|
||||||
|
assert_equal \
|
||||||
|
"git archive --format=tar HEAD | docker buildx build --push --platform linux/amd64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile -",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -41,7 +49,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } })
|
builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } })
|
||||||
assert_equal "native/remote", builder.name
|
assert_equal "native/remote", builder.name
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker buildx build --push --platform linux/amd64 --builder kamal-app-native-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
|
"git archive --format=tar HEAD | docker buildx build --push --platform linux/amd64 --builder kamal-app-native-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile -",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -85,26 +93,62 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
test "native push with build args" do
|
test "native push with build args" do
|
||||||
builder = new_builder_command(builder: { "multiarch" => false, "args" => { "a" => 1, "b" => 2 } })
|
builder = new_builder_command(builder: { "multiarch" => false, "args" => { "a" => 1, "b" => 2 } })
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" --file Dockerfile . && docker push dhh/app:123 && docker push dhh/app:latest",
|
"git archive --format=tar HEAD | docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" --file Dockerfile - && docker push dhh/app:123 && docker push dhh/app:latest",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "multiarch push with build args" do
|
test "multiarch push with build args" do
|
||||||
builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } })
|
builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } })
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" --file Dockerfile .",
|
"git archive --format=tar HEAD | docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" --file Dockerfile -",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "native push with build secrets" do
|
test "native push with build secrets" do
|
||||||
builder = new_builder_command(builder: { "multiarch" => false, "secrets" => [ "a", "b" ] })
|
builder = new_builder_command(builder: { "multiarch" => false, "secrets" => [ "a", "b" ] })
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --secret id=\"a\" --secret id=\"b\" --file Dockerfile . && docker push dhh/app:123 && docker push dhh/app:latest",
|
"git archive --format=tar HEAD | docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --secret id=\"a\" --secret id=\"b\" --file Dockerfile - && docker push dhh/app:123 && docker push dhh/app:latest",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "build with ssh agent socket" do
|
||||||
|
builder = new_builder_command(builder: { "ssh" => "default=$SSH_AUTH_SOCK" })
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"-t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile --ssh default=$SSH_AUTH_SOCK",
|
||||||
|
builder.target.build_options.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
test "validate image" do
|
test "validate image" do
|
||||||
assert_equal "docker inspect -f '{{ .Config.Labels.service }}' dhh/app:123 | grep -x app || (echo \"Image dhh/app:123 is missing the `service` label\" && exit 1)", new_builder_command.validate_image.join(" ")
|
assert_equal "docker inspect -f '{{ .Config.Labels.service }}' dhh/app:123 | grep -x app || (echo \"Image dhh/app:123 is missing the 'service' label\" && exit 1)", new_builder_command.validate_image.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "multiarch context build" do
|
||||||
|
builder = new_builder_command(builder: { "context" => "./foo" })
|
||||||
|
assert_equal \
|
||||||
|
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo",
|
||||||
|
builder.push.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "native context build" do
|
||||||
|
builder = new_builder_command(builder: { "multiarch" => false, "context" => "./foo" })
|
||||||
|
assert_equal \
|
||||||
|
"docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo && docker push dhh/app:123 && docker push dhh/app:latest",
|
||||||
|
builder.push.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cached context build" do
|
||||||
|
builder = new_builder_command(builder: { "multiarch" => false, "context" => "./foo", "cache" => { "type" => "gha" } })
|
||||||
|
assert_equal \
|
||||||
|
"docker buildx build --push -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile ./foo",
|
||||||
|
builder.push.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "remote context build" do
|
||||||
|
builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "context" => "./foo" })
|
||||||
|
assert_equal \
|
||||||
|
"docker buildx build --push --platform linux/amd64 --builder kamal-app-native-remote -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo",
|
||||||
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class CommandsDockerTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "install" do
|
test "install" do
|
||||||
assert_equal "curl -fsSL https://get.docker.com | sh", @docker.install.join(" ")
|
assert_equal "sh -c 'curl -fsSL https://get.docker.com || wget -O - https://get.docker.com || echo \"exit 1\"' | sh", @docker.install.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "installed?" do
|
test "installed?" do
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ require "test_helper"
|
|||||||
class CommandsHealthcheckTest < ActiveSupport::TestCase
|
class CommandsHealthcheckTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@config = {
|
@config = {
|
||||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ],
|
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ]
|
||||||
traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ class CommandsHookTest < ActiveSupport::TestCase
|
|||||||
freeze_time
|
freeze_time
|
||||||
|
|
||||||
@config = {
|
@config = {
|
||||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ],
|
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ]
|
||||||
traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@performer = `whoami`.strip
|
@performer = `whoami`.strip
|
||||||
|
|||||||
@@ -3,31 +3,30 @@ require "test_helper"
|
|||||||
class CommandsLockTest < ActiveSupport::TestCase
|
class CommandsLockTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@config = {
|
@config = {
|
||||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ],
|
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ]
|
||||||
traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "status" do
|
test "status" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"stat .kamal/lock-app > /dev/null && cat .kamal/lock-app/details | base64 -d",
|
"stat .kamal/locks/app-production > /dev/null && cat .kamal/locks/app-production/details | base64 -d",
|
||||||
new_command.status.join(" ")
|
new_command.status.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "acquire" do
|
test "acquire" do
|
||||||
assert_match \
|
assert_match \
|
||||||
%r{mkdir \.kamal/lock-app && echo ".*" > \.kamal/lock-app/details}m,
|
%r{mkdir \.kamal/locks/app-production && echo ".*" > \.kamal/locks/app-production/details}m,
|
||||||
new_command.acquire("Hello", "123").join(" ")
|
new_command.acquire("Hello", "123").join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "release" do
|
test "release" do
|
||||||
assert_match \
|
assert_match \
|
||||||
"rm .kamal/lock-app/details && rm -r .kamal/lock-app",
|
"rm .kamal/locks/app-production/details && rm -r .kamal/locks/app-production",
|
||||||
new_command.release.join(" ")
|
new_command.release.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def new_command
|
def new_command
|
||||||
Kamal::Commands::Lock.new(Kamal::Configuration.new(@config, version: "123"))
|
Kamal::Commands::Lock.new(Kamal::Configuration.new(@config, version: "123", destination: "production"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
114
test/commands/proxy_test.rb
Normal file
114
test/commands/proxy_test.rb
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class CommandsProxyTest < ActiveSupport::TestCase
|
||||||
|
setup do
|
||||||
|
@config = {
|
||||||
|
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
ENV["EXAMPLE_API_KEY"] = "456"
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
ENV.delete("EXAMPLE_API_KEY")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "run" do
|
||||||
|
assert_equal \
|
||||||
|
"docker run --name mproxy --detach --restart unless-stopped --network kamal --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Kamal::Commands::Proxy::DEFAULT_IMAGE}",
|
||||||
|
new_command.run.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "run with ports configured" do
|
||||||
|
assert_equal \
|
||||||
|
"docker run --name mproxy --detach --restart unless-stopped --network kamal --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Kamal::Commands::Proxy::DEFAULT_IMAGE}",
|
||||||
|
new_command.run.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "run without configuration" do
|
||||||
|
@config.delete(:proxy)
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker run --name mproxy --detach --restart unless-stopped --network kamal --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Kamal::Commands::Proxy::DEFAULT_IMAGE}",
|
||||||
|
new_command.run.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "run with logging config" do
|
||||||
|
@config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } }
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker run --name mproxy --detach --restart unless-stopped --network kamal --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" #{Kamal::Commands::Proxy::DEFAULT_IMAGE}",
|
||||||
|
new_command.run.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy start" do
|
||||||
|
assert_equal \
|
||||||
|
"docker container start mproxy",
|
||||||
|
new_command.start.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy stop" do
|
||||||
|
assert_equal \
|
||||||
|
"docker container stop mproxy",
|
||||||
|
new_command.stop.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy info" do
|
||||||
|
assert_equal \
|
||||||
|
"docker ps --filter name=^mproxy$",
|
||||||
|
new_command.info.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy logs" do
|
||||||
|
assert_equal \
|
||||||
|
"docker logs mproxy --timestamps 2>&1",
|
||||||
|
new_command.logs.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy logs since 2h" do
|
||||||
|
assert_equal \
|
||||||
|
"docker logs mproxy --since 2h --timestamps 2>&1",
|
||||||
|
new_command.logs(since: "2h").join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy logs last 10 lines" do
|
||||||
|
assert_equal \
|
||||||
|
"docker logs mproxy --tail 10 --timestamps 2>&1",
|
||||||
|
new_command.logs(lines: 10).join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy logs with grep hello!" do
|
||||||
|
assert_equal \
|
||||||
|
"docker logs mproxy --timestamps 2>&1 | grep 'hello!'",
|
||||||
|
new_command.logs(grep: "hello!").join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy remove container" do
|
||||||
|
assert_equal \
|
||||||
|
"docker container prune --force --filter label=org.opencontainers.image.title=mproxy",
|
||||||
|
new_command.remove_container.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy remove image" do
|
||||||
|
assert_equal \
|
||||||
|
"docker image prune --all --force --filter label=org.opencontainers.image.title=mproxy",
|
||||||
|
new_command.remove_image.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy follow logs" do
|
||||||
|
assert_equal \
|
||||||
|
"ssh -t root@1.1.1.1 -p 22 'docker logs mproxy --timestamps --tail 10 --follow 2>&1'",
|
||||||
|
new_command.follow_logs(host: @config[:servers].first)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "proxy follow logs with grep hello!" do
|
||||||
|
assert_equal \
|
||||||
|
"ssh -t root@1.1.1.1 -p 22 'docker logs mproxy --timestamps --tail 10 --follow 2>&1 | grep \"hello!\"'",
|
||||||
|
new_command.follow_logs(host: @config[:servers].first, grep: "hello!")
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def new_command
|
||||||
|
Kamal::Commands::Proxy.new(Kamal::Configuration.new(@config, version: "123"))
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -3,8 +3,7 @@ require "test_helper"
|
|||||||
class CommandsPruneTest < ActiveSupport::TestCase
|
class CommandsPruneTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@config = {
|
@config = {
|
||||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ],
|
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ]
|
||||||
traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -23,7 +22,11 @@ class CommandsPruneTest < ActiveSupport::TestCase
|
|||||||
test "app containers" do
|
test "app containers" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker ps -q -a --filter label=service=app --filter status=created --filter status=exited --filter status=dead | tail -n +6 | while read container_id; do docker rm $container_id; done",
|
"docker ps -q -a --filter label=service=app --filter status=created --filter status=exited --filter status=dead | tail -n +6 | while read container_id; do docker rm $container_id; done",
|
||||||
new_command.app_containers.join(" ")
|
new_command.app_containers(retain: 5).join(" ")
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker ps -q -a --filter label=service=app --filter status=created --filter status=exited --filter status=dead | tail -n +4 | while read container_id; do docker rm $container_id; done",
|
||||||
|
new_command.app_containers(retain: 3).join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "healthcheck containers" do
|
test "healthcheck containers" do
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class CommandsRegistryTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "registry login" do
|
test "registry login" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker login hub.docker.com -u dhh -p secret",
|
"docker login hub.docker.com -u \"dhh\" -p \"secret\"",
|
||||||
@registry.login.join(" ")
|
@registry.login.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -24,7 +24,18 @@ class CommandsRegistryTest < ActiveSupport::TestCase
|
|||||||
@config[:registry]["password"] = [ "KAMAL_REGISTRY_PASSWORD" ]
|
@config[:registry]["password"] = [ "KAMAL_REGISTRY_PASSWORD" ]
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker login hub.docker.com -u dhh -p more-secret",
|
"docker login hub.docker.com -u \"dhh\" -p \"more-secret\"",
|
||||||
|
@registry.login.join(" ")
|
||||||
|
ensure
|
||||||
|
ENV.delete("KAMAL_REGISTRY_PASSWORD")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "registry login escape password" do
|
||||||
|
ENV["KAMAL_REGISTRY_PASSWORD"] = "more-secret'\""
|
||||||
|
@config[:registry]["password"] = [ "KAMAL_REGISTRY_PASSWORD" ]
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker login hub.docker.com -u \"dhh\" -p \"more-secret'\\\"\"",
|
||||||
@registry.login.join(" ")
|
@registry.login.join(" ")
|
||||||
ensure
|
ensure
|
||||||
ENV.delete("KAMAL_REGISTRY_PASSWORD")
|
ENV.delete("KAMAL_REGISTRY_PASSWORD")
|
||||||
@@ -35,7 +46,7 @@ class CommandsRegistryTest < ActiveSupport::TestCase
|
|||||||
@config[:registry]["username"] = [ "KAMAL_REGISTRY_USERNAME" ]
|
@config[:registry]["username"] = [ "KAMAL_REGISTRY_USERNAME" ]
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker login hub.docker.com -u also-secret -p secret",
|
"docker login hub.docker.com -u \"also-secret\" -p \"secret\"",
|
||||||
@registry.login.join(" ")
|
@registry.login.join(" ")
|
||||||
ensure
|
ensure
|
||||||
ENV.delete("KAMAL_REGISTRY_USERNAME")
|
ENV.delete("KAMAL_REGISTRY_USERNAME")
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ require "test_helper"
|
|||||||
class CommandsServerTest < ActiveSupport::TestCase
|
class CommandsServerTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@config = {
|
@config = {
|
||||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ],
|
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ]
|
||||||
traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,202 +0,0 @@
|
|||||||
require "test_helper"
|
|
||||||
|
|
||||||
class CommandsTraefikTest < ActiveSupport::TestCase
|
|
||||||
setup do
|
|
||||||
@image = "traefik:test"
|
|
||||||
|
|
||||||
@config = {
|
|
||||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ],
|
|
||||||
traefik: { "image" => @image, "args" => { "accesslog.format" => "json", "api.insecure" => true, "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
|
|
||||||
}
|
|
||||||
|
|
||||||
ENV["EXAMPLE_API_KEY"] = "456"
|
|
||||||
end
|
|
||||||
|
|
||||||
teardown do
|
|
||||||
ENV.delete("EXAMPLE_API_KEY")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run" do
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
|
|
||||||
@config[:traefik]["host_port"] = "8080"
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 8080:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
|
|
||||||
@config[:traefik]["publish"] = false
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run with ports configured" do
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
|
|
||||||
@config[:traefik]["options"] = {"publish" => %w[9000:9000 9001:9001]}
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" --publish \"9000:9000\" --publish \"9001:9001\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run with volumes configured" do
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
|
|
||||||
@config[:traefik]["options"] = {"volume" => %w[./letsencrypt/acme.json:/letsencrypt/acme.json] }
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" --volume \"./letsencrypt/acme.json:/letsencrypt/acme.json\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run with several options configured" do
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
|
|
||||||
@config[:traefik]["options"] = {"volume" => %w[./letsencrypt/acme.json:/letsencrypt/acme.json], "publish" => %w[8080:8080], "memory" => "512m"}
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" --volume \"./letsencrypt/acme.json:/letsencrypt/acme.json\" --publish \"8080:8080\" --memory \"512m\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run with labels configured" do
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
|
|
||||||
@config[:traefik]["labels"] = { "traefik.http.routers.dashboard.service" => "api@internal", "traefik.http.routers.dashboard.middlewares" => "auth" }
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" --label traefik.http.routers.dashboard.service=\"api@internal\" --label traefik.http.routers.dashboard.middlewares=\"auth\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run with env configured" do
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
|
|
||||||
@config[:traefik]["env"] = { "secret" => %w[EXAMPLE_API_KEY] }
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run without configuration" do
|
|
||||||
@config.delete(:traefik)
|
|
||||||
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{Kamal::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run with logging config" do
|
|
||||||
@config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } }
|
|
||||||
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run with default args overriden" do
|
|
||||||
@config[:traefik]["args"]["log.level"] = "ERROR"
|
|
||||||
|
|
||||||
assert_equal \
|
|
||||||
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" #{@image} --providers.docker --log.level=\"ERROR\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
|
|
||||||
new_command.run.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik start" do
|
|
||||||
assert_equal \
|
|
||||||
"docker container start traefik",
|
|
||||||
new_command.start.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik stop" do
|
|
||||||
assert_equal \
|
|
||||||
"docker container stop traefik",
|
|
||||||
new_command.stop.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik info" do
|
|
||||||
assert_equal \
|
|
||||||
"docker ps --filter name=^traefik$",
|
|
||||||
new_command.info.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik logs" do
|
|
||||||
assert_equal \
|
|
||||||
"docker logs traefik --timestamps 2>&1",
|
|
||||||
new_command.logs.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik logs since 2h" do
|
|
||||||
assert_equal \
|
|
||||||
"docker logs traefik --since 2h --timestamps 2>&1",
|
|
||||||
new_command.logs(since: '2h').join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik logs last 10 lines" do
|
|
||||||
assert_equal \
|
|
||||||
"docker logs traefik --tail 10 --timestamps 2>&1",
|
|
||||||
new_command.logs(lines: 10).join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik logs with grep hello!" do
|
|
||||||
assert_equal \
|
|
||||||
"docker logs traefik --timestamps 2>&1 | grep 'hello!'",
|
|
||||||
new_command.logs(grep: 'hello!').join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik remove container" do
|
|
||||||
assert_equal \
|
|
||||||
"docker container prune --force --filter label=org.opencontainers.image.title=Traefik",
|
|
||||||
new_command.remove_container.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik remove image" do
|
|
||||||
assert_equal \
|
|
||||||
"docker image prune --all --force --filter label=org.opencontainers.image.title=Traefik",
|
|
||||||
new_command.remove_image.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik follow logs" do
|
|
||||||
assert_equal \
|
|
||||||
"ssh -t root@1.1.1.1 -p 22 'docker logs traefik --timestamps --tail 10 --follow 2>&1'",
|
|
||||||
new_command.follow_logs(host: @config[:servers].first)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "traefik follow logs with grep hello!" do
|
|
||||||
assert_equal \
|
|
||||||
"ssh -t root@1.1.1.1 -p 22 'docker logs traefik --timestamps --tail 10 --follow 2>&1 | grep \"hello!\"'",
|
|
||||||
new_command.follow_logs(host: @config[:servers].first, grep: 'hello!')
|
|
||||||
end
|
|
||||||
|
|
||||||
test "env_file" do
|
|
||||||
@config[:traefik]["env"] = { "secret" => %w[EXAMPLE_API_KEY] }
|
|
||||||
|
|
||||||
assert_equal "EXAMPLE_API_KEY=456\n", new_command.env_file.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
test "host_env_file_path" do
|
|
||||||
assert_equal ".kamal/env/traefik/traefik.env", new_command.host_env_file_path
|
|
||||||
end
|
|
||||||
|
|
||||||
test "make_env_directory" do
|
|
||||||
assert_equal "mkdir -p .kamal/env/traefik", new_command.make_env_directory.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "remove_env_file" do
|
|
||||||
assert_equal "rm -f .kamal/env/traefik/traefik.env", new_command.remove_env_file.join(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def new_command
|
|
||||||
Kamal::Commands::Traefik.new(Kamal::Configuration.new(@config, version: "123"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -20,7 +20,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
},
|
},
|
||||||
"secret" => [
|
"secret" => [
|
||||||
"MYSQL_ROOT_PASSWORD"
|
"MYSQL_ROOT_PASSWORD"
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
"files" => [
|
"files" => [
|
||||||
"config/mysql/my.cnf:/etc/mysql/my.cnf",
|
"config/mysql/my.cnf:/etc/mysql/my.cnf",
|
||||||
@@ -49,6 +49,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"monitoring" => {
|
"monitoring" => {
|
||||||
|
"service" => "custom-monitoring",
|
||||||
"image" => "monitoring:latest",
|
"image" => "monitoring:latest",
|
||||||
"roles" => [ "web" ],
|
"roles" => [ "web" ],
|
||||||
"port" => "4321:4321",
|
"port" => "4321:4321",
|
||||||
@@ -72,6 +73,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
test "service name" do
|
test "service name" do
|
||||||
assert_equal "app-mysql", @config.accessory(:mysql).service_name
|
assert_equal "app-mysql", @config.accessory(:mysql).service_name
|
||||||
assert_equal "app-redis", @config.accessory(:redis).service_name
|
assert_equal "app-redis", @config.accessory(:redis).service_name
|
||||||
|
assert_equal "custom-monitoring", @config.accessory(:monitoring).service_name
|
||||||
end
|
end
|
||||||
|
|
||||||
test "port" do
|
test "port" do
|
||||||
@@ -111,29 +113,25 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "env args" do
|
test "env args" do
|
||||||
assert_equal ["--env-file", ".kamal/env/accessories/app-mysql.env"], @config.accessory(:mysql).env_args
|
assert_equal [ "--env-file", ".kamal/env/accessories/app-mysql.env", "--env", "MYSQL_ROOT_HOST=\"%\"" ], @config.accessory(:mysql).env_args
|
||||||
assert_equal ["--env-file", ".kamal/env/accessories/app-redis.env"], @config.accessory(:redis).env_args
|
assert_equal [ "--env-file", ".kamal/env/accessories/app-redis.env", "--env", "SOMETHING=\"else\"" ], @config.accessory(:redis).env_args
|
||||||
end
|
end
|
||||||
|
|
||||||
test "env file with secret" do
|
test "env with secrets" do
|
||||||
ENV["MYSQL_ROOT_PASSWORD"] = "secret123"
|
ENV["MYSQL_ROOT_PASSWORD"] = "secret123"
|
||||||
|
|
||||||
expected = <<~ENV
|
expected_secrets_file = <<~ENV
|
||||||
MYSQL_ROOT_PASSWORD=secret123
|
MYSQL_ROOT_PASSWORD=secret123
|
||||||
MYSQL_ROOT_HOST=%
|
|
||||||
ENV
|
ENV
|
||||||
|
|
||||||
assert_equal expected, @config.accessory(:mysql).env_file.to_s
|
assert_equal expected_secrets_file, @config.accessory(:mysql).env.secrets_io.string
|
||||||
|
assert_equal [ "--env-file", ".kamal/env/accessories/app-mysql.env", "--env", "MYSQL_ROOT_HOST=\"%\"" ], @config.accessory(:mysql).env_args
|
||||||
ensure
|
ensure
|
||||||
ENV["MYSQL_ROOT_PASSWORD"] = nil
|
ENV["MYSQL_ROOT_PASSWORD"] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
test "host_env_directory" do
|
test "env secrets path" do
|
||||||
assert_equal ".kamal/env/accessories", @config.accessory(:mysql).host_env_directory
|
assert_equal ".kamal/env/accessories/app-mysql.env", @config.accessory(:mysql).env.secrets_file
|
||||||
end
|
|
||||||
|
|
||||||
test "host_env_file_path" do
|
|
||||||
assert_equal ".kamal/env/accessories/app-mysql.env", @config.accessory(:mysql).host_env_file_path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "volume args" do
|
test "volume args" do
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "context" do
|
test "context" do
|
||||||
assert_equal ".", @config.builder.context
|
assert_equal "-", @config.builder.context
|
||||||
end
|
end
|
||||||
|
|
||||||
test "setting context" do
|
test "setting context" do
|
||||||
@@ -148,4 +148,14 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_equal "..", @config_with_builder_option.builder.context
|
assert_equal "..", @config_with_builder_option.builder.context
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "ssh" do
|
||||||
|
assert_nil @config.builder.ssh
|
||||||
|
end
|
||||||
|
|
||||||
|
test "setting ssh params" do
|
||||||
|
@deploy_with_builder_option[:builder] = { "ssh" => "default=$SSH_AUTH_SOCK" }
|
||||||
|
|
||||||
|
assert_equal "default=$SSH_AUTH_SOCK", @config_with_builder_option.builder.ssh
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
74
test/configuration/env_test.rb
Normal file
74
test/configuration/env_test.rb
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ConfigurationEnvTest < ActiveSupport::TestCase
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
test "simple" do
|
||||||
|
assert_config \
|
||||||
|
config: { "foo" => "bar", "baz" => "haz" },
|
||||||
|
clear: { "foo" => "bar", "baz" => "haz" },
|
||||||
|
secrets: {}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "clear" do
|
||||||
|
assert_config \
|
||||||
|
config: { "clear" => { "foo" => "bar", "baz" => "haz" } },
|
||||||
|
clear: { "foo" => "bar", "baz" => "haz" },
|
||||||
|
secrets: {}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "secret" do
|
||||||
|
ENV["PASSWORD"] = "hello"
|
||||||
|
env = Kamal::Configuration::Env.from_config config: { "secret" => [ "PASSWORD" ] }
|
||||||
|
|
||||||
|
assert_config \
|
||||||
|
config: { "secret" => [ "PASSWORD" ] },
|
||||||
|
clear: {},
|
||||||
|
secrets: { "PASSWORD" => "hello" }
|
||||||
|
ensure
|
||||||
|
ENV.delete "PASSWORD"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "missing secret" do
|
||||||
|
env = {
|
||||||
|
"secret" => [ "PASSWORD" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_raises(KeyError) { Kamal::Configuration::Env.from_config(config: { "secret" => [ "PASSWORD" ] }).secrets }
|
||||||
|
end
|
||||||
|
|
||||||
|
test "secret and clear" do
|
||||||
|
ENV["PASSWORD"] = "hello"
|
||||||
|
config = {
|
||||||
|
"secret" => [ "PASSWORD" ],
|
||||||
|
"clear" => {
|
||||||
|
"foo" => "bar",
|
||||||
|
"baz" => "haz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_config \
|
||||||
|
config: config,
|
||||||
|
clear: { "foo" => "bar", "baz" => "haz" },
|
||||||
|
secrets: { "PASSWORD" => "hello" }
|
||||||
|
ensure
|
||||||
|
ENV.delete "PASSWORD"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "stringIO conversion" do
|
||||||
|
env = {
|
||||||
|
"foo" => "bar",
|
||||||
|
"baz" => "haz"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equal "foo=bar\nbaz=haz\n", \
|
||||||
|
StringIO.new(Kamal::EnvFile.new(env)).read
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def assert_config(config:, clear:, secrets:)
|
||||||
|
env = Kamal::Configuration::Env.from_config config: config
|
||||||
|
assert_equal clear, env.clear
|
||||||
|
assert_equal secrets, env.secrets
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -38,11 +38,11 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "label args" do
|
test "label args" do
|
||||||
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"workers\"" ], @config_with_roles.role(:workers).label_args
|
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"workers\"", "--label", "destination" ], @config_with_roles.role(:workers).label_args
|
||||||
end
|
end
|
||||||
|
|
||||||
test "special label args for web" do
|
test "special label args for web" do
|
||||||
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"web\"", "--label", "traefik.http.services.app-web.loadbalancer.server.scheme=\"http\"", "--label", "traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\"", "--label", "traefik.http.routers.app-web.priority=\"2\"", "--label", "traefik.http.middlewares.app-web-retry.retry.attempts=\"5\"", "--label", "traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\"", "--label", "traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\"" ], @config.role(:web).label_args
|
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"web\"", "--label", "destination" ], @config.role(:web).label_args
|
||||||
end
|
end
|
||||||
|
|
||||||
test "custom labels" do
|
test "custom labels" do
|
||||||
@@ -56,28 +56,11 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
assert_equal "70", @config_with_roles.role(:workers).labels["my.custom.label"]
|
assert_equal "70", @config_with_roles.role(:workers).labels["my.custom.label"]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "overwriting default traefik label" do
|
|
||||||
@deploy[:labels] = { "traefik.http.routers.app-web.rule" => "\"Host(\\`example.com\\`) || (Host(\\`example.org\\`) && Path(\\`/traefik\\`))\"" }
|
|
||||||
assert_equal "\"Host(\\`example.com\\`) || (Host(\\`example.org\\`) && Path(\\`/traefik\\`))\"", @config.role(:web).labels["traefik.http.routers.app-web.rule"]
|
|
||||||
end
|
|
||||||
|
|
||||||
test "default traefik label on non-web role" do
|
|
||||||
config = Kamal::Configuration.new(@deploy_with_roles.tap { |c|
|
|
||||||
c[:servers]["beta"] = { "traefik" => "true", "hosts" => [ "1.1.1.5" ] }
|
|
||||||
})
|
|
||||||
|
|
||||||
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"beta\"", "--label", "traefik.http.services.app-beta.loadbalancer.server.scheme=\"http\"", "--label", "traefik.http.routers.app-beta.rule=\"PathPrefix(\\`/\\`)\"", "--label", "traefik.http.routers.app-beta.priority=\"2\"", "--label", "traefik.http.middlewares.app-beta-retry.retry.attempts=\"5\"", "--label", "traefik.http.middlewares.app-beta-retry.retry.initialinterval=\"500ms\"", "--label", "traefik.http.routers.app-beta.middlewares=\"app-beta-retry@docker\"" ], config.role(:beta).label_args
|
|
||||||
end
|
|
||||||
|
|
||||||
test "env overwritten by role" do
|
test "env overwritten by role" do
|
||||||
assert_equal "redis://a/b", @config_with_roles.role(:workers).env["REDIS_URL"]
|
assert_equal "redis://a/b", @config_with_roles.role(:workers).env.clear["REDIS_URL"]
|
||||||
|
|
||||||
expected_env = <<~ENV
|
assert_equal "\n", @config_with_roles.role(:workers).env.secrets_io.string
|
||||||
REDIS_URL=redis://a/b
|
assert_equal [ "--env-file", ".kamal/env/roles/app-workers.env", "--env", "REDIS_URL=\"redis://a/b\"", "--env", "WEB_CONCURRENCY=\"4\"" ], @config_with_roles.role(:workers).env_args
|
||||||
WEB_CONCURRENCY=4
|
|
||||||
ENV
|
|
||||||
|
|
||||||
assert_equal expected_env, @config_with_roles.role(:workers).env_file.to_s
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "container name" do
|
test "container name" do
|
||||||
@@ -90,7 +73,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "env args" do
|
test "env args" do
|
||||||
assert_equal ["--env-file", ".kamal/env/roles/app-workers.env"], @config_with_roles.role(:workers).env_args
|
assert_equal [ "--env-file", ".kamal/env/roles/app-workers.env", "--env", "REDIS_URL=\"redis://a/b\"", "--env", "WEB_CONCURRENCY=\"4\"" ], @config_with_roles.role(:workers).env_args
|
||||||
end
|
end
|
||||||
|
|
||||||
test "env secret overwritten by role" do
|
test "env secret overwritten by role" do
|
||||||
@@ -116,14 +99,13 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
ENV["REDIS_PASSWORD"] = "secret456"
|
ENV["REDIS_PASSWORD"] = "secret456"
|
||||||
ENV["DB_PASSWORD"] = "secret&\"123"
|
ENV["DB_PASSWORD"] = "secret&\"123"
|
||||||
|
|
||||||
expected = <<~ENV
|
expected_secrets_file = <<~ENV
|
||||||
REDIS_PASSWORD=secret456
|
REDIS_PASSWORD=secret456
|
||||||
DB_PASSWORD=secret&\"123
|
DB_PASSWORD=secret&\"123
|
||||||
REDIS_URL=redis://a/b
|
|
||||||
WEB_CONCURRENCY=4
|
|
||||||
ENV
|
ENV
|
||||||
|
|
||||||
assert_equal expected, @config_with_roles.role(:workers).env_file.to_s
|
assert_equal expected_secrets_file, @config_with_roles.role(:workers).env.secrets_io.string
|
||||||
|
assert_equal [ "--env-file", ".kamal/env/roles/app-workers.env", "--env", "REDIS_URL=\"redis://a/b\"", "--env", "WEB_CONCURRENCY=\"4\"" ], @config_with_roles.role(:workers).env_args
|
||||||
ensure
|
ensure
|
||||||
ENV["REDIS_PASSWORD"] = nil
|
ENV["REDIS_PASSWORD"] = nil
|
||||||
ENV["DB_PASSWORD"] = nil
|
ENV["DB_PASSWORD"] = nil
|
||||||
@@ -142,13 +124,12 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
ENV["DB_PASSWORD"] = "secret123"
|
ENV["DB_PASSWORD"] = "secret123"
|
||||||
|
|
||||||
expected = <<~ENV
|
expected_secrets_file = <<~ENV
|
||||||
DB_PASSWORD=secret123
|
DB_PASSWORD=secret123
|
||||||
REDIS_URL=redis://a/b
|
|
||||||
WEB_CONCURRENCY=4
|
|
||||||
ENV
|
ENV
|
||||||
|
|
||||||
assert_equal expected, @config_with_roles.role(:workers).env_file.to_s
|
assert_equal expected_secrets_file, @config_with_roles.role(:workers).env.secrets_io.string
|
||||||
|
assert_equal [ "--env-file", ".kamal/env/roles/app-workers.env", "--env", "REDIS_URL=\"redis://a/b\"", "--env", "WEB_CONCURRENCY=\"4\"" ], @config_with_roles.role(:workers).env_args
|
||||||
ensure
|
ensure
|
||||||
ENV["DB_PASSWORD"] = nil
|
ENV["DB_PASSWORD"] = nil
|
||||||
end
|
end
|
||||||
@@ -165,13 +146,12 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
ENV["REDIS_PASSWORD"] = "secret456"
|
ENV["REDIS_PASSWORD"] = "secret456"
|
||||||
|
|
||||||
expected = <<~ENV
|
expected_secrets_file = <<~ENV
|
||||||
REDIS_PASSWORD=secret456
|
REDIS_PASSWORD=secret456
|
||||||
REDIS_URL=redis://a/b
|
|
||||||
WEB_CONCURRENCY=4
|
|
||||||
ENV
|
ENV
|
||||||
|
|
||||||
assert_equal expected, @config_with_roles.role(:workers).env_file.to_s
|
assert_equal expected_secrets_file, @config_with_roles.role(:workers).env.secrets_io.string
|
||||||
|
assert_equal [ "--env-file", ".kamal/env/roles/app-workers.env", "--env", "REDIS_URL=\"redis://a/b\"", "--env", "WEB_CONCURRENCY=\"4\"" ], @config_with_roles.role(:workers).env_args
|
||||||
ensure
|
ensure
|
||||||
ENV["REDIS_PASSWORD"] = nil
|
ENV["REDIS_PASSWORD"] = nil
|
||||||
end
|
end
|
||||||
@@ -188,48 +168,24 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
@deploy_with_roles[:servers]["workers"]["env"] = {
|
@deploy_with_roles[:servers]["workers"]["env"] = {
|
||||||
"clear" => {
|
"clear" => {
|
||||||
"REDIS_URL" => "redis://c/d",
|
"REDIS_URL" => "redis://c/d"
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ENV["REDIS_PASSWORD"] = "secret456"
|
ENV["REDIS_PASSWORD"] = "secret456"
|
||||||
|
|
||||||
expected = <<~ENV
|
expected_secrets_file = <<~ENV
|
||||||
REDIS_PASSWORD=secret456
|
REDIS_PASSWORD=secret456
|
||||||
REDIS_URL=redis://c/d
|
|
||||||
ENV
|
ENV
|
||||||
|
|
||||||
assert_equal expected, @config_with_roles.role(:workers).env_file.to_s
|
assert_equal expected_secrets_file, @config_with_roles.role(:workers).env.secrets_io.string
|
||||||
|
assert_equal [ "--env-file", ".kamal/env/roles/app-workers.env", "--env", "REDIS_URL=\"redis://c/d\"" ], @config_with_roles.role(:workers).env_args
|
||||||
ensure
|
ensure
|
||||||
ENV["REDIS_PASSWORD"] = nil
|
ENV["REDIS_PASSWORD"] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
test "host_env_directory" do
|
test "env secrets_file" do
|
||||||
assert_equal ".kamal/env/roles", @config_with_roles.role(:workers).host_env_directory
|
assert_equal ".kamal/env/roles/app-workers.env", @config_with_roles.role(:workers).env.secrets_file
|
||||||
end
|
|
||||||
|
|
||||||
test "host_env_file_path" do
|
|
||||||
assert_equal ".kamal/env/roles/app-workers.env", @config_with_roles.role(:workers).host_env_file_path
|
|
||||||
end
|
|
||||||
|
|
||||||
test "uses cord" do
|
|
||||||
assert @config_with_roles.role(:web).uses_cord?
|
|
||||||
assert !@config_with_roles.role(:workers).uses_cord?
|
|
||||||
end
|
|
||||||
|
|
||||||
test "cord host file" do
|
|
||||||
assert_match %r{.kamal/cords/app-web-[0-9a-f]{32}/cord}, @config_with_roles.role(:web).cord_host_file
|
|
||||||
end
|
|
||||||
|
|
||||||
test "cord volume" do
|
|
||||||
assert_equal "/tmp/kamal-cord", @config_with_roles.role(:web).cord_volume.container_path
|
|
||||||
assert_match %r{.kamal/cords/app-web-[0-9a-f]{32}}, @config_with_roles.role(:web).cord_volume.host_path
|
|
||||||
assert_equal "--volume", @config_with_roles.role(:web).cord_volume.docker_args[0]
|
|
||||||
assert_match %r{\$\(pwd\)/.kamal/cords/app-web-[0-9a-f]{32}:/tmp/kamal-cord}, @config_with_roles.role(:web).cord_volume.docker_args[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
test "cord container file" do
|
|
||||||
assert_equal "/tmp/kamal-cord/cord", @config_with_roles.role(:web).cord_container_file
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "asset path and volume args" do
|
test "asset path and volume args" do
|
||||||
@@ -238,8 +194,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
assert_nil @config_with_roles.role(:workers).asset_volume_args
|
assert_nil @config_with_roles.role(:workers).asset_volume_args
|
||||||
assert_nil @config_with_roles.role(:web).asset_path
|
assert_nil @config_with_roles.role(:web).asset_path
|
||||||
assert_nil @config_with_roles.role(:workers).asset_path
|
assert_nil @config_with_roles.role(:workers).asset_path
|
||||||
assert !@config_with_roles.role(:web).assets?
|
assert_not @config_with_roles.role(:web).assets?
|
||||||
assert !@config_with_roles.role(:workers).assets?
|
assert_not @config_with_roles.role(:workers).assets?
|
||||||
|
|
||||||
config_with_assets = Kamal::Configuration.new(@deploy_with_roles.dup.tap { |c|
|
config_with_assets = Kamal::Configuration.new(@deploy_with_roles.dup.tap { |c|
|
||||||
c[:asset_path] = "foo"
|
c[:asset_path] = "foo"
|
||||||
@@ -249,7 +205,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "--volume", "$(pwd)/.kamal/assets/volumes/app-web-12345:foo" ], config_with_assets.role(:web).asset_volume_args
|
assert_equal [ "--volume", "$(pwd)/.kamal/assets/volumes/app-web-12345:foo" ], config_with_assets.role(:web).asset_volume_args
|
||||||
assert_nil config_with_assets.role(:workers).asset_volume_args
|
assert_nil config_with_assets.role(:workers).asset_volume_args
|
||||||
assert config_with_assets.role(:web).assets?
|
assert config_with_assets.role(:web).assets?
|
||||||
assert !config_with_assets.role(:workers).assets?
|
assert_not config_with_assets.role(:workers).assets?
|
||||||
|
|
||||||
config_with_assets = Kamal::Configuration.new(@deploy_with_roles.dup.tap { |c|
|
config_with_assets = Kamal::Configuration.new(@deploy_with_roles.dup.tap { |c|
|
||||||
c[:servers]["web"] = { "hosts" => [ "1.1.1.1", "1.1.1.2" ], "asset_path" => "bar" }
|
c[:servers]["web"] = { "hosts" => [ "1.1.1.1", "1.1.1.2" ], "asset_path" => "bar" }
|
||||||
@@ -259,7 +215,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "--volume", "$(pwd)/.kamal/assets/volumes/app-web-12345:bar" ], config_with_assets.role(:web).asset_volume_args
|
assert_equal [ "--volume", "$(pwd)/.kamal/assets/volumes/app-web-12345:bar" ], config_with_assets.role(:web).asset_volume_args
|
||||||
assert_nil config_with_assets.role(:workers).asset_volume_args
|
assert_nil config_with_assets.role(:workers).asset_volume_args
|
||||||
assert config_with_assets.role(:web).assets?
|
assert config_with_assets.role(:web).assets?
|
||||||
assert !config_with_assets.role(:workers).assets?
|
assert_not config_with_assets.role(:workers).assets?
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
ENV.delete("VERSION")
|
ENV.delete("VERSION")
|
||||||
|
|||||||
@@ -42,6 +42,16 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "service name valid" do
|
||||||
|
assert Kamal::Configuration.new(@deploy.tap { _1[:service] = "hey-app1_primary" }).valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "service name invalid" do
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
Kamal::Configuration.new @deploy.tap { _1[:service] = "app.com" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "roles" do
|
test "roles" do
|
||||||
assert_equal %w[ web ], @config.roles.collect(&:name)
|
assert_equal %w[ web ], @config.roles.collect(&:name)
|
||||||
assert_equal %w[ web workers ], @config_with_roles.roles.collect(&:name)
|
assert_equal %w[ web workers ], @config_with_roles.roles.collect(&:name)
|
||||||
@@ -63,13 +73,13 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
assert_equal "1.1.1.1", @config_with_roles.primary_host
|
assert_equal "1.1.1.1", @config_with_roles.primary_host
|
||||||
end
|
end
|
||||||
|
|
||||||
test "traefik hosts" do
|
test "proxy hosts" do
|
||||||
assert_equal [ "1.1.1.1", "1.1.1.2" ], @config_with_roles.traefik_hosts
|
assert_equal [ "1.1.1.1", "1.1.1.2" ], @config_with_roles.proxy_hosts
|
||||||
|
|
||||||
@deploy_with_roles[:servers]["workers"]["traefik"] = true
|
@deploy_with_roles[:servers]["workers"]["proxy"] = true
|
||||||
config = Kamal::Configuration.new(@deploy_with_roles)
|
config = Kamal::Configuration.new(@deploy_with_roles)
|
||||||
|
|
||||||
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], config.traefik_hosts
|
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], config.proxy_hosts
|
||||||
end
|
end
|
||||||
|
|
||||||
test "version no git repo" do
|
test "version no git repo" do
|
||||||
@@ -93,7 +103,17 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
Kamal::Git.expects(:revision).returns("git-version")
|
Kamal::Git.expects(:revision).returns("git-version")
|
||||||
Kamal::Git.expects(:uncommitted_changes).returns("M file\n")
|
Kamal::Git.expects(:uncommitted_changes).returns("M file\n")
|
||||||
assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, @config.version
|
assert_equal "git-version", @config.version
|
||||||
|
end
|
||||||
|
|
||||||
|
test "version from uncommitted context" do
|
||||||
|
ENV.delete("VERSION")
|
||||||
|
|
||||||
|
config = Kamal::Configuration.new(@deploy.tap { |c| c[:builder] = { "context" => "." } })
|
||||||
|
|
||||||
|
Kamal::Git.expects(:revision).returns("git-version")
|
||||||
|
Kamal::Git.expects(:uncommitted_changes).returns("M file\n")
|
||||||
|
assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, config.version
|
||||||
end
|
end
|
||||||
|
|
||||||
test "version from env" do
|
test "version from env" do
|
||||||
@@ -230,19 +250,19 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "to_h" do
|
test "to_h" do
|
||||||
expected_config = \
|
expected_config = \
|
||||||
{ :roles=>["web"],
|
{ roles: [ "web" ],
|
||||||
:hosts=>["1.1.1.1", "1.1.1.2"],
|
hosts: [ "1.1.1.1", "1.1.1.2" ],
|
||||||
:primary_host=>"1.1.1.1",
|
primary_host: "1.1.1.1",
|
||||||
:version=>"missing",
|
version: "missing",
|
||||||
:repository=>"dhh/app",
|
repository: "dhh/app",
|
||||||
:absolute_image=>"dhh/app:missing",
|
absolute_image: "dhh/app:missing",
|
||||||
:service_with_version=>"app-missing",
|
service_with_version: "app-missing",
|
||||||
:ssh_options=>{ :user=>"root", port: 22, log_level: :fatal, keepalive: true, keepalive_interval: 30 },
|
ssh_options: { user: "root", port: 22, log_level: :fatal, keepalive: true, keepalive_interval: 30 },
|
||||||
:sshkit=>{},
|
sshkit: {},
|
||||||
:volume_args=>["--volume", "/local/path:/container/path"],
|
volume_args: [ "--volume", "/local/path:/container/path" ],
|
||||||
:builder=>{},
|
builder: {},
|
||||||
:logging=>["--log-opt", "max-size=\"10m\""],
|
logging: [ "--log-opt", "max-size=\"10m\"" ],
|
||||||
:healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 }}
|
healthcheck: { "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "log_lines" => 50 } }
|
||||||
|
|
||||||
assert_equal expected_config, @config.to_h
|
assert_equal expected_config, @config.to_h
|
||||||
end
|
end
|
||||||
@@ -290,17 +310,17 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "primary role" do
|
test "primary role" do
|
||||||
assert_equal "web", @config.primary_role
|
assert_equal "web", @config.primary_role.name
|
||||||
|
|
||||||
config = Kamal::Configuration.new(@deploy_with_roles.deep_merge({
|
config = Kamal::Configuration.new(@deploy_with_roles.deep_merge({
|
||||||
servers: { "alternate_web" => { "hosts" => [ "1.1.1.4", "1.1.1.5" ] } },
|
servers: { "alternate_web" => { "hosts" => [ "1.1.1.4", "1.1.1.5" ] } },
|
||||||
primary_role: "alternate_web" }))
|
primary_role: "alternate_web" }))
|
||||||
|
|
||||||
|
|
||||||
assert_equal "alternate_web", config.primary_role
|
assert_equal "alternate_web", config.primary_role.name
|
||||||
assert_equal "1.1.1.4", config.primary_host
|
assert_equal "1.1.1.4", config.primary_host
|
||||||
assert config.role(:alternate_web).primary?
|
assert config.role(:alternate_web).primary?
|
||||||
assert config.role(:alternate_web).running_traefik?
|
assert config.role(:alternate_web).running_proxy?
|
||||||
end
|
end
|
||||||
|
|
||||||
test "primary role missing" do
|
test "primary role missing" do
|
||||||
@@ -309,4 +329,12 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
assert_match /bar isn't defined/, error.message
|
assert_match /bar isn't defined/, error.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "retain_containers" do
|
||||||
|
assert_equal 5, @config.retain_containers
|
||||||
|
config = Kamal::Configuration.new(@deploy_with_roles.merge(retain_containers: 2))
|
||||||
|
assert_equal 2, config.retain_containers
|
||||||
|
|
||||||
|
assert_raises(ArgumentError) { Kamal::Configuration.new(@deploy_with_roles.merge(retain_containers: 0)) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class EnvFileTest < ActiveSupport::TestCase
|
class EnvFileTest < ActiveSupport::TestCase
|
||||||
test "env file simple" do
|
test "to_s" do
|
||||||
env = {
|
env = {
|
||||||
"foo" => "bar",
|
"foo" => "bar",
|
||||||
"baz" => "haz"
|
"baz" => "haz"
|
||||||
@@ -11,80 +11,27 @@ class EnvFileTest < ActiveSupport::TestCase
|
|||||||
Kamal::EnvFile.new(env).to_s
|
Kamal::EnvFile.new(env).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
test "env file clear" do
|
test "to_s empty" do
|
||||||
env = {
|
|
||||||
"clear" => {
|
|
||||||
"foo" => "bar",
|
|
||||||
"baz" => "haz"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_equal "foo=bar\nbaz=haz\n", \
|
|
||||||
Kamal::EnvFile.new(env).to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
test "env file empty" do
|
|
||||||
assert_equal "\n", Kamal::EnvFile.new({}).to_s
|
assert_equal "\n", Kamal::EnvFile.new({}).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
test "env file secret" do
|
test "to_s escaped newline" do
|
||||||
ENV["PASSWORD"] = "hello"
|
|
||||||
env = {
|
env = {
|
||||||
"secret" => [ "PASSWORD" ]
|
"foo" => "hello\\nthere"
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_equal "PASSWORD=hello\n", \
|
assert_equal "foo=hello\\\\nthere\n", \
|
||||||
Kamal::EnvFile.new(env).to_s
|
Kamal::EnvFile.new(env).to_s
|
||||||
ensure
|
ensure
|
||||||
ENV.delete "PASSWORD"
|
ENV.delete "PASSWORD"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "env file secret escaped newline" do
|
test "to_s newline" do
|
||||||
ENV["PASSWORD"] = "hello\\nthere"
|
|
||||||
env = {
|
env = {
|
||||||
"secret" => [ "PASSWORD" ]
|
"foo" => "hello\nthere"
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_equal "PASSWORD=hello\\\\nthere\n", \
|
assert_equal "foo=hello\\nthere\n", \
|
||||||
Kamal::EnvFile.new(env).to_s
|
|
||||||
ensure
|
|
||||||
ENV.delete "PASSWORD"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "env file secret newline" do
|
|
||||||
ENV["PASSWORD"] = "hello\nthere"
|
|
||||||
env = {
|
|
||||||
"secret" => [ "PASSWORD" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_equal "PASSWORD=hello\\nthere\n", \
|
|
||||||
Kamal::EnvFile.new(env).to_s
|
|
||||||
ensure
|
|
||||||
ENV.delete "PASSWORD"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "env file missing secret" do
|
|
||||||
env = {
|
|
||||||
"secret" => [ "PASSWORD" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_raises(KeyError) { Kamal::EnvFile.new(env).to_s }
|
|
||||||
|
|
||||||
ensure
|
|
||||||
ENV.delete "PASSWORD"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "env file secret and clear" do
|
|
||||||
ENV["PASSWORD"] = "hello"
|
|
||||||
env = {
|
|
||||||
"secret" => [ "PASSWORD" ],
|
|
||||||
"clear" => {
|
|
||||||
"foo" => "bar",
|
|
||||||
"baz" => "haz"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_equal "PASSWORD=hello\nfoo=bar\nbaz=haz\n", \
|
|
||||||
Kamal::EnvFile.new(env).to_s
|
Kamal::EnvFile.new(env).to_s
|
||||||
ensure
|
ensure
|
||||||
ENV.delete "PASSWORD"
|
ENV.delete "PASSWORD"
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ service: app
|
|||||||
image: dhh/app
|
image: dhh/app
|
||||||
servers:
|
servers:
|
||||||
web_chicago:
|
web_chicago:
|
||||||
traefik: enabled
|
proxy: enabled
|
||||||
hosts:
|
hosts:
|
||||||
- 1.1.1.1
|
- 1.1.1.1
|
||||||
- 1.1.1.2
|
- 1.1.1.2
|
||||||
web_tokyo:
|
web_tokyo:
|
||||||
traefik: enabled
|
proxy: enabled
|
||||||
hosts:
|
hosts:
|
||||||
- 1.1.1.3
|
- 1.1.1.3
|
||||||
- 1.1.1.4
|
- 1.1.1.4
|
||||||
|
|||||||
2
test/fixtures/deploy_with_aliases.yml
vendored
2
test/fixtures/deploy_with_aliases.yml
vendored
@@ -10,7 +10,7 @@ tokyo_hosts: &tokyo_hosts
|
|||||||
web_common: &web_common
|
web_common: &web_common
|
||||||
env:
|
env:
|
||||||
ROLE: "web"
|
ROLE: "web"
|
||||||
traefik: true
|
proxy: true
|
||||||
|
|
||||||
# actual config
|
# actual config
|
||||||
service: app
|
service: app
|
||||||
|
|||||||
17
test/fixtures/deploy_with_low_percentage_boot_strategy.yml
vendored
Normal file
17
test/fixtures/deploy_with_low_percentage_boot_strategy.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
service: app
|
||||||
|
image: dhh/app
|
||||||
|
servers:
|
||||||
|
web:
|
||||||
|
- "1.1.1.1"
|
||||||
|
- "1.1.1.2"
|
||||||
|
workers:
|
||||||
|
- "1.1.1.3"
|
||||||
|
- "1.1.1.4"
|
||||||
|
|
||||||
|
registry:
|
||||||
|
username: user
|
||||||
|
password: pw
|
||||||
|
|
||||||
|
boot:
|
||||||
|
limit: 1%
|
||||||
|
wait: 2
|
||||||
@@ -13,5 +13,5 @@ registry:
|
|||||||
password: pw
|
password: pw
|
||||||
|
|
||||||
boot:
|
boot:
|
||||||
limit: 25%
|
limit: 1%
|
||||||
wait: 2
|
wait: 2
|
||||||
|
|||||||
2
test/fixtures/deploy_workers_only.yml
vendored
2
test/fixtures/deploy_workers_only.yml
vendored
@@ -2,7 +2,7 @@ service: app
|
|||||||
image: dhh/app
|
image: dhh/app
|
||||||
servers:
|
servers:
|
||||||
workers:
|
workers:
|
||||||
traefik: false
|
proxy: false
|
||||||
hosts:
|
hosts:
|
||||||
- 1.1.1.1
|
- 1.1.1.1
|
||||||
- 1.1.1.2
|
- 1.1.1.2
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require_relative "integration_test"
|
require_relative "integration_test"
|
||||||
|
|
||||||
class AccessoryTest < IntegrationTest
|
class IntegrationAccessoryTest < IntegrationTest
|
||||||
test "boot, stop, start, restart, logs, remove" do
|
test "boot, stop, start, restart, logs, remove" do
|
||||||
kamal :envify
|
kamal :envify
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ class AccessoryTest < IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assert_accessory_not_running(name)
|
def assert_accessory_not_running(name)
|
||||||
refute_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name)
|
assert_no_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def accessory_details(name)
|
def accessory_details(name)
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
require_relative "integration_test"
|
require_relative "integration_test"
|
||||||
|
|
||||||
class AppTest < IntegrationTest
|
class IntegrationAppTest < IntegrationTest
|
||||||
test "stop, start, boot, logs, images, containers, exec, remove" do
|
test "stop, start, boot, logs, images, containers, exec, remove" do
|
||||||
kamal :envify
|
kamal :envify
|
||||||
|
|
||||||
|
kamal :setup
|
||||||
|
|
||||||
kamal :deploy
|
kamal :deploy
|
||||||
|
|
||||||
assert_app_is_up
|
assert_app_is_up
|
||||||
|
|
||||||
kamal :app, :stop
|
kamal :app, :stop
|
||||||
|
|
||||||
assert_app_is_down
|
assert_app_is_down response_code: "502"
|
||||||
|
|
||||||
kamal :app, :start
|
kamal :app, :start
|
||||||
|
|
||||||
@@ -50,6 +52,6 @@ class AppTest < IntegrationTest
|
|||||||
|
|
||||||
kamal :app, :remove
|
kamal :app, :remove
|
||||||
|
|
||||||
assert_app_is_down
|
assert_app_is_down response_code: "502"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -50,8 +50,19 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- shared:/shared
|
- shared:/shared
|
||||||
|
|
||||||
|
vm3:
|
||||||
|
privileged: true
|
||||||
|
build:
|
||||||
|
context: docker/vm
|
||||||
|
volumes:
|
||||||
|
- shared:/shared
|
||||||
|
|
||||||
load_balancer:
|
load_balancer:
|
||||||
build:
|
build:
|
||||||
context: docker/load_balancer
|
context: docker/load_balancer
|
||||||
ports:
|
ports:
|
||||||
- "12345:80"
|
- "12345:80"
|
||||||
|
depends_on:
|
||||||
|
- vm1
|
||||||
|
- vm2
|
||||||
|
- vm3
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
FROM ruby:3.2
|
FROM ruby:3.2
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /
|
||||||
|
|
||||||
ENV VERBOSE=true
|
ENV VERBOSE=true
|
||||||
|
|
||||||
@@ -17,7 +17,8 @@ RUN echo \
|
|||||||
RUN apt-get update --fix-missing && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
RUN apt-get update --fix-missing && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||||
|
|
||||||
COPY *.sh .
|
COPY *.sh .
|
||||||
COPY app/ .
|
COPY app/ app/
|
||||||
|
COPY app_with_roles/ app_with_roles/
|
||||||
|
|
||||||
RUN rm -rf /root/.ssh
|
RUN rm -rf /root/.ssh
|
||||||
RUN ln -s /shared/ssh /root/.ssh
|
RUN ln -s /shared/ssh /root/.ssh
|
||||||
@@ -25,7 +26,8 @@ RUN mkdir -p /etc/docker/certs.d/registry:4443 && ln -s /shared/certs/domain.crt
|
|||||||
|
|
||||||
RUN git config --global user.email "deployer@example.com"
|
RUN git config --global user.email "deployer@example.com"
|
||||||
RUN git config --global user.name "Deployer"
|
RUN git config --global user.name "Deployer"
|
||||||
RUN git init && echo ".env" >> .gitignore && git add . && git commit -am "Initial version"
|
RUN cd app && git init && echo ".env" >> .gitignore && git add . && git commit -am "Initial version"
|
||||||
|
RUN cd app_with_roles && git init && echo ".env" >> .gitignore && git add . && git commit -am "Initial version"
|
||||||
|
|
||||||
HEALTHCHECK --interval=1s CMD pgrep sleep
|
HEALTHCHECK --interval=1s CMD pgrep sleep
|
||||||
|
|
||||||
|
|||||||
3
test/integration/docker/deployer/app/.kamal/hooks/docker-setup
Executable file
3
test/integration/docker/deployer/app/.kamal/hooks/docker-setup
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Docker set up!"
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/docker-setup
|
||||||
3
test/integration/docker/deployer/app/.kamal/hooks/post-proxy-reboot
Executable file
3
test/integration/docker/deployer/app/.kamal/hooks/post-proxy-reboot
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Rebooted proxy on ${KAMAL_HOSTS}"
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/post-proxy-reboot
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
echo "Rebooted Traefik on ${KAMAL_HOSTS}"
|
|
||||||
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/post-traefik-reboot
|
|
||||||
3
test/integration/docker/deployer/app/.kamal/hooks/pre-proxy-reboot
Executable file
3
test/integration/docker/deployer/app/.kamal/hooks/pre-proxy-reboot
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Rebooting proxy on ${KAMAL_HOSTS}..."
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-proxy-reboot
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
echo "Rebooting Traefik on ${KAMAL_HOSTS}..."
|
|
||||||
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-traefik-reboot
|
|
||||||
@@ -6,4 +6,5 @@ ARG COMMIT_SHA
|
|||||||
RUN echo $COMMIT_SHA > /usr/share/nginx/html/version
|
RUN echo $COMMIT_SHA > /usr/share/nginx/html/version
|
||||||
RUN mkdir -p /usr/share/nginx/html/versions && echo "version" > /usr/share/nginx/html/versions/$COMMIT_SHA
|
RUN mkdir -p /usr/share/nginx/html/versions && echo "version" > /usr/share/nginx/html/versions/$COMMIT_SHA
|
||||||
RUN mkdir -p /usr/share/nginx/html/versions && echo "hidden" > /usr/share/nginx/html/versions/.hidden
|
RUN mkdir -p /usr/share/nginx/html/versions && echo "hidden" > /usr/share/nginx/html/versions/.hidden
|
||||||
|
RUN echo "Up!" > /usr/share/nginx/html/up
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ image: app
|
|||||||
servers:
|
servers:
|
||||||
- vm1
|
- vm1
|
||||||
- vm2
|
- vm2
|
||||||
|
port: 80
|
||||||
env:
|
env:
|
||||||
clear:
|
clear:
|
||||||
CLEAR_TOKEN: '4321'
|
CLEAR_TOKEN: 4321
|
||||||
|
HOST_TOKEN: "${HOST_TOKEN}"
|
||||||
secret:
|
secret:
|
||||||
- SECRET_TOKEN
|
- SECRET_TOKEN
|
||||||
asset_path: /usr/share/nginx/html/versions
|
asset_path: /usr/share/nginx/html/versions
|
||||||
@@ -20,15 +22,13 @@ builder:
|
|||||||
COMMIT_SHA: <%= `git rev-parse HEAD` %>
|
COMMIT_SHA: <%= `git rev-parse HEAD` %>
|
||||||
healthcheck:
|
healthcheck:
|
||||||
cmd: wget -qO- http://localhost > /dev/null || exit 1
|
cmd: wget -qO- http://localhost > /dev/null || exit 1
|
||||||
traefik:
|
proxy:
|
||||||
args:
|
image: registry:4443/dmcbreen/mproxy:latest
|
||||||
accesslog: true
|
|
||||||
accesslog.format: json
|
|
||||||
image: registry:4443/traefik:v2.9
|
|
||||||
accessories:
|
accessories:
|
||||||
busybox:
|
busybox:
|
||||||
|
service: custom-busybox
|
||||||
image: registry:4443/busybox:1.36.0
|
image: registry:4443/busybox:1.36.0
|
||||||
cmd: sh -c 'echo "Starting busybox..."; trap exit term; while true; do sleep 1; done'
|
cmd: sh -c 'echo "Starting busybox..."; trap exit term; while true; do sleep 1; done'
|
||||||
roles:
|
roles:
|
||||||
- web
|
- web
|
||||||
stop_wait_time: 1
|
stop_wait_time: 5
|
||||||
|
|||||||
1
test/integration/docker/deployer/app_with_roles/.env.erb
Normal file
1
test/integration/docker/deployer/app_with_roles/.env.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
SECRET_TOKEN=1234
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Docker set up!"
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/docker-setup
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user