Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb86123db4 | ||
|
|
bc6963e6bf | ||
|
|
f4f2b5cb17 | ||
|
|
817336df49 | ||
|
|
4c399a74bb | ||
|
|
e12436a1db | ||
|
|
b244e919bf | ||
|
|
7ad416f029 | ||
|
|
371f98d67f | ||
|
|
b879412a6f | ||
|
|
e678775a18 | ||
|
|
689b81014b | ||
|
|
01a4eecf98 | ||
|
|
6f7422af44 | ||
|
|
1fccaf60b2 | ||
|
|
9b02a7668d | ||
|
|
f81ba12aa5 | ||
|
|
25e8b91569 | ||
|
|
21c6a1f1ba |
2
Gemfile
2
Gemfile
@@ -6,3 +6,5 @@ gemspec
|
||||
gem "debug"
|
||||
gem "mocha"
|
||||
gem "railties"
|
||||
gem "ed25519"
|
||||
gem "bcrypt_pbkdf"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
mrsk (0.8.0)
|
||||
mrsk (0.8.2)
|
||||
activesupport (>= 7.0)
|
||||
dotenv (~> 2.8)
|
||||
sshkit (~> 1.21)
|
||||
@@ -29,6 +29,7 @@ GEM
|
||||
i18n (>= 1.6, < 2)
|
||||
minitest (>= 5.1)
|
||||
tzinfo (~> 2.0)
|
||||
bcrypt_pbkdf (1.1.0)
|
||||
builder (3.2.4)
|
||||
concurrent-ruby (1.1.10)
|
||||
crass (1.0.6)
|
||||
@@ -36,6 +37,7 @@ GEM
|
||||
irb (>= 1.5.0)
|
||||
reline (>= 0.3.1)
|
||||
dotenv (2.8.1)
|
||||
ed25519 (1.3.0)
|
||||
erubi (1.12.0)
|
||||
i18n (1.12.0)
|
||||
concurrent-ruby (~> 1.0)
|
||||
@@ -96,7 +98,9 @@ PLATFORMS
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
bcrypt_pbkdf
|
||||
debug
|
||||
ed25519
|
||||
mocha
|
||||
mrsk!
|
||||
railties
|
||||
|
||||
@@ -498,7 +498,7 @@ If you wish to remove the entire application, including Traefik, containers, ima
|
||||
|
||||
## Stage of development
|
||||
|
||||
This is alpha software. Lots of stuff is missing. Lots of stuff will keep moving around for a while.
|
||||
This is beta software. Commands may still move around. But we're live in production at [37signals](https://37signals.com).
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
execute *accessory.run
|
||||
end
|
||||
|
||||
audit_broadcast "Booted accessory #{name}"
|
||||
audit_broadcast "Booted accessory #{name}" unless options[:skip_broadcast]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,18 +5,27 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
||||
using_version(options[:version] || most_recent_version_available) do |version|
|
||||
say "Start container with version #{version} (or reboot if already running)...", :magenta
|
||||
|
||||
cli = self
|
||||
|
||||
MRSK.config.roles.each do |role|
|
||||
on(role.hosts) do |host|
|
||||
execute *MRSK.auditor.record("Booted app version #{version}"), verbosity: :debug
|
||||
|
||||
begin
|
||||
execute *MRSK.app.stop, raise_on_non_zero_exit: false
|
||||
old_version = capture_with_info(*MRSK.app.current_running_version).strip
|
||||
execute *MRSK.app.run(role: role.name)
|
||||
|
||||
cli.say "Waiting #{MRSK.config.readiness_delay}s for app to boot...", :magenta
|
||||
sleep MRSK.config.readiness_delay
|
||||
|
||||
execute *MRSK.app.stop(version: old_version), raise_on_non_zero_exit: false if old_version.present?
|
||||
|
||||
rescue SSHKit::Command::Failed => e
|
||||
if e.message =~ /already in use/
|
||||
error "Rebooting container with same version already deployed on #{host}"
|
||||
error "Rebooting container with same version #{version} already deployed on #{host} (may cause gap in zero-downtime promise!)"
|
||||
execute *MRSK.auditor.record("Rebooted app version #{version}"), verbosity: :debug
|
||||
|
||||
execute *MRSK.app.stop(version: version)
|
||||
execute *MRSK.app.remove_container(version: version)
|
||||
execute *MRSK.app.run(role: role.name)
|
||||
else
|
||||
|
||||
@@ -20,6 +20,8 @@ module Mrsk::Cli
|
||||
class_option :config_file, aliases: "-c", default: "config/deploy.yml", desc: "Path to config file"
|
||||
class_option :destination, aliases: "-d", desc: "Specify destination to be used for config file (staging -> deploy.staging.yml)"
|
||||
|
||||
class_option :skip_broadcast, aliases: "-B", type: :boolean, default: false, desc: "Skip audit broadcasts"
|
||||
|
||||
def initialize(*)
|
||||
super
|
||||
load_envs
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
||||
MAX_ATTEMPTS = 5
|
||||
MAX_ATTEMPTS = 7
|
||||
|
||||
class HealthcheckError < StandardError; end
|
||||
|
||||
default_command :perform
|
||||
|
||||
@@ -18,7 +20,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
||||
if status == "200"
|
||||
info "#{target} succeeded with 200 OK!"
|
||||
else
|
||||
raise "#{target} failed with status #{status}"
|
||||
raise HealthcheckError, "#{target} failed with status #{status}"
|
||||
end
|
||||
rescue SSHKit::Command::Failed
|
||||
if attempt <= MAX_ATTEMPTS
|
||||
@@ -31,7 +33,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
||||
raise
|
||||
end
|
||||
end
|
||||
rescue SSHKit::Command::Failed => e
|
||||
rescue SSHKit::Command::Failed, HealthcheckError => e
|
||||
error capture_with_info(*MRSK.healthcheck.logs)
|
||||
|
||||
if e.message =~ /curl/
|
||||
|
||||
@@ -32,7 +32,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
invoke "mrsk:cli:prune:all"
|
||||
end
|
||||
|
||||
audit_broadcast "Deployed app in #{runtime.to_i} seconds"
|
||||
audit_broadcast "Deployed app in #{runtime.to_i} seconds" unless options[:skip_broadcast]
|
||||
end
|
||||
|
||||
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
||||
@@ -47,7 +47,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
invoke "mrsk:cli:app:boot"
|
||||
end
|
||||
|
||||
audit_broadcast "Redeployed app in #{runtime.to_i} seconds"
|
||||
audit_broadcast "Redeployed app in #{runtime.to_i} seconds" unless options[:skip_broadcast]
|
||||
end
|
||||
|
||||
desc "rollback [VERSION]", "Rollback app to VERSION"
|
||||
@@ -55,14 +55,22 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
MRSK.version = version
|
||||
|
||||
if container_name_available?(MRSK.config.service_with_version)
|
||||
say "Stop current version, then start version #{version}...", :magenta
|
||||
say "Start version #{version}, then stop the old version...", :magenta
|
||||
|
||||
cli = self
|
||||
|
||||
on(MRSK.hosts) do |host|
|
||||
execute *MRSK.app.stop, raise_on_non_zero_exit: false
|
||||
old_version = capture_with_info(*MRSK.app.current_running_version).strip.presence
|
||||
|
||||
execute *MRSK.app.start
|
||||
|
||||
cli.say "Waiting #{MRSK.config.readiness_delay}s for app to start...", :magenta
|
||||
sleep MRSK.config.readiness_delay
|
||||
|
||||
execute *MRSK.app.stop(version: old_version), raise_on_non_zero_exit: false
|
||||
end
|
||||
|
||||
audit_broadcast "Rolled back app to version #{version}"
|
||||
audit_broadcast "Rolled back app to version #{version}" unless options[:skip_broadcast]
|
||||
else
|
||||
say "The app version '#{version}' is not available as a container (use 'mrsk app containers' for available versions)", :red
|
||||
end
|
||||
|
||||
@@ -18,8 +18,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
docker :start, service_with_version
|
||||
end
|
||||
|
||||
def stop
|
||||
pipe current_container_id, xargs(docker(:stop))
|
||||
def stop(version: nil)
|
||||
pipe \
|
||||
version ? container_id_for_version(version) : current_container_id,
|
||||
xargs(docker(:stop))
|
||||
end
|
||||
|
||||
def info
|
||||
@@ -132,6 +134,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
end
|
||||
end
|
||||
|
||||
def container_id_for_version(version)
|
||||
container_id_for(container_name: service_with_version(version))
|
||||
end
|
||||
|
||||
def service_filter
|
||||
[ "--filter", "label=service=#{config.service}" ]
|
||||
end
|
||||
|
||||
@@ -136,6 +136,9 @@ class Mrsk::Configuration
|
||||
{ "path" => "/up", "port" => 3000 }.merge(raw_config.healthcheck || {})
|
||||
end
|
||||
|
||||
def readiness_delay
|
||||
raw_config.readiness_delay || 7
|
||||
end
|
||||
|
||||
def valid?
|
||||
ensure_required_keys_present && ensure_env_available
|
||||
|
||||
@@ -58,10 +58,10 @@ class Mrsk::Configuration::Role
|
||||
def traefik_labels
|
||||
if running_traefik?
|
||||
{
|
||||
"traefik.http.routers.#{config.service}.rule" => "'PathPrefix(`/`)'",
|
||||
"traefik.http.routers.#{config.service}.rule" => "PathPrefix(`/`)",
|
||||
"traefik.http.services.#{config.service}.loadbalancer.healthcheck.path" => config.healthcheck["path"],
|
||||
"traefik.http.services.#{config.service}.loadbalancer.healthcheck.interval" => "1s",
|
||||
"traefik.http.middlewares.#{config.service}.retry.attempts" => "3",
|
||||
"traefik.http.middlewares.#{config.service}.retry.attempts" => "5",
|
||||
"traefik.http.middlewares.#{config.service}.retry.initialinterval" => "500ms"
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
module Mrsk::Utils
|
||||
extend self
|
||||
|
||||
# Return a list of shell arguments using the same named argument against the passed attributes (hash or array).
|
||||
# Return a list of escaped shell arguments using the same named argument against the passed attributes (hash or array).
|
||||
def argumentize(argument, attributes, redacted: false)
|
||||
Array(attributes).flat_map do |k, v|
|
||||
if v.present?
|
||||
[ argument, redacted ? redact("#{k}=#{v}") : "#{k}=#{v}" ]
|
||||
Array(attributes).flat_map do |key, value|
|
||||
if value.present?
|
||||
escaped_pair = [ key, value.to_s.dump.gsub(/`/, '\\\\`') ].join("=")
|
||||
[ argument, redacted ? redact(escaped_pair) : escaped_pair ]
|
||||
else
|
||||
[ argument, k ]
|
||||
[ argument, key ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Mrsk
|
||||
VERSION = "0.8.0"
|
||||
VERSION = "0.8.2"
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ class CliAccessoryTest < CliTestCase
|
||||
end
|
||||
|
||||
test "boot" do
|
||||
assert_match "Running docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=10m --publish 3306:3306 -e [REDACTED] -e 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", run_command("boot", "mysql")
|
||||
assert_match "Running docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=10m --publish 3306:3306 -e [REDACTED] -e 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", run_command("boot", "mysql")
|
||||
end
|
||||
|
||||
test "exec" do
|
||||
|
||||
@@ -2,7 +2,16 @@ require_relative "cli_test_case"
|
||||
|
||||
class CliAppTest < CliTestCase
|
||||
test "boot" do
|
||||
assert_match /Running docker run --detach --restart unless-stopped/, run_command("boot")
|
||||
# Stub current version fetch
|
||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
||||
.returns("999") # new version
|
||||
.then
|
||||
.returns("123") # old version
|
||||
|
||||
run_command("boot").tap do |output|
|
||||
assert_match /docker run --detach --restart unless-stopped/, output
|
||||
assert_match /docker container ls --all --filter name=app-123 --quiet | xargs docker stop/, output
|
||||
end
|
||||
end
|
||||
|
||||
test "boot will reboot if same version is already running" do
|
||||
@@ -11,12 +20,17 @@ class CliAppTest < CliTestCase
|
||||
# Prevent expected failures from outputting to terminal
|
||||
Thread.report_on_exception = false
|
||||
|
||||
MRSK.app.stubs(:run).raises(SSHKit::Command::Failed.new("already in use")).then.returns([ :docker, :run ])
|
||||
MRSK.app.stubs(:run)
|
||||
.raises(SSHKit::Command::Failed.new("already in use"))
|
||||
.then
|
||||
.raises(SSHKit::Command::Failed.new("already in use"))
|
||||
.then
|
||||
.returns([ :docker, :run ])
|
||||
|
||||
run_command("boot").tap do |output|
|
||||
assert_match /Rebooting container with same version already deployed/, output # Can't start what's already running
|
||||
assert_match /docker ps --quiet --filter label=service=app \| xargs docker stop/, output # Stop what's running
|
||||
assert_match /docker container ls --all --filter name=app-999 --quiet \| xargs docker container rm/, output # Remove old container
|
||||
assert_match /Rebooting container with same version 999 already deployed/, output # Can't start what's already running
|
||||
assert_match /docker container ls --all --filter name=app-999 --quiet | xargs docker container rm/, output # Stop old running
|
||||
assert_match /docker container ls --all --filter name=app-999 --quiet | xargs docker container rm/, output # Remove old container
|
||||
assert_match /docker run/, output # Start new container
|
||||
end
|
||||
ensure
|
||||
|
||||
@@ -19,7 +19,7 @@ class CliMainTest < CliTestCase
|
||||
Mrsk::Cli::Main.any_instance.stubs(:container_name_available?).returns(true)
|
||||
|
||||
run_command("rollback", "123").tap do |output|
|
||||
assert_match /Stop current version, then start version 123/, output
|
||||
assert_match /Start version 123, then stop the old version/, output
|
||||
assert_match /docker ps -q --filter label=service=app | xargs docker stop/, output
|
||||
assert_match /docker start app-123/, output
|
||||
end
|
||||
|
||||
@@ -49,11 +49,11 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
||||
|
||||
test "run" do
|
||||
assert_equal \
|
||||
"docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=10m --publish 3306:3306 -e MYSQL_ROOT_PASSWORD=secret123 -e MYSQL_ROOT_HOST=% --label service=app-mysql mysql:8.0",
|
||||
"docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=10m --publish 3306:3306 -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" --label service=\"app-mysql\" mysql:8.0",
|
||||
@mysql.run.join(" ")
|
||||
|
||||
assert_equal \
|
||||
"docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=10m --publish 6379:6379 -e SOMETHING=else --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 -e SOMETHING=\"else\" --volume /var/lib/redis:/data --label service=\"app-redis\" --label cache=\"true\" redis:latest",
|
||||
@redis.run.join(" ")
|
||||
end
|
||||
|
||||
@@ -78,7 +78,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
||||
|
||||
test "execute in new container" do
|
||||
assert_equal \
|
||||
"docker run --rm -e MYSQL_ROOT_PASSWORD=secret123 -e MYSQL_ROOT_HOST=% mysql:8.0 mysql -u root",
|
||||
"docker run --rm -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" mysql:8.0 mysql -u root",
|
||||
@mysql.execute_in_new_container("mysql", "-u", "root").join(" ")
|
||||
end
|
||||
|
||||
@@ -90,7 +90,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
||||
|
||||
test "execute in new container over ssh" do
|
||||
@mysql.stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
||||
assert_match %r|docker run -it --rm -e MYSQL_ROOT_PASSWORD=secret123 -e MYSQL_ROOT_HOST=% mysql:8.0 mysql -u root|,
|
||||
assert_match %r|docker run -it --rm -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" mysql:8.0 mysql -u root|,
|
||||
@mysql.execute_in_new_container_over_ssh("mysql", "-u", "root")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
||||
|
||||
test "run" do
|
||||
assert_equal \
|
||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=456 --label service=app --label role=web --label traefik.http.routers.app.rule='PathPrefix(`/`)' --label traefik.http.services.app.loadbalancer.healthcheck.path=/up --label traefik.http.services.app.loadbalancer.healthcheck.interval=1s --label traefik.http.middlewares.app.retry.attempts=3 --label traefik.http.middlewares.app.retry.initialinterval=500ms dhh/app:999",
|
||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"5\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
||||
@app.run.join(" ")
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
||||
@config[:volumes] = ["/local/path:/container/path" ]
|
||||
|
||||
assert_equal \
|
||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=456 --volume /local/path:/container/path --label service=app --label role=web --label traefik.http.routers.app.rule='PathPrefix(`/`)' --label traefik.http.services.app.loadbalancer.healthcheck.path=/up --label traefik.http.services.app.loadbalancer.healthcheck.interval=1s --label traefik.http.middlewares.app.retry.attempts=3 --label traefik.http.middlewares.app.retry.initialinterval=500ms dhh/app:999",
|
||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --volume /local/path:/container/path --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"5\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
||||
@app.run.join(" ")
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
||||
@config[:healthcheck] = { "path" => "/healthz" }
|
||||
|
||||
assert_equal \
|
||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=456 --label service=app --label role=web --label traefik.http.routers.app.rule='PathPrefix(`/`)' --label traefik.http.services.app.loadbalancer.healthcheck.path=/healthz --label traefik.http.services.app.loadbalancer.healthcheck.interval=1s --label traefik.http.middlewares.app.retry.attempts=3 --label traefik.http.middlewares.app.retry.initialinterval=500ms dhh/app:999",
|
||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/healthz\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"5\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
||||
@app.run.join(" ")
|
||||
end
|
||||
|
||||
@@ -94,7 +94,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
||||
|
||||
test "execute in new container" do
|
||||
assert_equal \
|
||||
"docker run --rm -e RAILS_MASTER_KEY=456 dhh/app:999 bin/rails db:setup",
|
||||
"docker run --rm -e RAILS_MASTER_KEY=\"456\" dhh/app:999 bin/rails db:setup",
|
||||
@app.execute_in_new_container("bin/rails", "db:setup").join(" ")
|
||||
end
|
||||
|
||||
@@ -106,7 +106,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
||||
|
||||
test "execute in new container over ssh" do
|
||||
@app.stub(:run_over_ssh, ->(cmd, host:) { cmd.join(" ") }) do
|
||||
assert_match %r|docker run -it --rm -e RAILS_MASTER_KEY=456 dhh/app:999 bin/rails c|,
|
||||
assert_match %r|docker run -it --rm -e RAILS_MASTER_KEY=\"456\" dhh/app:999 bin/rails c|,
|
||||
@app.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
||||
builder = new_builder_command
|
||||
assert_equal "multiarch", builder.name
|
||||
assert_equal \
|
||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=app .",
|
||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" .",
|
||||
builder.push.join(" ")
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
||||
builder = new_builder_command(builder: { "multiarch" => false })
|
||||
assert_equal "native", builder.name
|
||||
assert_equal \
|
||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=app . && docker push dhh/app:123",
|
||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" . && docker push dhh/app:123",
|
||||
builder.push.join(" ")
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
||||
builder = new_builder_command(builder: { "local" => { }, "remote" => { } })
|
||||
assert_equal "multiarch/remote", builder.name
|
||||
assert_equal \
|
||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --label service=app .",
|
||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --label service=\"app\" .",
|
||||
builder.push.join(" ")
|
||||
end
|
||||
|
||||
@@ -33,42 +33,42 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
||||
builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" } })
|
||||
assert_equal "native/remote", builder.name
|
||||
assert_equal \
|
||||
"docker buildx build --push --platform linux/amd64 --builder mrsk-app-native-remote -t dhh/app:123 -t dhh/app:latest --label service=app .",
|
||||
"docker buildx build --push --platform linux/amd64 --builder mrsk-app-native-remote -t dhh/app:123 -t dhh/app:latest --label service=\"app\" .",
|
||||
builder.push.join(" ")
|
||||
end
|
||||
|
||||
test "build args" do
|
||||
builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } })
|
||||
assert_equal \
|
||||
"-t dhh/app:123 -t dhh/app:latest --label service=app --build-arg a=1 --build-arg b=2",
|
||||
"-t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\"",
|
||||
builder.target.build_options.join(" ")
|
||||
end
|
||||
|
||||
test "build secrets" do
|
||||
builder = new_builder_command(builder: { "secrets" => ["token_a", "token_b"] })
|
||||
assert_equal \
|
||||
"-t dhh/app:123 -t dhh/app:latest --label service=app --secret id=token_a --secret id=token_b",
|
||||
"-t dhh/app:123 -t dhh/app:latest --label service=\"app\" --secret id=\"token_a\" --secret id=\"token_b\"",
|
||||
builder.target.build_options.join(" ")
|
||||
end
|
||||
|
||||
test "native push with build args" do
|
||||
builder = new_builder_command(builder: { "multiarch" => false, "args" => { "a" => 1, "b" => 2 } })
|
||||
assert_equal \
|
||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=app --build-arg a=1 --build-arg b=2 . && docker push dhh/app:123",
|
||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" . && docker push dhh/app:123",
|
||||
builder.push.join(" ")
|
||||
end
|
||||
|
||||
test "multiarch push with build args" do
|
||||
builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } })
|
||||
assert_equal \
|
||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=app --build-arg a=1 --build-arg b=2 .",
|
||||
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" .",
|
||||
builder.push.join(" ")
|
||||
end
|
||||
|
||||
test "native push with with build secrets" do
|
||||
builder = new_builder_command(builder: { "multiarch" => false, "secrets" => [ "a", "b" ] })
|
||||
assert_equal \
|
||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=app --secret id=a --secret id=b . && docker push dhh/app:123",
|
||||
"docker build -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --secret id=\"a\" --secret id=\"b\" . && docker push dhh/app:123",
|
||||
builder.push.join(" ")
|
||||
end
|
||||
|
||||
|
||||
@@ -72,20 +72,20 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "label args" do
|
||||
assert_equal ["--label", "service=app-mysql"], @config.accessory(:mysql).label_args
|
||||
assert_equal ["--label", "service=app-redis", "--label", "cache=true"], @config.accessory(:redis).label_args
|
||||
assert_equal ["--label", "service=\"app-mysql\""], @config.accessory(:mysql).label_args
|
||||
assert_equal ["--label", "service=\"app-redis\"", "--label", "cache=\"true\""], @config.accessory(:redis).label_args
|
||||
end
|
||||
|
||||
test "env args with secret" do
|
||||
ENV["MYSQL_ROOT_PASSWORD"] = "secret123"
|
||||
assert_equal ["-e", "MYSQL_ROOT_PASSWORD=secret123", "-e", "MYSQL_ROOT_HOST=%"], @config.accessory(:mysql).env_args
|
||||
assert_equal ["-e", "MYSQL_ROOT_PASSWORD=\"secret123\"", "-e", "MYSQL_ROOT_HOST=\"%\""], @config.accessory(:mysql).env_args
|
||||
assert @config.accessory(:mysql).env_args[1].is_a?(SSHKit::Redaction)
|
||||
ensure
|
||||
ENV["MYSQL_ROOT_PASSWORD"] = nil
|
||||
end
|
||||
|
||||
test "env args without secret" do
|
||||
assert_equal ["-e", "SOMETHING=else"], @config.accessory(:redis).env_args
|
||||
assert_equal ["-e", "SOMETHING=\"else\""], @config.accessory(:redis).env_args
|
||||
end
|
||||
|
||||
test "volume args" do
|
||||
|
||||
@@ -38,11 +38,11 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
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\"" ], @config_with_roles.role(:workers).label_args
|
||||
end
|
||||
|
||||
test "special label args for web" do
|
||||
assert_equal [ "--label", "service=app", "--label", "role=web", "--label", "traefik.http.routers.app.rule='PathPrefix(`/`)'", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=/up", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=1s", "--label", "traefik.http.middlewares.app.retry.attempts=3", "--label", "traefik.http.middlewares.app.retry.initialinterval=500ms"], @config.role(:web).label_args
|
||||
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"web\"", "--label", "traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\"", "--label", "traefik.http.middlewares.app.retry.attempts=\"5\"", "--label", "traefik.http.middlewares.app.retry.initialinterval=\"500ms\""], @config.role(:web).label_args
|
||||
end
|
||||
|
||||
test "custom labels" do
|
||||
@@ -57,8 +57,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "overwriting default traefik label" do
|
||||
@deploy[:labels] = { "traefik.http.routers.app.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.rule"]
|
||||
@deploy[:labels] = { "traefik.http.routers.app.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.rule"]
|
||||
end
|
||||
|
||||
test "default traefik label on non-web role" do
|
||||
@@ -66,12 +66,12 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
||||
c[:servers]["beta"] = { "traefik" => "true", "hosts" => [ "1.1.1.5" ] }
|
||||
})
|
||||
|
||||
assert_equal [ "--label", "service=app", "--label", "role=beta", "--label", "traefik.http.routers.app.rule='PathPrefix(`/`)'", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=/up", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=1s", "--label", "traefik.http.middlewares.app.retry.attempts=3", "--label", "traefik.http.middlewares.app.retry.initialinterval=500ms" ], config.role(:beta).label_args
|
||||
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"beta\"", "--label", "traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\"", "--label", "traefik.http.middlewares.app.retry.attempts=\"5\"", "--label", "traefik.http.middlewares.app.retry.initialinterval=\"500ms\"" ], config.role(:beta).label_args
|
||||
end
|
||||
|
||||
test "env overwritten by role" do
|
||||
assert_equal "redis://a/b", @config_with_roles.role(:workers).env["REDIS_URL"]
|
||||
assert_equal ["-e", "REDIS_URL=redis://a/b", "-e", "WEB_CONCURRENCY=4"], @config_with_roles.role(:workers).env_args
|
||||
assert_equal ["-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], @config_with_roles.role(:workers).env_args
|
||||
end
|
||||
|
||||
test "env secret overwritten by role" do
|
||||
@@ -95,9 +95,9 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
||||
}
|
||||
|
||||
ENV["REDIS_PASSWORD"] = "secret456"
|
||||
ENV["DB_PASSWORD"] = "secret123"
|
||||
ENV["DB_PASSWORD"] = "secret&\"123"
|
||||
|
||||
assert_equal ["-e", "REDIS_PASSWORD=secret456", "-e", "DB_PASSWORD=secret123", "-e", "REDIS_URL=redis://a/b", "-e", "WEB_CONCURRENCY=4"], @config_with_roles.role(:workers).env_args
|
||||
assert_equal ["-e", "REDIS_PASSWORD=\"secret456\"", "-e", "DB_PASSWORD=\"secret&\\\"123\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], @config_with_roles.role(:workers).env_args
|
||||
ensure
|
||||
ENV["REDIS_PASSWORD"] = nil
|
||||
ENV["DB_PASSWORD"] = nil
|
||||
@@ -116,7 +116,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
||||
|
||||
ENV["DB_PASSWORD"] = "secret123"
|
||||
|
||||
assert_equal ["-e", "DB_PASSWORD=secret123", "-e", "REDIS_URL=redis://a/b", "-e", "WEB_CONCURRENCY=4"], @config_with_roles.role(:workers).env_args
|
||||
assert_equal ["-e", "DB_PASSWORD=\"secret123\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], @config_with_roles.role(:workers).env_args
|
||||
ensure
|
||||
ENV["DB_PASSWORD"] = nil
|
||||
end
|
||||
@@ -133,7 +133,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
||||
|
||||
ENV["REDIS_PASSWORD"] = "secret456"
|
||||
|
||||
assert_equal ["-e", "REDIS_PASSWORD=secret456", "-e", "REDIS_URL=redis://a/b", "-e", "WEB_CONCURRENCY=4"], @config_with_roles.role(:workers).env_args
|
||||
assert_equal ["-e", "REDIS_PASSWORD=\"secret456\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], @config_with_roles.role(:workers).env_args
|
||||
ensure
|
||||
ENV["REDIS_PASSWORD"] = nil
|
||||
end
|
||||
|
||||
@@ -89,7 +89,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "env args" do
|
||||
assert_equal [ "-e", "REDIS_URL=redis://x/y" ], @config.env_args
|
||||
assert_equal [ "-e", "REDIS_URL=\"redis://x/y\"" ], @config.env_args
|
||||
end
|
||||
|
||||
test "env args with clear and secrets" do
|
||||
@@ -98,7 +98,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
env: { "clear" => { "PORT" => "3000" }, "secret" => [ "PASSWORD" ] }
|
||||
}) })
|
||||
|
||||
assert_equal [ "-e", "PASSWORD=secret123", "-e", "PORT=3000" ], config.env_args
|
||||
assert_equal [ "-e", "PASSWORD=\"secret123\"", "-e", "PORT=\"3000\"" ], config.env_args
|
||||
assert config.env_args[1].is_a?(SSHKit::Redaction)
|
||||
ensure
|
||||
ENV["PASSWORD"] = nil
|
||||
@@ -109,7 +109,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
env: { "clear" => { "PORT" => "3000" } }
|
||||
}) })
|
||||
|
||||
assert_equal [ "-e", "PORT=3000" ], config.env_args
|
||||
assert_equal [ "-e", "PORT=\"3000\"" ], config.env_args
|
||||
end
|
||||
|
||||
test "env args with only secrets" do
|
||||
@@ -118,7 +118,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
env: { "secret" => [ "PASSWORD" ] }
|
||||
}) })
|
||||
|
||||
assert_equal [ "-e", "PASSWORD=secret123" ], config.env_args
|
||||
assert_equal [ "-e", "PASSWORD=\"secret123\"" ], config.env_args
|
||||
assert config.env_args[1].is_a?(SSHKit::Redaction)
|
||||
ensure
|
||||
ENV["PASSWORD"] = nil
|
||||
@@ -181,6 +181,6 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "to_h" do
|
||||
assert_equal({ :roles=>["web"], :hosts=>["1.1.1.1", "1.1.1.2"], :primary_host=>"1.1.1.1", :version=>"missing", :repository=>"dhh/app", :absolute_image=>"dhh/app:missing", :service_with_version=>"app-missing", :env_args=>["-e", "REDIS_URL=redis://x/y"], :ssh_options=>{:user=>"root", :auth_methods=>["publickey"]}, :volume_args=>["--volume", "/local/path:/container/path"], :healthcheck=>{"path"=>"/up", "port"=>3000 }}, @config.to_h)
|
||||
assert_equal({ :roles=>["web"], :hosts=>["1.1.1.1", "1.1.1.2"], :primary_host=>"1.1.1.1", :version=>"missing", :repository=>"dhh/app", :absolute_image=>"dhh/app:missing", :service_with_version=>"app-missing", :env_args=>["-e", "REDIS_URL=\"redis://x/y\""], :ssh_options=>{:user=>"root", :auth_methods=>["publickey"]}, :volume_args=>["--volume", "/local/path:/container/path"], :healthcheck=>{"path"=>"/up", "port"=>3000 }}, @config.to_h)
|
||||
end
|
||||
end
|
||||
|
||||
2
test/fixtures/deploy_with_accessories.yml
vendored
2
test/fixtures/deploy_with_accessories.yml
vendored
@@ -27,3 +27,5 @@ accessories:
|
||||
port: 6379
|
||||
directories:
|
||||
- data:/data
|
||||
|
||||
readiness_delay: 0
|
||||
Reference in New Issue
Block a user