Require an arch to be set, and default to amd64 in the template

This commit is contained in:
Donal McBreen
2024-08-28 11:35:39 +01:00
parent 56268d724d
commit d2d0223c37
46 changed files with 118 additions and 77 deletions

View File

@@ -18,6 +18,10 @@ registry:
password: password:
- KAMAL_REGISTRY_PASSWORD - KAMAL_REGISTRY_PASSWORD
# Configure builder setup.
builder:
arch: amd64
# Inject ENV variables into containers (secrets come from .env). # Inject ENV variables into containers (secrets come from .env).
# Remember to run `kamal env push` after making changes! # Remember to run `kamal env push` after making changes!
# env: # env:
@@ -30,16 +34,6 @@ registry:
# ssh: # ssh:
# user: app # user: app
# Configure builder setup.
# builder:
# args:
# RUBY_VERSION: 3.2.0
# secrets:
# - GITHUB_TOKEN
# remote:
# arch: amd64
# host: ssh://app@192.168.0.1
# Use accessory services (secrets come from .env). # Use accessory services (secrets come from .env).
# accessories: # accessories:
# db: # db:

View File

@@ -5,5 +5,7 @@ class Kamal::Configuration::Validator::Builder < Kamal::Configuration::Validator
if config["cache"] && config["cache"]["type"] if config["cache"] && config["cache"]["type"]
error "Invalid cache type: #{config["cache"]["type"]}" unless [ "gha", "registry" ].include?(config["cache"]["type"]) error "Invalid cache type: #{config["cache"]["type"]}" unless [ "gha", "registry" ].include?(config["cache"]["type"])
end end
error "Builder arch not set" unless config["arch"].present?
end end
end end

View File

@@ -26,7 +26,7 @@ class CliBuildTest < CliTestCase
assert_match /Cloning repo into build directory/, output assert_match /Cloning repo into build directory/, output
assert_match /git -C #{Dir.tmpdir}\/kamal-clones\/app-#{pwd_sha} clone #{Dir.pwd}/, output assert_match /git -C #{Dir.tmpdir}\/kamal-clones\/app-#{pwd_sha} clone #{Dir.pwd}/, output
assert_match /docker --version && docker buildx version/, output assert_match /docker --version && docker buildx version/, output
assert_match /docker build --push --platform linux\/amd64,linux\/arm64 --builder kamal-local-docker-container -t dhh\/app:999 -t dhh\/app:latest --label service="app" --file Dockerfile \. as .*@localhost/, output assert_match /docker build --push --platform linux\/amd64 --builder kamal-local-docker-container -t dhh\/app:999 -t dhh\/app:latest --label service="app" --file Dockerfile \. as .*@localhost/, output
end end
end end
end end
@@ -49,7 +49,7 @@ class CliBuildTest < CliTestCase
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :submodule, :update, "--init") SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :submodule, :update, "--init")
SSHKit::Backend::Abstract.any_instance.expects(:execute) SSHKit::Backend::Abstract.any_instance.expects(:execute)
.with(:docker, :build, "--push", "--platform", "linux/amd64,linux/arm64", "--builder", "kamal-local-docker-container", "-t", "dhh/app:999", "-t", "dhh/app:latest", "--label", "service=\"app\"", "--file", "Dockerfile", ".") .with(:docker, :build, "--push", "--platform", "linux/amd64", "--builder", "kamal-local-docker-container", "-t", "dhh/app:999", "-t", "dhh/app:latest", "--label", "service=\"app\"", "--file", "Dockerfile", ".")
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:git, "-C", anything, :"rev-parse", :HEAD) .with(:git, "-C", anything, :"rev-parse", :HEAD)
@@ -74,7 +74,7 @@ class CliBuildTest < CliTestCase
assert_no_match /Cloning repo into build directory/, output assert_no_match /Cloning repo into build directory/, 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 build --push --platform linux\/amd64,linux\/arm64 --builder kamal-local-docker-container -t dhh\/app:999 -t dhh\/app:latest --label service="app" --file Dockerfile . as .*@localhost/, output assert_match /docker build --push --platform linux\/amd64 --builder kamal-local-docker-container -t dhh\/app:999 -t dhh\/app:latest --label service="app" --file Dockerfile . as .*@localhost/, output
end end
end end
@@ -137,7 +137,7 @@ class CliBuildTest < CliTestCase
.returns("") .returns("")
SSHKit::Backend::Abstract.any_instance.expects(:execute) SSHKit::Backend::Abstract.any_instance.expects(:execute)
.with(:docker, :build, "--push", "--platform", "linux/amd64,linux/arm64", "--builder", "kamal-local-docker-container", "-t", "dhh/app:999", "-t", "dhh/app:latest", "--label", "service=\"app\"", "--file", "Dockerfile", ".") .with(:docker, :build, "--push", "--platform", "linux/amd64", "--builder", "kamal-local-docker-container", "-t", "dhh/app:999", "-t", "dhh/app:latest", "--label", "service=\"app\"", "--file", "Dockerfile", ".")
run_command("push").tap do |output| run_command("push").tap do |output|
assert_match /WARN Missing compatible builder, so creating a new one first/, output assert_match /WARN Missing compatible builder, so creating a new one first/, output

