Merge branch 'main' into allow-bastion-server
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
require "test_helper"
|
||||
require "mrsk/configuration"
|
||||
require "mrsk/commands/accessory"
|
||||
|
||||
class CommandsAccessoryTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@config = {
|
||||
@config = {
|
||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
|
||||
servers: [ "1.1.1.1" ],
|
||||
accessories: {
|
||||
@@ -41,18 +39,20 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
||||
@config = Mrsk::Configuration.new(@config)
|
||||
@mysql = Mrsk::Commands::Accessory.new(@config, name: :mysql)
|
||||
@redis = Mrsk::Commands::Accessory.new(@config, name: :redis)
|
||||
|
||||
ENV["MYSQL_ROOT_PASSWORD"] = "secret123"
|
||||
end
|
||||
|
||||
teardown do
|
||||
ENV.delete("MYSQL_ROOT_PASSWORD")
|
||||
end
|
||||
|
||||
test "run" do
|
||||
ENV["MYSQL_ROOT_PASSWORD"] = "secret123"
|
||||
|
||||
assert_equal \
|
||||
[:docker, :run, "--name", "app-mysql", "-d", "--restart", "unless-stopped", "-p", "3306:3306", "-e", "MYSQL_ROOT_PASSWORD=secret123", "-e", "MYSQL_ROOT_HOST=%", "--label", "service=app-mysql", "mysql:8.0"], @mysql.run
|
||||
|
||||
assert_equal \
|
||||
[:docker, :run, "--name", "app-redis", "-d", "--restart", "unless-stopped", "-p", "6379:6379", "-e", "SOMETHING=else", "--volume", "/var/lib/redis:/data", "--label", "service=app-redis", "--label", "cache=true", "redis:latest"], @redis.run
|
||||
ensure
|
||||
ENV["MYSQL_ROOT_PASSWORD"] = nil
|
||||
end
|
||||
|
||||
test "start" do
|
||||
@@ -67,6 +67,35 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
||||
assert_equal [:docker, :ps, "--filter", "label=service=app-mysql"], @mysql.info
|
||||
end
|
||||
|
||||
|
||||
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" ],
|
||||
@mysql.execute_in_new_container("mysql", "-u", "root")
|
||||
end
|
||||
|
||||
test "execute in existing container" do
|
||||
assert_equal \
|
||||
[ :docker, :exec, "app-mysql", "mysql", "-u", "root" ],
|
||||
@mysql.execute_in_existing_container("mysql", "-u", "root")
|
||||
end
|
||||
|
||||
test "execute in new container over ssh" do
|
||||
@mysql.stub(:run_over_ssh, ->(cmd) { cmd }) do
|
||||
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
|
||||
|
||||
test "execute in existing container over ssh" do
|
||||
@mysql.stub(:run_over_ssh, ->(cmd) { cmd }) do
|
||||
assert_match %r|docker exec -it app-mysql mysql -u root|,
|
||||
@mysql.execute_in_existing_container_over_ssh("mysql", "-u", "root")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
test "logs" do
|
||||
assert_equal [:docker, :logs, "app-mysql", "-t", "2>&1"], @mysql.logs
|
||||
assert_equal [:docker, :logs, "app-mysql", " --since 5m", " -n 100", "-t", "2>&1", "|", "grep 'thing'"], @mysql.logs(since: "5m", lines: 100, grep: "thing")
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require "test_helper"
|
||||
require "mrsk/configuration"
|
||||
require "mrsk/commands/app"
|
||||
|
||||
class CommandsAppTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@@ -26,12 +24,34 @@ class CommandsAppTest < ActiveSupport::TestCase
|
||||
[:docker, :run, "-d", "--restart unless-stopped", "--name", "app-missing", "-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:missing"], @app.run
|
||||
end
|
||||
|
||||
test "run with" do
|
||||
|
||||
test "execute in new container" do
|
||||
assert_equal \
|
||||
[ :docker, :run, "--rm", "-e", "RAILS_MASTER_KEY=456", "dhh/app:missing", "bin/rails", "db:setup" ],
|
||||
@app.run_exec("bin/rails", "db:setup")
|
||||
@app.execute_in_new_container("bin/rails", "db:setup")
|
||||
end
|
||||
|
||||
test "execute in existing container" do
|
||||
assert_equal \
|
||||
[ :docker, :exec, "app-missing", "bin/rails", "db:setup" ],
|
||||
@app.execute_in_existing_container("bin/rails", "db:setup")
|
||||
end
|
||||
|
||||
test "execute in new container over ssh" do
|
||||
@app.stub(:run_over_ssh, ->(cmd, host:) { cmd }) do
|
||||
assert_match %r|docker run -it --rm -e RAILS_MASTER_KEY=456 dhh/app:missing bin/rails c|,
|
||||
@app.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||
end
|
||||
end
|
||||
|
||||
test "execute in existing container over ssh" do
|
||||
@app.stub(:run_over_ssh, ->(cmd, host:) { cmd }) do
|
||||
assert_match %r|docker exec -it app-missing bin/rails c|,
|
||||
@app.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
test "run without master key" do
|
||||
ENV["RAILS_MASTER_KEY"] = nil
|
||||
@app = Mrsk::Commands::App.new Mrsk::Configuration.new(@config.tap { |c| c[:skip_master_key] = true })
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require "test_helper"
|
||||
require "mrsk/configuration"
|
||||
require "mrsk/commands/builder"
|
||||
|
||||
class CommandsBuilderTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
require "test_helper"
|
||||
require "mrsk/configuration"
|
||||
require "mrsk/commands/registry"
|
||||
|
||||
class CommandsRegistryTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@config = { service: "app",
|
||||
@config = { service: "app",
|
||||
image: "dhh/app",
|
||||
registry: { "username" => "dhh",
|
||||
"password" => "secret",
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require "test_helper"
|
||||
require "mrsk/configuration"
|
||||
require "mrsk/commands/traefik"
|
||||
|
||||
class CommandsTraefikTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
|
||||
Reference in New Issue
Block a user