Skip to content

Commit 57d582e

Browse files
authored
Merge pull request #972 from kohkimakimoto/dev-provenance-flag
Add provenance option
2 parents bf8779c + 92d82dd commit 57d582e

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

lib/kamal/commands/builder/base.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class BuilderError < StandardError; end
66
delegate :argumentize, to: Kamal::Utils
77
delegate \
88
:args, :secrets, :dockerfile, :target, :arches, :local_arches, :remote_arches, :remote,
9-
:cache_from, :cache_to, :ssh, :driver, :docker_driver?,
9+
:cache_from, :cache_to, :ssh, :provenance, :driver, :docker_driver?,
1010
to: :builder_config
1111

1212
def clean
@@ -37,7 +37,7 @@ def inspect_builder
3737
end
3838

3939
def build_options
40-
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_target, *build_ssh ]
40+
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_target, *build_ssh, *builder_provenance ]
4141
end
4242

4343
def build_context
@@ -97,6 +97,10 @@ def build_ssh
9797
argumentize "--ssh", ssh if ssh.present?
9898
end
9999

100+
def builder_provenance
101+
argumentize "--provenance", provenance unless provenance.nil?
102+
end
103+
100104
def builder_config
101105
config.builder
102106
end

lib/kamal/configuration/builder.rb

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ def ssh
111111
builder_config["ssh"]
112112
end
113113

114+
def provenance
115+
builder_config["provenance"]
116+
end
117+
114118
def git_clone?
115119
Kamal::Git.used? && builder_config["context"].nil?
116120
end

lib/kamal/configuration/docs/builder.yml

+6
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ builder:
102102
#
103103
# The build driver to use, defaults to `docker-container`:
104104
driver: docker
105+
106+
# Provenance
107+
#
108+
# It is used to configure provenance attestations for the build result.
109+
# The value can also be a boolean to enable or disable provenance attestations.
110+
provenance: mode=max

test/commands/builder_test.rb

+14
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ class CommandsBuilderTest < ActiveSupport::TestCase
144144
builder.push.join(" ")
145145
end
146146

147+
test "push with provenance" do
148+
builder = new_builder_command(builder: { "provenance" => "mode=max" })
149+
assert_equal \
150+
"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 .",
151+
builder.push.join(" ")
152+
end
153+
154+
test "push with provenance false" do
155+
builder = new_builder_command(builder: { "provenance" => false })
156+
assert_equal \
157+
"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 .",
158+
builder.push.join(" ")
159+
end
160+
147161
test "mirror count" do
148162
command = new_builder_command
149163
assert_equal "docker info --format '{{index .RegistryConfig.Mirrors 0}}'", command.first_mirror.join(" ")

test/configuration/builder_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
134134
assert_equal "default=$SSH_AUTH_SOCK", config.builder.ssh
135135
end
136136

137+
test "provenance" do
138+
assert_nil config.builder.provenance
139+
end
140+
141+
test "setting provenance" do
142+
@deploy[:builder]["provenance"] = "mode=max"
143+
144+
assert_equal "mode=max", config.builder.provenance
145+
end
146+
137147
test "local disabled but no remote set" do
138148
@deploy[:builder]["local"] = false
139149

0 commit comments

Comments
 (0)