View File

@@ -5,6 +5,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
@config = { @config = {
service: "app", image: "dhh/app", registry: { "server" => "private.registry", "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "server" => "private.registry", "username" => "dhh", "password" => "secret" },
servers: [ "1.1.1.1" ], servers: [ "1.1.1.1" ],
builder: { "arch" => "amd64" },
accessories: { accessories: {
"mysql" => { "mysql" => {
"image" => "private.registry/mysql:8.0", "image" => "private.registry/mysql:8.0",

View File

@@ -5,7 +5,7 @@ class CommandsAppTest < ActiveSupport::TestCase
ENV["RAILS_MASTER_KEY"] = "456" ENV["RAILS_MASTER_KEY"] = "456"
Kamal::Configuration.any_instance.stubs(:run_id).returns("12345678901234567890123456789012") Kamal::Configuration.any_instance.stubs(:run_id).returns("12345678901234567890123456789012")
@config = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ], env: { "secret" => [ "RAILS_MASTER_KEY" ] } } @config = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ], env: { "secret" => [ "RAILS_MASTER_KEY" ] }, builder: { "arch" => "amd64" } }
end end
teardown do teardown do

View File

@@ -8,7 +8,7 @@ class CommandsAuditorTest < 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" }, builder: { "arch" => "amd64" }, servers: [ "1.1.1.1" ]
} }
@auditor = new_command @auditor = new_command

View File

@@ -2,14 +2,14 @@ require "test_helper"
class CommandsBuilderTest < ActiveSupport::TestCase class CommandsBuilderTest < ActiveSupport::TestCase
setup do setup do
@config = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ] } @config = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ], builder: { "arch" => "amd64" } }
end end
test "target linux/amd64,linux/arm64 locally by default" do test "target linux/amd64 locally by default" do
builder = new_builder_command(builder: { "cache" => { "type" => "gha" } }) builder = new_builder_command(builder: { "cache" => { "type" => "gha" } })
assert_equal "local", builder.name assert_equal "local", builder.name
assert_equal \ assert_equal \
"docker build --push --platform linux/amd64,linux/arm64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", "docker build --push --platform linux/amd64 --builder kamal-local-docker-container -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
@@ -25,12 +25,12 @@ class CommandsBuilderTest < ActiveSupport::TestCase
builder = new_builder_command(builder: { "cache" => { "type" => "gha" } }) builder = new_builder_command(builder: { "cache" => { "type" => "gha" } })
assert_equal "local", builder.name assert_equal "local", builder.name
assert_equal \ assert_equal \
"docker build --push --platform linux/amd64,linux/arm64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", "docker build --push --platform linux/amd64 --builder kamal-local-docker-container -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
test "hybrid build if remote is set" do test "hybrid build if remote is set and building multiarch" do
builder = new_builder_command(builder: { "remote" => "ssh://app@127.0.0.1", "cache" => { "type" => "gha" } }) builder = new_builder_command(builder: { "arch" => [ "amd64", "arm64" ], "remote" => "ssh://app@127.0.0.1", "cache" => { "type" => "gha" } })
assert_equal "hybrid", builder.name assert_equal "hybrid", builder.name
assert_equal \ assert_equal \
"docker build --push --platform linux/amd64,linux/arm64 --builder kamal-hybrid-docker-container-ssh---app-127-0-0-1 -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", "docker build --push --platform linux/amd64,linux/arm64 --builder kamal-hybrid-docker-container-ssh---app-127-0-0-1 -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
@@ -93,21 +93,21 @@ class CommandsBuilderTest < ActiveSupport::TestCase
test "build context" do test "build context" do
builder = new_builder_command(builder: { "context" => ".." }) builder = new_builder_command(builder: { "context" => ".." })
assert_equal \ assert_equal \
"docker build --push --platform linux/amd64,linux/arm64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ..", "docker build --push --platform linux/amd64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ..",
builder.push.join(" ") builder.push.join(" ")
end end
test "push with build args" do test "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 build --push --platform linux/amd64,linux/arm64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" --file Dockerfile .", "docker build --push --platform linux/amd64 --builder kamal-local-docker-container -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 "push with build secrets" do test "push with build secrets" do
builder = new_builder_command(builder: { "secrets" => [ "a", "b" ] }) builder = new_builder_command(builder: { "secrets" => [ "a", "b" ] })
assert_equal \ assert_equal \
"docker build --push --platform linux/amd64,linux/arm64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --secret id=\"a\" --secret id=\"b\" --file Dockerfile .", "docker build --push --platform linux/amd64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --secret id=\"a\" --secret id=\"b\" --file Dockerfile .",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -126,7 +126,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
test "context build" do test "context build" do
builder = new_builder_command(builder: { "context" => "./foo" }) builder = new_builder_command(builder: { "context" => "./foo" })
assert_equal \ assert_equal \
"docker build --push --platform linux/amd64,linux/arm64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo", "docker build --push --platform linux/amd64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -137,7 +137,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
private private
def new_builder_command(additional_config = {}) def new_builder_command(additional_config = {})
Kamal::Commands::Builder.new(Kamal::Configuration.new(@config.merge(additional_config), version: "123")) Kamal::Commands::Builder.new(Kamal::Configuration.new(@config.deep_merge(additional_config), version: "123"))
end end
def build_directory def build_directory

