Skip to content

Commit

Permalink
Merge pull request #972 from kohkimakimoto/dev-provenance-flag
Browse files Browse the repository at this point in the history
Add provenance option
  • Loading branch information
djmb authored Oct 23, 2024
2 parents bf8779c + 92d82dd commit 57d582e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/kamal/commands/builder/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BuilderError < StandardError; end
delegate :argumentize, to: Kamal::Utils
delegate \
:args, :secrets, :dockerfile, :target, :arches, :local_arches, :remote_arches, :remote,
:cache_from, :cache_to, :ssh, :driver, :docker_driver?,
:cache_from, :cache_to, :ssh, :provenance, :driver, :docker_driver?,
to: :builder_config

def clean
Expand Down Expand Up @@ -37,7 +37,7 @@ def inspect_builder
end

def build_options
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_target, *build_ssh ]
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_target, *build_ssh, *builder_provenance ]
end

def build_context
Expand Down Expand Up @@ -97,6 +97,10 @@ def build_ssh
argumentize "--ssh", ssh if ssh.present?
end

def builder_provenance
argumentize "--provenance", provenance unless provenance.nil?
end

def builder_config
config.builder
end
Expand Down
4 changes: 4 additions & 0 deletions lib/kamal/configuration/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def ssh
builder_config["ssh"]
end

def provenance
builder_config["provenance"]
end

def git_clone?
Kamal::Git.used? && builder_config["context"].nil?
end
Expand Down
6 changes: 6 additions & 0 deletions lib/kamal/configuration/docs/builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ builder:
#
# The build driver to use, defaults to `docker-container`:
driver: docker

# Provenance
#
# It is used to configure provenance attestations for the build result.
# The value can also be a boolean to enable or disable provenance attestations.
provenance: mode=max
14 changes: 14 additions & 0 deletions test/commands/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ class CommandsBuilderTest < ActiveSupport::TestCase
builder.push.join(" ")
end

test "push with provenance" do
builder = new_builder_command(builder: { "provenance" => "mode=max" })
assert_equal \
"docker buildx build --push --platform linux/amd64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile --provenance mode=max .",
builder.push.join(" ")
end

test "push with provenance false" do
builder = new_builder_command(builder: { "provenance" => false })
assert_equal \
"docker buildx build --push --platform linux/amd64 --builder kamal-local-docker-container -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile --provenance false .",
builder.push.join(" ")
end

test "mirror count" do
command = new_builder_command
assert_equal "docker info --format '{{index .RegistryConfig.Mirrors 0}}'", command.first_mirror.join(" ")
Expand Down
10 changes: 10 additions & 0 deletions test/configuration/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
assert_equal "default=$SSH_AUTH_SOCK", config.builder.ssh
end

test "provenance" do
assert_nil config.builder.provenance
end

test "setting provenance" do
@deploy[:builder]["provenance"] = "mode=max"

assert_equal "mode=max", config.builder.provenance
end

test "local disabled but no remote set" do
@deploy[:builder]["local"] = false

Expand Down

0 comments on commit 57d582e

Please sign in to comment.