Skip to content

Commit

Permalink
fix: ensure project descriptor in Pack Build (#7884)
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Parr authored Oct 4, 2022
1 parent 6c44ab4 commit c50ca8a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 13 deletions.
59 changes: 59 additions & 0 deletions pkg/skaffold/build/buildpacks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

pack "github.com/buildpacks/pack/pkg/client"
packcfg "github.com/buildpacks/pack/pkg/image"
packtypes "github.com/buildpacks/pack/pkg/project/types"
"github.com/docker/docker/api/types"
"github.com/google/go-cmp/cmp"

Expand Down Expand Up @@ -194,6 +195,64 @@ value = "VALUE2"
Image: "img:latest",
},
},
{
description: "file exclusion in project.toml",
artifact: withTrustedBuilder(withBuildpacks([]string{"my/buildpack", "my/otherBuildpack"}, buildpacksArtifact("my/otherBuilder", "my/otherRun"))),
tag: "img:tag",
mode: config.RunModes.Build,
api: &testutil.FakeAPIClient{},
resolver: mockArtifactResolver{},
files: map[string]string{
"project.toml": `[build]
exclude = [
"exclude_me"
]
`,
},
expectedOptions: &pack.BuildOptions{
AppPath: ".",
Builder: "my/otherBuilder",
RunImage: "my/otherRun",
Buildpacks: []string{"my/buildpack", "my/otherBuildpack"},
Image: "img:latest",
PullPolicy: packcfg.PullNever,
Env: nonDebugModeArgs,
ProjectDescriptor: packtypes.Descriptor{
Build: packtypes.Build{
Exclude: []string{"exclude_me"},
},
},
},
},
{
description: "file inclusion in project.toml",
artifact: withTrustedBuilder(withBuildpacks([]string{"my/buildpack", "my/otherBuildpack"}, buildpacksArtifact("my/otherBuilder", "my/otherRun"))),
tag: "img:tag",
mode: config.RunModes.Build,
api: &testutil.FakeAPIClient{},
resolver: mockArtifactResolver{},
files: map[string]string{
"project.toml": `[build]
include = [
"include_me"
]
`,
},
expectedOptions: &pack.BuildOptions{
AppPath: ".",
Builder: "my/otherBuilder",
RunImage: "my/otherRun",
Buildpacks: []string{"my/buildpack", "my/otherBuildpack"},
Image: "img:latest",
PullPolicy: packcfg.PullNever,
Env: nonDebugModeArgs,
ProjectDescriptor: packtypes.Descriptor{
Build: packtypes.Build{
Include: []string{"include_me"},
},
},
},
},
{
description: "dev mode",
artifact: withSync(&latest.Sync{Auto: util.BoolPtr(true)}, buildpacksArtifact("another/builder", "another/run")),
Expand Down
27 changes: 14 additions & 13 deletions pkg/skaffold/build/buildpacks/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ func (b *Builder) build(ctx context.Context, out io.Writer, a *latest.Artifact,
}
latest := parsed.BaseName + ":latest"

// Evaluate Env Vars.
// Evaluate Env Vars replacing those in project.toml.
env, err := env(a, b.mode, projectDescriptor)
if err != nil {
return "", fmt.Errorf("unable to evaluate env variables: %w", err)
}
projectDescriptor.Build.Env = nil

cc, err := containerConfig(artifact)
if err != nil {
Expand All @@ -94,22 +95,22 @@ func (b *Builder) build(ctx context.Context, out io.Writer, a *latest.Artifact,
}
}
}
projectDescriptor.Build.Buildpacks = nil

builderImage, runImage, pullPolicy := resolveDependencyImages(artifact, b.artifacts, a.Dependencies, b.pushImages)

if err := runPackBuildFunc(ctx, out, b.localDocker, pack.BuildOptions{
AppPath: workspace,
Builder: builderImage,
RunImage: runImage,
Buildpacks: buildpacks,
Env: env,
Image: latest,
PullPolicy: pullPolicy,
TrustBuilder: func(_ string) bool { return artifact.TrustBuilder },
ClearCache: clearCache,
ContainerConfig: cc,
// TODO(dgageot): Support project.toml include/exclude.
// FileFilter: func(string) bool { return true },
AppPath: workspace,
Builder: builderImage,
RunImage: runImage,
Buildpacks: buildpacks,
Env: env,
Image: latest,
PullPolicy: pullPolicy,
TrustBuilder: func(_ string) bool { return artifact.TrustBuilder },
ClearCache: clearCache,
ContainerConfig: cc,
ProjectDescriptor: projectDescriptor,
}); err != nil {
return "", err
}
Expand Down

0 comments on commit c50ca8a

Please sign in to comment.