View File

@@ -3,7 +3,7 @@ require "test_helper"
class CommandsDockerTest < ActiveSupport::TestCase class CommandsDockerTest < 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" ], builder: { "arch" => "amd64" }
} }
@docker = Kamal::Commands::Docker.new(Kamal::Configuration.new(@config)) @docker = Kamal::Commands::Docker.new(Kamal::Configuration.new(@config))
end end

View File

@@ -8,7 +8,7 @@ class CommandsHookTest < ActiveSupport::TestCase
@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" } } builder: { "arch" => "amd64" }, traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
} }
@performer = Kamal::Git.email.presence || `whoami`.chomp @performer = Kamal::Git.email.presence || `whoami`.chomp

View File

@@ -4,7 +4,7 @@ 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" } } builder: { "arch" => "amd64" }, traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
} }
end end

View File

@@ -4,7 +4,7 @@ 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" } } builder: { "arch" => "amd64" }, traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
} }
end end

View File

@@ -8,6 +8,7 @@ class CommandsRegistryTest < ActiveSupport::TestCase
"password" => "secret", "password" => "secret",
"server" => "hub.docker.com" "server" => "hub.docker.com"
}, },
builder: { "arch" => "amd64" },
servers: [ "1.1.1.1" ] servers: [ "1.1.1.1" ]
} }
@registry = Kamal::Commands::Registry.new Kamal::Configuration.new(@config) @registry = Kamal::Commands::Registry.new Kamal::Configuration.new(@config)

View File

@@ -4,7 +4,7 @@ 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" } } builder: { "arch" => "amd64" }, traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
} }
end end

