Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[buildpacks] Support trusted builders #4273

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/content/en/schemas/v2beta5.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,20 @@
"type": "string",
"description": "overrides the stack's default run image.",
"x-intellij-html-description": "overrides the stack's default run image."
},
"trustBuilder": {
"type": "boolean",
"description": "indicates that the builder should be trusted.",
"x-intellij-html-description": "indicates that the builder should be trusted.",
"default": "false"
}
},
"preferredOrder": [
"builder",
"runImage",
"env",
"buildpacks",
"trustBuilder",
"dependencies"
],
"additionalProperties": false,
Expand Down
19 changes: 12 additions & 7 deletions pkg/skaffold/build/buildpacks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ func TestBuild(t *testing.T) {
},
{
description: "success with buildpacks",
artifact: withBuildpacks([]string{"my/buildpack", "my/otherBuildpack"}, buildpacksArtifact("my/otherBuilder", "my/otherRun")),
artifact: withTrustedBuilder(withBuildpacks([]string{"my/buildpack", "my/otherBuildpack"}, buildpacksArtifact("my/otherBuilder", "my/otherRun"))),
tag: "img:tag",
api: &testutil.FakeAPIClient{},
expectedOptions: &pack.BuildOptions{
AppPath: ".",
Builder: "my/otherBuilder",
RunImage: "my/otherRun",
Buildpacks: []string{"my/buildpack", "my/otherBuildpack"},
Env: map[string]string{},
Image: "img:latest",
AppPath: ".",
Builder: "my/otherBuilder",
RunImage: "my/otherRun",
Buildpacks: []string{"my/buildpack", "my/otherBuildpack"},
TrustBuilder: true,
Env: map[string]string{},
Image: "img:latest",
},
},
{
Expand Down Expand Up @@ -257,6 +258,10 @@ func withSync(sync *latest.Sync, artifact *latest.Artifact) *latest.Artifact {
return artifact
}

func withTrustedBuilder(artifact *latest.Artifact) *latest.Artifact {
artifact.BuildpackArtifact.TrustBuilder = true
return artifact
}
func withBuildpacks(buildpacks []string, artifact *latest.Artifact) *latest.Artifact {
artifact.BuildpackArtifact.Buildpacks = buildpacks
return artifact
Expand Down
15 changes: 8 additions & 7 deletions pkg/skaffold/build/buildpacks/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ func (b *Builder) build(ctx context.Context, out io.Writer, a *latest.Artifact,
alreadyPulled := images.AreAlreadyPulled(artifact.Builder, artifact.RunImage)

if err := runPackBuildFunc(ctx, out, b.localDocker, pack.BuildOptions{
AppPath: workspace,
Builder: artifact.Builder,
RunImage: artifact.RunImage,
Buildpacks: buildpacks,
Env: env,
Image: latest,
NoPull: alreadyPulled,
AppPath: workspace,
Builder: artifact.Builder,
RunImage: artifact.RunImage,
Buildpacks: buildpacks,
Env: env,
Image: latest,
NoPull: alreadyPulled,
TrustBuilder: artifact.TrustBuilder,
// TODO(dgageot): Support project.toml include/exclude.
// FileFilter: func(string) bool { return true },
}); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/build/gcb/buildpacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (b *Builder) buildpackBuildSpec(artifact *latest.BuildpackArtifact, tag str
args = append(args, "--buildpack", buildpack)
}

if artifact.TrustBuilder {
args = append(args, "--trust-builder")
}

env, err := misc.EvaluateEnv(artifact.Env)
if err != nil {
return cloudbuild.Build{}, fmt.Errorf("unable to evaluate env variables: %w", err)
Expand Down
14 changes: 14 additions & 0 deletions pkg/skaffold/build/gcb/buildpacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ func TestBuildpackBuildSpec(t *testing.T) {
Images: []string{"img"},
},
},
{
description: "trusted builder",
artifact: &latest.BuildpackArtifact{
Builder: "builder",
TrustBuilder: true,
},
expected: cloudbuild.Build{
Steps: []*cloudbuild.BuildStep{{
Name: "pack/image",
Args: []string{"pack", "build", "img", "--builder", "builder", "--trust-builder"},
}},
Images: []string{"img"},
},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,9 @@ type BuildpackArtifact struct {
// Order matters.
Buildpacks []string `yaml:"buildpacks,omitempty"`

// TrustBuilder indicates that the builder should be trusted.
TrustBuilder bool `yaml:"trustBuilder,omitempty"`

// Dependencies are the file dependencies that skaffold should watch for both rebuilding and file syncing for this artifact.
Dependencies *BuildpackDependencies `yaml:"dependencies,omitempty"`
}
Expand Down