From d2d0223c370f4face9030b311762e920c1182b28 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Wed, 28 Aug 2024 11:35:39 +0100 Subject: [PATCH] Require an arch to be set, and default to amd64 in the template --- lib/kamal/cli/templates/deploy.yml | 14 ++-- lib/kamal/configuration/validator/builder.rb | 2 + test/cli/build_test.rb | 8 +-- test/commands/accessory_test.rb | 1 + test/commands/app_test.rb | 2 +- test/commands/auditor_test.rb | 2 +- test/commands/builder_test.rb | 22 +++--- test/commands/docker_test.rb | 2 +- test/commands/hook_test.rb | 2 +- test/commands/lock_test.rb | 2 +- test/commands/prune_test.rb | 2 +- test/commands/registry_test.rb | 1 + test/commands/server_test.rb | 2 +- test/commands/traefik_test.rb | 2 +- test/configuration/accessory_test.rb | 1 + test/configuration/builder_test.rb | 72 ++++++++----------- test/configuration/env/tags_test.rb | 4 ++ test/configuration/role_test.rb | 1 + test/configuration/ssh_test.rb | 1 + test/configuration/sshkit_test.rb | 1 + test/configuration/validation_test.rb | 1 + test/configuration_test.rb | 5 +- test/fixtures/deploy.erb.yml | 2 + test/fixtures/deploy_for_dest.yml | 2 + test/fixtures/deploy_for_required_dest.yml | 2 + .../deploy_primary_web_role_override.yml | 2 + test/fixtures/deploy_simple.yml | 2 + test/fixtures/deploy_with_accessories.yml | 2 + test/fixtures/deploy_with_assets.yml | 2 + test/fixtures/deploy_with_boot_strategy.yml | 2 + test/fixtures/deploy_with_env_tags.yml | 2 + test/fixtures/deploy_with_extensions.yml | 2 + ...ploy_with_low_percentage_boot_strategy.yml | 2 + .../deploy_with_multiple_traefik_roles.yml | 2 + .../deploy_with_percentage_boot_strategy.yml | 2 + test/fixtures/deploy_with_remote_builder.yml | 2 + ...y_with_remote_builder_and_custom_ports.yml | 2 + test/fixtures/deploy_with_roles.yml | 2 + test/fixtures/deploy_with_secrets.yml | 2 + .../deploy_with_two_roles_one_host.yml | 2 + .../deploy_with_uncommon_hostnames.yml | 2 + test/fixtures/deploy_without_clone.yml | 1 + test/fixtures/deploy_workers_only.yml | 2 + .../docker/deployer/app/config/deploy.yml | 1 + .../deployer/app_with_roles/config/deploy.yml | 1 + test/integration/main_test.rb | 2 +- 46 files changed, 118 insertions(+), 77 deletions(-) diff --git a/lib/kamal/cli/templates/deploy.yml b/lib/kamal/cli/templates/deploy.yml index 2602c66d..119961b9 100644 --- a/lib/kamal/cli/templates/deploy.yml +++ b/lib/kamal/cli/templates/deploy.yml @@ -18,6 +18,10 @@ registry: password: - KAMAL_REGISTRY_PASSWORD +# Configure builder setup. +builder: + arch: amd64 + # Inject ENV variables into containers (secrets come from .env). # Remember to run `kamal env push` after making changes! # env: @@ -30,16 +34,6 @@ registry: # ssh: # 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). # accessories: # db: diff --git a/lib/kamal/configuration/validator/builder.rb b/lib/kamal/configuration/validator/builder.rb index ebccdf81..4bd815bf 100644 --- a/lib/kamal/configuration/validator/builder.rb +++ b/lib/kamal/configuration/validator/builder.rb @@ -5,5 +5,7 @@ class Kamal::Configuration::Validator::Builder < Kamal::Configuration::Validator if config["cache"] && config["cache"]["type"] error "Invalid cache type: #{config["cache"]["type"]}" unless [ "gha", "registry" ].include?(config["cache"]["type"]) end + + error "Builder arch not set" unless config["arch"].present? end end diff --git a/test/cli/build_test.rb b/test/cli/build_test.rb index c8f01540..11b6fb1e 100644 --- a/test/cli/build_test.rb +++ b/test/cli/build_test.rb @@ -26,7 +26,7 @@ class CliBuildTest < CliTestCase 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 /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 @@ -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(: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) .with(:git, "-C", anything, :"rev-parse", :HEAD) @@ -74,7 +74,7 @@ class CliBuildTest < CliTestCase assert_no_match /Cloning repo into build directory/, output assert_hook_ran "pre-build", output, **hook_variables 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 @@ -137,7 +137,7 @@ class CliBuildTest < CliTestCase .returns("") 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| assert_match /WARN Missing compatible builder, so creating a new one first/, output diff --git a/test/commands/accessory_test.rb b/test/commands/accessory_test.rb index 94c1bebc..40002988 100644 --- a/test/commands/accessory_test.rb +++ b/test/commands/accessory_test.rb @@ -5,6 +5,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase @config = { service: "app", image: "dhh/app", registry: { "server" => "private.registry", "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ], + builder: { "arch" => "amd64" }, accessories: { "mysql" => { "image" => "private.registry/mysql:8.0", diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index 502501cd..bee7dc34 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -5,7 +5,7 @@ class CommandsAppTest < ActiveSupport::TestCase ENV["RAILS_MASTER_KEY"] = "456" 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 teardown do diff --git a/test/commands/auditor_test.rb b/test/commands/auditor_test.rb index 5b7a34c5..2aaafd67 100644 --- a/test/commands/auditor_test.rb +++ b/test/commands/auditor_test.rb @@ -8,7 +8,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase freeze_time @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 diff --git a/test/commands/builder_test.rb b/test/commands/builder_test.rb index 960c17fe..b7094126 100644 --- a/test/commands/builder_test.rb +++ b/test/commands/builder_test.rb @@ -2,14 +2,14 @@ require "test_helper" class CommandsBuilderTest < ActiveSupport::TestCase 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 - 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" } }) assert_equal "local", builder.name 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(" ") end @@ -25,12 +25,12 @@ class CommandsBuilderTest < ActiveSupport::TestCase builder = new_builder_command(builder: { "cache" => { "type" => "gha" } }) assert_equal "local", builder.name 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(" ") end - test "hybrid build if remote is set" do - builder = new_builder_command(builder: { "remote" => "ssh://app@127.0.0.1", "cache" => { "type" => "gha" } }) + test "hybrid build if remote is set and building multiarch" do + 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 \ "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 builder = new_builder_command(builder: { "context" => ".." }) 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(" ") end test "push with build args" do builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } }) 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(" ") end test "push with build secrets" do builder = new_builder_command(builder: { "secrets" => [ "a", "b" ] }) 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(" ") end @@ -126,7 +126,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase test "context build" do builder = new_builder_command(builder: { "context" => "./foo" }) 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(" ") end @@ -137,7 +137,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase private 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 def build_directory diff --git a/test/commands/docker_test.rb b/test/commands/docker_test.rb index 0c0e976b..db2ed45c 100644 --- a/test/commands/docker_test.rb +++ b/test/commands/docker_test.rb @@ -3,7 +3,7 @@ require "test_helper" class CommandsDockerTest < ActiveSupport::TestCase setup do @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)) end diff --git a/test/commands/hook_test.rb b/test/commands/hook_test.rb index c0e6e98f..60438c66 100644 --- a/test/commands/hook_test.rb +++ b/test/commands/hook_test.rb @@ -8,7 +8,7 @@ class CommandsHookTest < ActiveSupport::TestCase @config = { 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 diff --git a/test/commands/lock_test.rb b/test/commands/lock_test.rb index fc2b15ab..02871922 100644 --- a/test/commands/lock_test.rb +++ b/test/commands/lock_test.rb @@ -4,7 +4,7 @@ class CommandsLockTest < ActiveSupport::TestCase setup do @config = { 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 diff --git a/test/commands/prune_test.rb b/test/commands/prune_test.rb index c4a56a9a..430a13db 100644 --- a/test/commands/prune_test.rb +++ b/test/commands/prune_test.rb @@ -4,7 +4,7 @@ class CommandsPruneTest < ActiveSupport::TestCase setup do @config = { 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 diff --git a/test/commands/registry_test.rb b/test/commands/registry_test.rb index c25d7585..17376fef 100755 --- a/test/commands/registry_test.rb +++ b/test/commands/registry_test.rb @@ -8,6 +8,7 @@ class CommandsRegistryTest < ActiveSupport::TestCase "password" => "secret", "server" => "hub.docker.com" }, + builder: { "arch" => "amd64" }, servers: [ "1.1.1.1" ] } @registry = Kamal::Commands::Registry.new Kamal::Configuration.new(@config) diff --git a/test/commands/server_test.rb b/test/commands/server_test.rb index 9e063f77..8c465fd9 100644 --- a/test/commands/server_test.rb +++ b/test/commands/server_test.rb @@ -4,7 +4,7 @@ class CommandsServerTest < ActiveSupport::TestCase setup do @config = { 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 diff --git a/test/commands/traefik_test.rb b/test/commands/traefik_test.rb index a46fc284..446c3077 100644 --- a/test/commands/traefik_test.rb +++ b/test/commands/traefik_test.rb @@ -5,7 +5,7 @@ class CommandsTraefikTest < ActiveSupport::TestCase @image = "traefik:test" @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" } } } diff --git a/test/configuration/accessory_test.rb b/test/configuration/accessory_test.rb index 581cdab3..3f939607 100644 --- a/test/configuration/accessory_test.rb +++ b/test/configuration/accessory_test.rb @@ -8,6 +8,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase "web" => [ "1.1.1.1", "1.1.1.2" ], "workers" => [ "1.1.1.3", "1.1.1.4" ] }, + builder: { "arch" => "amd64" }, env: { "REDIS_URL" => "redis://x/y" }, accessories: { "mysql" => { diff --git a/test/configuration/builder_test.rb b/test/configuration/builder_test.rb index efcd613b..3df477c9 100644 --- a/test/configuration/builder_test.rb +++ b/test/configuration/builder_test.rb @@ -4,13 +4,7 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase setup do @deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, - 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: {} + builder: { "arch" => "amd64" }, servers: [ "1.1.1.1" ] } end @@ -27,16 +21,16 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase end test "setting both local and remote configs" do - @deploy_with_builder_option[:builder] = { + @deploy[:builder] = { "arch" => [ "amd64", "arm64" ], "remote" => "ssh://root@192.168.0.1" } - assert_equal true, config_with_builder_option.builder.local? - assert_equal true, config_with_builder_option.builder.remote? + assert_equal true, config.builder.local? + assert_equal true, config.builder.remote? - assert_equal [ "amd64", "arm64" ], config_with_builder_option.builder.arches - assert_equal "ssh://root@192.168.0.1", config_with_builder_option.builder.remote + assert_equal [ "amd64", "arm64" ], config.builder.arches + assert_equal "ssh://root@192.168.0.1", config.builder.remote end test "cached?" do @@ -44,10 +38,10 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase end test "invalid cache type specified" do - @deploy_with_builder_option[:builder] = { "cache" => { "type" => "invalid" } } + @deploy[:builder]["cache"] = { "type" => "invalid" } assert_raises(Kamal::ConfigurationError) do - config_with_builder_option.builder + config.builder end end @@ -60,32 +54,32 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase end 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,mode=max", config_with_builder_option.builder.cache_to + assert_equal "type=gha", config.builder.cache_from + assert_equal "type=gha,mode=max", config.builder.cache_to end 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,mode=max,image-manifest=true,oci-mediatypes=true,ref=dhh/app-build-cache", config_with_builder_option.builder.cache_to + 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.builder.cache_to end test "setting registry cache when using a custom registry" do - @deploy_with_builder_option[:registry]["server"] = "registry.example.com" - @deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } } + @deploy[:registry]["server"] = "registry.example.com" + @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,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,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.builder.cache_to end 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,mode=max,ref=kamal", config_with_builder_option.builder.cache_to + assert_equal "type=registry,ref=kamal", config.builder.cache_from + assert_equal "type=registry,mode=max,ref=kamal", config.builder.cache_to end test "args" do @@ -93,9 +87,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase end 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 test "secrets" do @@ -103,9 +97,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase end 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 test "dockerfile" do @@ -113,9 +107,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase end 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 test "context" do @@ -123,9 +117,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase end 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 test "ssh" do @@ -133,17 +127,13 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase end 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 private def config Kamal::Configuration.new(@deploy) end - - def config_with_builder_option - Kamal::Configuration.new(@deploy_with_builder_option) - end end diff --git a/test/configuration/env/tags_test.rb b/test/configuration/env/tags_test.rb index c36b6057..0fb649d1 100644 --- a/test/configuration/env/tags_test.rb +++ b/test/configuration/env/tags_test.rb @@ -5,6 +5,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase @deploy = { 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" ] } ], + builder: { "arch" => "amd64" }, env: { "clear" => { "REDIS_URL" => "redis://x/y", "THREE" => "false" }, "tags" => { @@ -64,6 +65,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ { "1.1.1.1" => [ "first", "second" ] } ], + builder: { "arch" => "amd64" }, env: { "tags" => { "first" => { "TYPE" => "first" }, @@ -82,6 +84,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ { "1.1.1.1" => "secrets" } ], + builder: { "arch" => "amd64" }, env: { "tags" => { "secrets" => { "secret" => [ "PASSWORD" ] } @@ -99,6 +102,7 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ { "1.1.1.1" => "clearly" } ], + builder: { "arch" => "amd64" }, env: { "tags" => { "clearly" => { "clear" => { "FOO" => "bar" } } diff --git a/test/configuration/role_test.rb b/test/configuration/role_test.rb index da9a3d1c..37c26fcd 100644 --- a/test/configuration/role_test.rb +++ b/test/configuration/role_test.rb @@ -5,6 +5,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase @deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1", "1.1.1.2" ], + builder: { "arch" => "amd64" }, env: { "REDIS_URL" => "redis://x/y" } } diff --git a/test/configuration/ssh_test.rb b/test/configuration/ssh_test.rb index f49c0055..76d1ae9a 100644 --- a/test/configuration/ssh_test.rb +++ b/test/configuration/ssh_test.rb @@ -5,6 +5,7 @@ class ConfigurationSshTest < ActiveSupport::TestCase @deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, + builder: { "arch" => "amd64" }, env: { "REDIS_URL" => "redis://x/y" }, servers: [ "1.1.1.1", "1.1.1.2" ], volumes: [ "/local/path:/container/path" ] diff --git a/test/configuration/sshkit_test.rb b/test/configuration/sshkit_test.rb index dc8c2258..1608e6ee 100644 --- a/test/configuration/sshkit_test.rb +++ b/test/configuration/sshkit_test.rb @@ -6,6 +6,7 @@ class ConfigurationSshkitTest < ActiveSupport::TestCase service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, env: { "REDIS_URL" => "redis://x/y" }, + builder: { "arch" => "amd64" }, servers: [ "1.1.1.1", "1.1.1.2" ], volumes: [ "/local/path:/container/path" ] } diff --git a/test/configuration/validation_test.rb b/test/configuration/validation_test.rb index b39dbc36..ac409e84 100644 --- a/test/configuration/validation_test.rb +++ b/test/configuration/validation_test.rb @@ -101,6 +101,7 @@ class ConfigurationValidationTest < ActiveSupport::TestCase valid_config = { service: "app", image: "app", + builder: { "arch" => "amd64" }, registry: { "username" => "user", "password" => "secret" }, servers: [ "1.1.1.1" ] } diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 043a4c8c..aa78dda9 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -8,6 +8,7 @@ class ConfigurationTest < ActiveSupport::TestCase @deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, + builder: { "arch" => "amd64" }, env: { "REDIS_URL" => "redis://x/y" }, servers: [ "1.1.1.1", "1.1.1.2" ], volumes: [ "/local/path:/container/path" ] @@ -121,7 +122,7 @@ class ConfigurationTest < ActiveSupport::TestCase test "version from uncommitted context" do 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(: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 }, sshkit: {}, volume_args: [ "--volume", "/local/path:/container/path" ], - builder: {}, + builder: { "arch" => "amd64" }, 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 } } diff --git a/test/fixtures/deploy.erb.yml b/test/fixtures/deploy.erb.yml index a668fb3a..9b9d202d 100644 --- a/test/fixtures/deploy.erb.yml +++ b/test/fixtures/deploy.erb.yml @@ -9,3 +9,5 @@ registry: server: registry.digitalocean.com username: <%= "my-user" %> password: <%= "my-password" %> +builder: + arch: amd64 diff --git a/test/fixtures/deploy_for_dest.yml b/test/fixtures/deploy_for_dest.yml index 96740aec..1784d95f 100644 --- a/test/fixtures/deploy_for_dest.yml +++ b/test/fixtures/deploy_for_dest.yml @@ -4,3 +4,5 @@ registry: server: registry.digitalocean.com username: <%= "my-user" %> password: <%= "my-password" %> +builder: + arch: amd64 diff --git a/test/fixtures/deploy_for_required_dest.yml b/test/fixtures/deploy_for_required_dest.yml index 28438363..1102df95 100644 --- a/test/fixtures/deploy_for_required_dest.yml +++ b/test/fixtures/deploy_for_required_dest.yml @@ -4,4 +4,6 @@ registry: server: registry.digitalocean.com username: <%= "my-user" %> password: <%= "my-password" %> +builder: + arch: amd64 require_destination: true diff --git a/test/fixtures/deploy_primary_web_role_override.yml b/test/fixtures/deploy_primary_web_role_override.yml index 694a9be7..aa52f5ed 100644 --- a/test/fixtures/deploy_primary_web_role_override.yml +++ b/test/fixtures/deploy_primary_web_role_override.yml @@ -17,4 +17,6 @@ registry: server: registry.digitalocean.com username: user password: pw +builder: + arch: amd64 primary_role: web_tokyo diff --git a/test/fixtures/deploy_simple.yml b/test/fixtures/deploy_simple.yml index 520c138e..c143f800 100644 --- a/test/fixtures/deploy_simple.yml +++ b/test/fixtures/deploy_simple.yml @@ -6,3 +6,5 @@ servers: registry: username: user password: pw +builder: + arch: amd64 diff --git a/test/fixtures/deploy_with_accessories.yml b/test/fixtures/deploy_with_accessories.yml index dd78e9f4..29f502ec 100644 --- a/test/fixtures/deploy_with_accessories.yml +++ b/test/fixtures/deploy_with_accessories.yml @@ -10,6 +10,8 @@ servers: registry: username: user password: pw +builder: + arch: amd64 accessories: mysql: diff --git a/test/fixtures/deploy_with_assets.yml b/test/fixtures/deploy_with_assets.yml index 0b6b7cf5..2879d445 100644 --- a/test/fixtures/deploy_with_assets.yml +++ b/test/fixtures/deploy_with_assets.yml @@ -6,4 +6,6 @@ servers: registry: username: user password: pw +builder: + arch: amd64 asset_path: /public/assets diff --git a/test/fixtures/deploy_with_boot_strategy.yml b/test/fixtures/deploy_with_boot_strategy.yml index 7691eb2e..963bb7c3 100644 --- a/test/fixtures/deploy_with_boot_strategy.yml +++ b/test/fixtures/deploy_with_boot_strategy.yml @@ -7,6 +7,8 @@ servers: workers: - "1.1.1.3" - "1.1.1.4" +builder: + arch: amd64 registry: username: user diff --git a/test/fixtures/deploy_with_env_tags.yml b/test/fixtures/deploy_with_env_tags.yml index f0a24760..6822b49d 100644 --- a/test/fixtures/deploy_with_env_tags.yml +++ b/test/fixtures/deploy_with_env_tags.yml @@ -11,6 +11,8 @@ servers: - 1.1.1.4: site1 - 1.2.1.3: site2 - 1.2.1.4: [ site2 experimental ] +builder: + arch: amd64 env: clear: TEST: "root" diff --git a/test/fixtures/deploy_with_extensions.yml b/test/fixtures/deploy_with_extensions.yml index 7d6a9db2..4a5f934a 100644 --- a/test/fixtures/deploy_with_extensions.yml +++ b/test/fixtures/deploy_with_extensions.yml @@ -21,4 +21,6 @@ registry: server: registry.digitalocean.com username: user password: pw +builder: + arch: amd64 primary_role: web_tokyo diff --git a/test/fixtures/deploy_with_low_percentage_boot_strategy.yml b/test/fixtures/deploy_with_low_percentage_boot_strategy.yml index 9b6a3c64..8698b89f 100644 --- a/test/fixtures/deploy_with_low_percentage_boot_strategy.yml +++ b/test/fixtures/deploy_with_low_percentage_boot_strategy.yml @@ -7,6 +7,8 @@ servers: workers: - "1.1.1.3" - "1.1.1.4" +builder: + arch: amd64 registry: username: user diff --git a/test/fixtures/deploy_with_multiple_traefik_roles.yml b/test/fixtures/deploy_with_multiple_traefik_roles.yml index a36a409f..a1270583 100644 --- a/test/fixtures/deploy_with_multiple_traefik_roles.yml +++ b/test/fixtures/deploy_with_multiple_traefik_roles.yml @@ -26,6 +26,8 @@ servers: hosts: - 1.1.1.3 - 1.1.1.4 +builder: + arch: amd64 env: REDIS_URL: redis://x/y registry: diff --git a/test/fixtures/deploy_with_percentage_boot_strategy.yml b/test/fixtures/deploy_with_percentage_boot_strategy.yml index 9b6a3c64..8698b89f 100644 --- a/test/fixtures/deploy_with_percentage_boot_strategy.yml +++ b/test/fixtures/deploy_with_percentage_boot_strategy.yml @@ -7,6 +7,8 @@ servers: workers: - "1.1.1.3" - "1.1.1.4" +builder: + arch: amd64 registry: username: user diff --git a/test/fixtures/deploy_with_remote_builder.yml b/test/fixtures/deploy_with_remote_builder.yml index a67963c2..118142f7 100644 --- a/test/fixtures/deploy_with_remote_builder.yml +++ b/test/fixtures/deploy_with_remote_builder.yml @@ -32,6 +32,8 @@ accessories: port: 6379 directories: - data:/data +builder: + arch: amd64 readiness_delay: 0 diff --git a/test/fixtures/deploy_with_remote_builder_and_custom_ports.yml b/test/fixtures/deploy_with_remote_builder_and_custom_ports.yml index d76100ff..0f409da4 100644 --- a/test/fixtures/deploy_with_remote_builder_and_custom_ports.yml +++ b/test/fixtures/deploy_with_remote_builder_and_custom_ports.yml @@ -32,6 +32,8 @@ accessories: port: 6379 directories: - data:/data +builder: + arch: amd64 readiness_delay: 0 diff --git a/test/fixtures/deploy_with_roles.yml b/test/fixtures/deploy_with_roles.yml index 0e405241..1eb8cc5c 100644 --- a/test/fixtures/deploy_with_roles.yml +++ b/test/fixtures/deploy_with_roles.yml @@ -14,3 +14,5 @@ registry: server: registry.digitalocean.com username: user password: pw +builder: + arch: amd64 diff --git a/test/fixtures/deploy_with_secrets.yml b/test/fixtures/deploy_with_secrets.yml index a03cecbf..35145a3e 100644 --- a/test/fixtures/deploy_with_secrets.yml +++ b/test/fixtures/deploy_with_secrets.yml @@ -9,3 +9,5 @@ registry: env: secret: - PASSWORD +builder: + arch: amd64 diff --git a/test/fixtures/deploy_with_two_roles_one_host.yml b/test/fixtures/deploy_with_two_roles_one_host.yml index cae05469..939ff7e5 100644 --- a/test/fixtures/deploy_with_two_roles_one_host.yml +++ b/test/fixtures/deploy_with_two_roles_one_host.yml @@ -13,3 +13,5 @@ registry: server: registry.digitalocean.com username: user password: pw +builder: + arch: amd64 diff --git a/test/fixtures/deploy_with_uncommon_hostnames.yml b/test/fixtures/deploy_with_uncommon_hostnames.yml index 71e7a601..112f7b39 100644 --- a/test/fixtures/deploy_with_uncommon_hostnames.yml +++ b/test/fixtures/deploy_with_uncommon_hostnames.yml @@ -6,3 +6,5 @@ servers: registry: username: user password: pw +builder: + arch: amd64 diff --git a/test/fixtures/deploy_without_clone.yml b/test/fixtures/deploy_without_clone.yml index abb1224a..c322155f 100644 --- a/test/fixtures/deploy_without_clone.yml +++ b/test/fixtures/deploy_without_clone.yml @@ -36,4 +36,5 @@ accessories: readiness_delay: 0 builder: + arch: amd64 context: "." diff --git a/test/fixtures/deploy_workers_only.yml b/test/fixtures/deploy_workers_only.yml index 75cbbde1..d83adeeb 100644 --- a/test/fixtures/deploy_workers_only.yml +++ b/test/fixtures/deploy_workers_only.yml @@ -10,3 +10,5 @@ primary_role: workers registry: username: user password: pw +builder: + arch: amd64 diff --git a/test/integration/docker/deployer/app/config/deploy.yml b/test/integration/docker/deployer/app/config/deploy.yml index 99bfc297..de701afc 100644 --- a/test/integration/docker/deployer/app/config/deploy.yml +++ b/test/integration/docker/deployer/app/config/deploy.yml @@ -24,6 +24,7 @@ registry: password: root builder: driver: docker + arch: <%= uname_m = `uname -m`; uname_m == "x86_64" ? "amd64" : uname_m %> args: COMMIT_SHA: <%= `git rev-parse HEAD` %> healthcheck: diff --git a/test/integration/docker/deployer/app_with_roles/config/deploy.yml b/test/integration/docker/deployer/app_with_roles/config/deploy.yml index d7e757cc..baedfaf5 100644 --- a/test/integration/docker/deployer/app_with_roles/config/deploy.yml +++ b/test/integration/docker/deployer/app_with_roles/config/deploy.yml @@ -18,6 +18,7 @@ registry: password: root builder: driver: docker + arch: <%= uname_m = `uname -m`; uname_m == "x86_64" ? "amd64" : uname_m %> args: COMMIT_SHA: <%= `git rev-parse HEAD` %> healthcheck: diff --git a/test/integration/main_test.rb b/test/integration/main_test.rb index d0cf024e..a1e81493 100644 --- a/test/integration/main_test.rb +++ b/test/integration/main_test.rb @@ -77,7 +77,7 @@ class MainTest < IntegrationTest assert_equal "app-#{version}", config[:service_with_version] assert_equal [], config[:volume_args] 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({ "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