View File

@@ -5,7 +5,7 @@ class CommandsTraefikTest < ActiveSupport::TestCase
@image = "traefik:test" @image = "traefik:test"
@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" ], builder: { "arch" => "amd64" },
traefik: { "image" => @image, "args" => { "accesslog.format" => "json", "api.insecure" => true, "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } } traefik: { "image" => @image, "args" => { "accesslog.format" => "json", "api.insecure" => true, "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
} }

View File

@@ -8,6 +8,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
"web" => [ "1.1.1.1", "1.1.1.2" ], "web" => [ "1.1.1.1", "1.1.1.2" ],
"workers" => [ "1.1.1.3", "1.1.1.4" ] "workers" => [ "1.1.1.3", "1.1.1.4" ]
}, },
builder: { "arch" => "amd64" },
env: { "REDIS_URL" => "redis://x/y" }, env: { "REDIS_URL" => "redis://x/y" },
accessories: { accessories: {
"mysql" => { "mysql" => {

View File

@@ -4,13 +4,7 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
setup do setup do
@deploy = { @deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ "1.1.1.1" ] builder: { "arch" => "amd64" }, servers: [ "1.1.1.1" ]
}
@deploy_with_builder_option = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ "1.1.1.1" ],
builder: {}
} }
end end
@@ -27,16 +21,16 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
end end
test "setting both local and remote configs" do test "setting both local and remote configs" do
@deploy_with_builder_option[:builder] = { @deploy[:builder] = {
"arch" => [ "amd64", "arm64" ], "arch" => [ "amd64", "arm64" ],
"remote" => "ssh://root@192.168.0.1" "remote" => "ssh://root@192.168.0.1"
} }
assert_equal true, config_with_builder_option.builder.local? assert_equal true, config.builder.local?
assert_equal true, config_with_builder_option.builder.remote? assert_equal true, config.builder.remote?
assert_equal [ "amd64", "arm64" ], config_with_builder_option.builder.arches assert_equal [ "amd64", "arm64" ], config.builder.arches
assert_equal "ssh://root@192.168.0.1", config_with_builder_option.builder.remote assert_equal "ssh://root@192.168.0.1", config.builder.remote
end end
test "cached?" do test "cached?" do
@@ -44,10 +38,10 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
end end
test "invalid cache type specified" do test "invalid cache type specified" do
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "invalid" } } @deploy[:builder]["cache"] = { "type" => "invalid" }
assert_raises(Kamal::ConfigurationError) do assert_raises(Kamal::ConfigurationError) do
config_with_builder_option.builder config.builder
end end
end end
@@ -60,32 +54,32 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
end end
test "setting gha cache" do test "setting gha cache" do
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "gha", "options" => "mode=max" } } @deploy[:builder] = { "arch" => "amd64", "cache" => { "type" => "gha", "options" => "mode=max" } }
assert_equal "type=gha", config_with_builder_option.builder.cache_from assert_equal "type=gha", config.builder.cache_from
assert_equal "type=gha,mode=max", config_with_builder_option.builder.cache_to assert_equal "type=gha,mode=max", config.builder.cache_to
end end
test "setting registry cache" do test "setting registry cache" do
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } } @deploy[:builder] = { "arch" => "amd64", "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } }
assert_equal "type=registry,ref=dhh/app-build-cache", config_with_builder_option.builder.cache_from assert_equal "type=registry,ref=dhh/app-build-cache", config.builder.cache_from
assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=dhh/app-build-cache", config_with_builder_option.builder.cache_to assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=dhh/app-build-cache", config.builder.cache_to
end end
test "setting registry cache when using a custom registry" do test "setting registry cache when using a custom registry" do
@deploy_with_builder_option[:registry]["server"] = "registry.example.com" @deploy[:registry]["server"] = "registry.example.com"
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } } @deploy[:builder] = { "arch" => "amd64", "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } }
assert_equal "type=registry,ref=registry.example.com/dhh/app-build-cache", config_with_builder_option.builder.cache_from assert_equal "type=registry,ref=registry.example.com/dhh/app-build-cache", config.builder.cache_from
assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=registry.example.com/dhh/app-build-cache", config_with_builder_option.builder.cache_to assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=registry.example.com/dhh/app-build-cache", config.builder.cache_to
end end
test "setting registry cache with image" do test "setting registry cache with image" do
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "image" => "kamal", "options" => "mode=max" } } @deploy[:builder] = { "arch" => "amd64", "cache" => { "type" => "registry", "image" => "kamal", "options" => "mode=max" } }
assert_equal "type=registry,ref=kamal", config_with_builder_option.builder.cache_from assert_equal "type=registry,ref=kamal", config.builder.cache_from
assert_equal "type=registry,mode=max,ref=kamal", config_with_builder_option.builder.cache_to assert_equal "type=registry,mode=max,ref=kamal", config.builder.cache_to
end end
test "args" do test "args" do
@@ -93,9 +87,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
end end
test "setting args" do test "setting args" do
@deploy_with_builder_option[:builder] = { "args" => { "key" => "value" } } @deploy[:builder]["args"] = { "key" => "value" }
assert_equal({ "key" => "value" }, config_with_builder_option.builder.args) assert_equal({ "key" => "value" }, config.builder.args)
end end
test "secrets" do test "secrets" do
@@ -103,9 +97,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
end end
test "setting secrets" do test "setting secrets" do
@deploy_with_builder_option[:builder] = { "secrets" => [ "GITHUB_TOKEN" ] } @deploy[:builder]["secrets"] = [ "GITHUB_TOKEN" ]
assert_equal [ "GITHUB_TOKEN" ], config_with_builder_option.builder.secrets assert_equal [ "GITHUB_TOKEN" ], config.builder.secrets
end end
test "dockerfile" do test "dockerfile" do
@@ -113,9 +107,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
end end
test "setting dockerfile" do test "setting dockerfile" do
@deploy_with_builder_option[:builder] = { "dockerfile" => "Dockerfile.dev" } @deploy[:builder]["dockerfile"] = "Dockerfile.dev"
assert_equal "Dockerfile.dev", config_with_builder_option.builder.dockerfile assert_equal "Dockerfile.dev", config.builder.dockerfile
end end
test "context" do test "context" do
@@ -123,9 +117,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
end end
test "setting context" do test "setting context" do
@deploy_with_builder_option[:builder] = { "context" => ".." } @deploy[:builder]["context"] = ".."
assert_equal "..", config_with_builder_option.builder.context assert_equal "..", config.builder.context
end end
test "ssh" do test "ssh" do
@@ -133,17 +127,13 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
end end
test "setting ssh params" do test "setting ssh params" do
@deploy_with_builder_option[:builder] = { "ssh" => "default=$SSH_AUTH_SOCK" } @deploy[:builder]["ssh"] = "default=$SSH_AUTH_SOCK"
assert_equal "default=$SSH_AUTH_SOCK", config_with_builder_option.builder.ssh assert_equal "default=$SSH_AUTH_SOCK", config.builder.ssh
end end
private private
def config def config
Kamal::Configuration.new(@deploy) Kamal::Configuration.new(@deploy)
end end
def config_with_builder_option
Kamal::Configuration.new(@deploy_with_builder_option)
end
end end

