Use local docker registry to push and pull app images
This commit is contained in:
@@ -153,6 +153,48 @@ class CliBuildTest < CliTestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "push without builder for local registry" do
|
||||
with_build_directory do |build_directory|
|
||||
stub_setup
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||
.with(:docker, "--version", "&&", :docker, :buildx, "version")
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||
.with { |*args| args[0..1] == [ :docker, :login ] }
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||
.with(:docker, :start, "kamal-docker-registry", "||", :docker, :run, "--detach", "-p", "127.0.0.1:5000:5000", "--name", "kamal-docker-registry", "registry:3")
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||
.with(:docker, :buildx, :rm, "kamal-local-registry-docker-container")
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||
.with(:docker, :buildx, :create, "--name", "kamal-local-registry-docker-container", "--driver=docker-container --driver-opt network=host")
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||
.with(:docker, :buildx, :inspect, "kamal-local-registry-docker-container")
|
||||
.raises(SSHKit::Command::Failed.new("no builder"))
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with { |*args| args.first.to_s.start_with?("git") }
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||
.with(:git, "-C", anything, :"rev-parse", :HEAD)
|
||||
.returns(Kamal::Git.revision)
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||
.with(:git, "-C", anything, :status, "--porcelain")
|
||||
.returns("")
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||
.with(:docker, :buildx, :build, "--output=type=registry", "--platform", "linux/amd64", "--builder", "kamal-local-registry-docker-container", "-t", "localhost:5000/dhh/app:999", "-t", "localhost:5000/dhh/app:latest", "--label", "service=\"app\"", "--file", "Dockerfile", ".", "2>&1")
|
||||
|
||||
run_command("push", fixture: :with_local_registry_and_accessories).tap do |output|
|
||||
assert_match /WARN Missing compatible builder, so creating a new one first/, output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "push without builder" do
|
||||
with_build_directory do |build_directory|
|
||||
stub_setup
|
||||
|
||||
@@ -39,6 +39,30 @@ class CliMainTest < CliTestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "deploy with local registry" do
|
||||
with_test_secrets("secrets" => "DB_PASSWORD=secret") do
|
||||
invoke_options = { "config_file" => "test/fixtures/deploy_with_local_registry.yml", "version" => "999", "skip_hooks" => false, "verbose" => true }
|
||||
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], 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:boot", [], invoke_options)
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
|
||||
|
||||
Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
|
||||
|
||||
run_command("deploy", "--verbose", config_file: "deploy_with_local_registry").tap do |output|
|
||||
assert_hook_ran "pre-connect", output
|
||||
assert_match /Build and push app image/, output
|
||||
assert_hook_ran "pre-deploy", output
|
||||
assert_match /Ensure kamal-proxy is running/, output
|
||||
assert_match /Detect stale containers/, output
|
||||
assert_match /Prune old containers and images/, output
|
||||
assert_hook_ran "post-deploy", output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "deploy" do
|
||||
with_test_secrets("secrets" => "DB_PASSWORD=secret") do
|
||||
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false, "verbose" => true }
|
||||
@@ -302,6 +326,16 @@ class CliMainTest < CliTestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "remove" do
|
||||
options = { "config_file" => "test/fixtures/deploy_simple.yml", "skip_hooks" => false, "confirmed" => true }
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:remove", [], options)
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:remove", [], options)
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:remove", [ "all" ], options)
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:remove", [], options.merge(skip_local: true))
|
||||
|
||||
run_command("remove", "-y")
|
||||
end
|
||||
|
||||
test "details" do
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:details")
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:details")
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
require_relative "cli_test_case"
|
||||
|
||||
class CliRegistryTest < CliTestCase
|
||||
test "login" do
|
||||
run_command("login").tap do |output|
|
||||
test "setup" do
|
||||
run_command("setup").tap do |output|
|
||||
assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] as .*@localhost/, output
|
||||
assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] on 1.1.1.\d/, output
|
||||
end
|
||||
end
|
||||
|
||||
test "login skip local" do
|
||||
run_command("login", "-L").tap do |output|
|
||||
test "setup skip local" do
|
||||
run_command("setup", "-L").tap do |output|
|
||||
assert_no_match /docker login -u \[REDACTED\] -p \[REDACTED\] as .*@localhost/, output
|
||||
assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] on 1.1.1.\d/, output
|
||||
end
|
||||
end
|
||||
|
||||
test "login skip remote" do
|
||||
run_command("login", "-R").tap do |output|
|
||||
test "setup skip remote" do
|
||||
run_command("setup", "-R").tap do |output|
|
||||
assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] as .*@localhost/, output
|
||||
assert_no_match /docker login -u \[REDACTED\] -p \[REDACTED\] on 1.1.1.\d/, output
|
||||
end
|
||||
end
|
||||
|
||||
test "logout" do
|
||||
run_command("logout").tap do |output|
|
||||
test "remove" do
|
||||
run_command("remove").tap do |output|
|
||||
assert_match /docker logout as .*@localhost/, output
|
||||
assert_match /docker logout on 1.1.1.\d/, output
|
||||
end
|
||||
end
|
||||
|
||||
test "logout skip local" do
|
||||
run_command("logout", "-L").tap do |output|
|
||||
test "remove skip local" do
|
||||
run_command("remove", "-L").tap do |output|
|
||||
assert_no_match /docker logout as .*@localhost/, output
|
||||
assert_match /docker logout on 1.1.1.\d/, output
|
||||
end
|
||||
end
|
||||
|
||||
test "logout skip remote" do
|
||||
run_command("logout", "-R").tap do |output|
|
||||
test "remove skip remote" do
|
||||
run_command("remove", "-R").tap do |output|
|
||||
assert_match /docker logout as .*@localhost/, output
|
||||
assert_no_match /docker logout on 1.1.1.\d/, output
|
||||
end
|
||||
end
|
||||
|
||||
test "login with no docker" do
|
||||
test "setup with no docker" do
|
||||
stub_setup
|
||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||
.with(:docker, "--version", "&&", :docker, :buildx, "version")
|
||||
.raises(SSHKit::Command::Failed.new("command not found"))
|
||||
|
||||
assert_raises(Kamal::Cli::DependencyError) { run_command("login") }
|
||||
assert_raises(Kamal::Cli::DependencyError) { run_command("setup") }
|
||||
end
|
||||
|
||||
test "allow remote login with no docker" do
|
||||
@@ -61,12 +61,23 @@ class CliRegistryTest < CliTestCase
|
||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||
.with { |*args| args[0..1] == [ :docker, :login ] }
|
||||
|
||||
assert_nothing_raised { run_command("login", "--skip-local") }
|
||||
assert_nothing_raised { run_command("setup", "--skip-local") }
|
||||
end
|
||||
|
||||
test "setup local registry" do
|
||||
run_command("setup", fixture: :with_local_registry).tap do |output|
|
||||
assert_match /docker start kamal-docker-registry || docker run --detach -p 127.0.0.1:5000:5000 --name kamal-docker-registry registry:2 as .*@localhost/, output
|
||||
end
|
||||
end
|
||||
|
||||
test "remove local registry" do
|
||||
run_command("remove", fixture: :with_local_registry).tap do |output|
|
||||
assert_match /docker stop kamal-docker-registry && docker rm kamal-docker-registry as .*@localhost/, output
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def run_command(*command)
|
||||
stdouted { Kamal::Cli::Registry.start([ *command, "-c", "test/fixtures/deploy_with_accessories.yml" ]) }
|
||||
def run_command(*command, fixture: :with_accessories)
|
||||
stdouted { Kamal::Cli::Registry.start([ *command, "-c", "test/fixtures/deploy_#{fixture}.yml" ]) }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user