Skip to content

Commit 0566431

Browse files
committed
only use attestation when building image outside the development inner loop
when building a image, by default attestation are generated and modify the image ID which trigger a container recreation on up, run command even if there isn't any changes on the image content itself Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
1 parent 4f6cc2a commit 0566431

5 files changed

Lines changed: 50 additions & 24 deletions

File tree

cmd/compose/build.go

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ import (
3535

3636
type buildOptions struct {
3737
*ProjectOptions
38-
quiet bool
39-
pull bool
40-
push bool
41-
args []string
42-
noCache bool
43-
memory cliopts.MemBytes
44-
ssh string
45-
builder string
46-
deps bool
47-
print bool
48-
check bool
38+
quiet bool
39+
pull bool
40+
push bool
41+
args []string
42+
noCache bool
43+
memory cliopts.MemBytes
44+
ssh string
45+
builder string
46+
deps bool
47+
print bool
48+
check bool
49+
provenance string
4950
}
5051

5152
func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions, error) {
@@ -69,20 +70,27 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,
6970
if uiMode == ui.ModeJSON {
7071
uiMode = "rawjson"
7172
}
73+
var provenance *string
74+
// empty when set by up, run or create functions and "none" when set by the user from the build command
75+
if opts.provenance != "" && opts.provenance != "none" {
76+
provenance = &opts.provenance
77+
}
78+
7279
return api.BuildOptions{
73-
Pull: opts.pull,
74-
Push: opts.push,
75-
Progress: uiMode,
76-
Args: types.NewMappingWithEquals(opts.args),
77-
NoCache: opts.noCache,
78-
Quiet: opts.quiet,
79-
Services: services,
80-
Deps: opts.deps,
81-
Memory: int64(opts.memory),
82-
Print: opts.print,
83-
Check: opts.check,
84-
SSHs: SSHKeys,
85-
Builder: builderName,
80+
Pull: opts.pull,
81+
Push: opts.push,
82+
Progress: uiMode,
83+
Args: types.NewMappingWithEquals(opts.args),
84+
NoCache: opts.noCache,
85+
Quiet: opts.quiet,
86+
Services: services,
87+
Deps: opts.deps,
88+
Memory: int64(opts.memory),
89+
Print: opts.print,
90+
Check: opts.check,
91+
SSHs: SSHKeys,
92+
Builder: builderName,
93+
Provenance: provenance,
8694
}, nil
8795
}
8896

@@ -123,6 +131,7 @@ func buildCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
123131
flags.StringVar(&opts.ssh, "ssh", "", "Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent)")
124132
flags.StringVar(&opts.builder, "builder", "", "Set builder to use")
125133
flags.BoolVar(&opts.deps, "with-dependencies", false, "Also build dependencies (transitively)")
134+
flags.StringVar(&opts.provenance, "provenance", "min", "Set provenance mode (none|min|max)")
126135

127136
flags.Bool("parallel", true, "Build images in parallel. DEPRECATED")
128137
flags.MarkHidden("parallel") //nolint:errcheck

docs/reference/compose_build.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ run `docker compose build` to rebuild it.
2222
| `-m`, `--memory` | `bytes` | `0` | Set memory limit for the build container. Not supported by BuildKit. |
2323
| `--no-cache` | `bool` | | Do not use cache when building the image |
2424
| `--print` | `bool` | | Print equivalent bake file |
25+
| `--provenance` | `string` | `max` | Set provenance mode (none\|min\|max) |
2526
| `--pull` | `bool` | | Always attempt to pull a newer version of the image |
2627
| `--push` | `bool` | | Push service images |
2728
| `-q`, `--quiet` | `bool` | | Don't print anything to STDOUT |

docs/reference/docker_compose_build.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ options:
126126
experimentalcli: false
127127
kubernetes: false
128128
swarm: false
129+
- option: provenance
130+
value_type: string
131+
default_value: max
132+
description: Set provenance mode (none|min|max)
133+
deprecated: false
134+
hidden: false
135+
experimental: false
136+
experimentalcli: false
137+
kubernetes: false
138+
swarm: false
129139
- option: pull
130140
value_type: bool
131141
default_value: "false"

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ type BuildOptions struct {
159159
Print bool
160160
// Check let builder validate build configuration
161161
Check bool
162+
// Provenance
163+
Provenance *string
162164
}
163165

164166
// Apply mutates project according to build options

pkg/compose/build.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
481481
return build.Options{}, err
482482
}
483483

484+
attests := map[string]*string{}
485+
attests["provenance"] = options.Provenance
486+
484487
return build.Options{
485488
Inputs: build.Inputs{
486489
ContextPath: service.Build.Context,
@@ -504,6 +507,7 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
504507
Session: sessionConfig,
505508
Allow: allow,
506509
SourcePolicy: sp,
510+
Attests: attests,
507511
}, nil
508512
}
509513

0 commit comments

Comments
 (0)