View File

@@ -5,6 +5,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
@deploy = { @deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ { "1.1.1.1" => "odd" }, { "1.1.1.2" => "even" }, { "1.1.1.3" => [ "odd", "three" ] } ], servers: [ { "1.1.1.1" => "odd" }, { "1.1.1.2" => "even" }, { "1.1.1.3" => [ "odd", "three" ] } ],
builder: { "arch" => "amd64" },
env: { env: {
"clear" => { "REDIS_URL" => "redis://x/y", "THREE" => "false" }, "clear" => { "REDIS_URL" => "redis://x/y", "THREE" => "false" },
"tags" => { "tags" => {
@@ -64,6 +65,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
deploy = { deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ { "1.1.1.1" => [ "first", "second" ] } ], servers: [ { "1.1.1.1" => [ "first", "second" ] } ],
builder: { "arch" => "amd64" },
env: { env: {
"tags" => { "tags" => {
"first" => { "TYPE" => "first" }, "first" => { "TYPE" => "first" },
@@ -82,6 +84,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
deploy = { deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ { "1.1.1.1" => "secrets" } ], servers: [ { "1.1.1.1" => "secrets" } ],
builder: { "arch" => "amd64" },
env: { env: {
"tags" => { "tags" => {
"secrets" => { "secret" => [ "PASSWORD" ] } "secrets" => { "secret" => [ "PASSWORD" ] }
@@ -99,6 +102,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
deploy = { deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ { "1.1.1.1" => "clearly" } ], servers: [ { "1.1.1.1" => "clearly" } ],
builder: { "arch" => "amd64" },
env: { env: {
"tags" => { "tags" => {
"clearly" => { "clear" => { "FOO" => "bar" } } "clearly" => { "clear" => { "FOO" => "bar" } }

View File

@@ -5,6 +5,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
@deploy = { @deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ "1.1.1.1", "1.1.1.2" ], servers: [ "1.1.1.1", "1.1.1.2" ],
builder: { "arch" => "amd64" },
env: { "REDIS_URL" => "redis://x/y" } env: { "REDIS_URL" => "redis://x/y" }
} }

View File

@@ -5,6 +5,7 @@ class ConfigurationSshTest < ActiveSupport::TestCase
@deploy = { @deploy = {
service: "app", image: "dhh/app", service: "app", image: "dhh/app",
registry: { "username" => "dhh", "password" => "secret" }, registry: { "username" => "dhh", "password" => "secret" },
builder: { "arch" => "amd64" },
env: { "REDIS_URL" => "redis://x/y" }, env: { "REDIS_URL" => "redis://x/y" },
servers: [ "1.1.1.1", "1.1.1.2" ], servers: [ "1.1.1.1", "1.1.1.2" ],
volumes: [ "/local/path:/container/path" ] volumes: [ "/local/path:/container/path" ]

View File

@@ -6,6 +6,7 @@ class ConfigurationSshkitTest < ActiveSupport::TestCase
service: "app", image: "dhh/app", service: "app", image: "dhh/app",
registry: { "username" => "dhh", "password" => "secret" }, registry: { "username" => "dhh", "password" => "secret" },
env: { "REDIS_URL" => "redis://x/y" }, env: { "REDIS_URL" => "redis://x/y" },
builder: { "arch" => "amd64" },
servers: [ "1.1.1.1", "1.1.1.2" ], servers: [ "1.1.1.1", "1.1.1.2" ],
volumes: [ "/local/path:/container/path" ] volumes: [ "/local/path:/container/path" ]
} }

View File

@@ -101,6 +101,7 @@ class ConfigurationValidationTest < ActiveSupport::TestCase
valid_config = { valid_config = {
service: "app", service: "app",
image: "app", image: "app",
builder: { "arch" => "amd64" },
registry: { "username" => "user", "password" => "secret" }, registry: { "username" => "user", "password" => "secret" },
servers: [ "1.1.1.1" ] servers: [ "1.1.1.1" ]
} }

View File

@@ -8,6 +8,7 @@ class ConfigurationTest < ActiveSupport::TestCase
@deploy = { @deploy = {
service: "app", image: "dhh/app", service: "app", image: "dhh/app",
registry: { "username" => "dhh", "password" => "secret" }, registry: { "username" => "dhh", "password" => "secret" },
builder: { "arch" => "amd64" },
env: { "REDIS_URL" => "redis://x/y" }, env: { "REDIS_URL" => "redis://x/y" },
servers: [ "1.1.1.1", "1.1.1.2" ], servers: [ "1.1.1.1", "1.1.1.2" ],
volumes: [ "/local/path:/container/path" ] volumes: [ "/local/path:/container/path" ]
@@ -121,7 +122,7 @@ class ConfigurationTest < ActiveSupport::TestCase
test "version from uncommitted context" do test "version from uncommitted context" do
ENV.delete("VERSION") ENV.delete("VERSION")
config = Kamal::Configuration.new(@deploy.tap { |c| c[:builder] = { "context" => "." } }) config = Kamal::Configuration.new(@deploy.tap { |c| c[:builder]["context"] = "." })
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")
@@ -267,7 +268,7 @@ class ConfigurationTest < ActiveSupport::TestCase
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: { "arch" => "amd64" },
logging: [ "--log-opt", "max-size=\"10m\"" ], logging: [ "--log-opt", "max-size=\"10m\"" ],
healthcheck: { "cmd"=>"curl -f http://localhost:3000/up || exit 1", "interval" => "1s", "path"=>"/up", "port"=>3000, "max_attempts" => 7, "cord" => "/tmp/kamal-cord", "log_lines" => 50 } } healthcheck: { "cmd"=>"curl -f http://localhost:3000/up || exit 1", "interval" => "1s", "path"=>"/up", "port"=>3000, "max_attempts" => 7, "cord" => "/tmp/kamal-cord", "log_lines" => 50 } }

View File

@@ -9,3 +9,5 @@ registry:
server: registry.digitalocean.com server: registry.digitalocean.com
username: <%= "my-user" %> username: <%= "my-user" %>
password: <%= "my-password" %> password: <%= "my-password" %>
builder:
arch: amd64

View File

@@ -4,3 +4,5 @@ registry:
server: registry.digitalocean.com server: registry.digitalocean.com
username: <%= "my-user" %> username: <%= "my-user" %>
password: <%= "my-password" %> password: <%= "my-password" %>
builder:
arch: amd64

View File

@@ -4,4 +4,6 @@ registry:
server: registry.digitalocean.com server: registry.digitalocean.com
username: <%= "my-user" %> username: <%= "my-user" %>
password: <%= "my-password" %> password: <%= "my-password" %>
builder:
arch: amd64
require_destination: true require_destination: true

View File

@@ -17,4 +17,6 @@ registry:
server: registry.digitalocean.com server: registry.digitalocean.com
username: user username: user
password: pw password: pw
builder:
arch: amd64
primary_role: web_tokyo primary_role: web_tokyo

View File

@@ -6,3 +6,5 @@ servers:
registry: registry:
username: user username: user
password: pw password: pw
builder:
arch: amd64

View File

@@ -10,6 +10,8 @@ servers:
registry: registry:
username: user username: user
password: pw password: pw
builder:
arch: amd64
accessories: accessories:
mysql: mysql:

View File

@@ -6,4 +6,6 @@ servers:
registry: registry:
username: user username: user
password: pw password: pw
builder:
arch: amd64
asset_path: /public/assets asset_path: /public/assets

View File

@@ -7,6 +7,8 @@ servers:
workers: workers:
- "1.1.1.3" - "1.1.1.3"
- "1.1.1.4" - "1.1.1.4"
builder:
arch: amd64
registry: registry:
username: user username: user

View File

@@ -11,6 +11,8 @@ servers:
- 1.1.1.4: site1 - 1.1.1.4: site1
- 1.2.1.3: site2 - 1.2.1.3: site2
- 1.2.1.4: [ site2 experimental ] - 1.2.1.4: [ site2 experimental ]
builder:
arch: amd64
env: env:
clear: clear:
TEST: "root" TEST: "root"

View File

@@ -21,4 +21,6 @@ registry:
server: registry.digitalocean.com server: registry.digitalocean.com
username: user username: user
password: pw password: pw
builder:
arch: amd64
primary_role: web_tokyo primary_role: web_tokyo

View File

@@ -7,6 +7,8 @@ servers:
workers: workers:
- "1.1.1.3" - "1.1.1.3"
- "1.1.1.4" - "1.1.1.4"
builder:
arch: amd64
registry: registry:
username: user username: user

View File

@@ -26,6 +26,8 @@ servers:
hosts: hosts:
- 1.1.1.3 - 1.1.1.3
- 1.1.1.4 - 1.1.1.4
builder:
arch: amd64
env: env:
REDIS_URL: redis://x/y REDIS_URL: redis://x/y
registry: registry:

View File

@@ -7,6 +7,8 @@ servers:
workers: workers:
- "1.1.1.3" - "1.1.1.3"
- "1.1.1.4" - "1.1.1.4"
builder:
arch: amd64
registry: registry:
username: user username: user

View File

@@ -32,6 +32,8 @@ accessories:
port: 6379 port: 6379
directories: directories:
- data:/data - data:/data
builder:
arch: amd64
readiness_delay: 0 readiness_delay: 0

View File

@@ -32,6 +32,8 @@ accessories:
port: 6379 port: 6379
directories: directories:
- data:/data - data:/data
builder:
arch: amd64
readiness_delay: 0 readiness_delay: 0

View File

@@ -14,3 +14,5 @@ registry:
server: registry.digitalocean.com server: registry.digitalocean.com
username: user username: user
password: pw password: pw
builder:
arch: amd64

View File

@@ -9,3 +9,5 @@ registry:
env: env:
secret: secret:
- PASSWORD - PASSWORD
builder:
arch: amd64

View File

@@ -13,3 +13,5 @@ registry:
server: registry.digitalocean.com server: registry.digitalocean.com
username: user username: user
password: pw password: pw
builder:
arch: amd64

View File

@@ -6,3 +6,5 @@ servers:
registry: registry:
username: user username: user
password: pw password: pw
builder:
arch: amd64

View File

@@ -36,4 +36,5 @@ accessories:
readiness_delay: 0 readiness_delay: 0
builder: builder:
arch: amd64
context: "." context: "."

View File

@@ -10,3 +10,5 @@ primary_role: workers
registry: registry:
username: user username: user
password: pw password: pw
builder:
arch: amd64

View File

@@ -24,6 +24,7 @@ registry:
password: root password: root
builder: builder:
driver: docker driver: docker
arch: <%= uname_m = `uname -m`; uname_m == "x86_64" ? "amd64" : uname_m %>
args: args:
COMMIT_SHA: <%= `git rev-parse HEAD` %> COMMIT_SHA: <%= `git rev-parse HEAD` %>
healthcheck: healthcheck:

View File

@@ -18,6 +18,7 @@ registry:
password: root password: root
builder: builder:
driver: docker driver: docker
arch: <%= uname_m = `uname -m`; uname_m == "x86_64" ? "amd64" : uname_m %>
args: args:
COMMIT_SHA: <%= `git rev-parse HEAD` %> COMMIT_SHA: <%= `git rev-parse HEAD` %>
healthcheck: healthcheck:

View File

@@ -77,7 +77,7 @@ class MainTest < IntegrationTest
assert_equal "app-#{version}", config[:service_with_version] assert_equal "app-#{version}", config[:service_with_version]
assert_equal [], config[:volume_args] assert_equal [], config[:volume_args]
assert_equal({ user: "root", port: 22, keepalive: true, keepalive_interval: 30, log_level: :fatal }, config[:ssh_options]) assert_equal({ user: "root", port: 22, keepalive: true, keepalive_interval: 30, log_level: :fatal }, config[:ssh_options])
assert_equal({ "driver" => "docker", "args" => { "COMMIT_SHA" => version } }, config[:builder]) assert_equal({ "driver" => "docker", "arch" => "amd64", "args" => { "COMMIT_SHA" => version } }, config[:builder])
assert_equal [ "--log-opt", "max-size=\"10m\"" ], config[:logging] assert_equal [ "--log-opt", "max-size=\"10m\"" ], config[:logging]
assert_equal({ "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1", "interval"=>"1s", "max_attempts"=>3, "port"=>3000, "path"=>"/up", "cord"=>"/tmp/kamal-cord", "log_lines"=>50 }, config[:healthcheck]) assert_equal({ "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1", "interval"=>"1s", "max_attempts"=>3, "port"=>3000, "path"=>"/up", "cord"=>"/tmp/kamal-cord", "log_lines"=>50 }, config[:healthcheck])
end end