Skip to content

Commit

Permalink
Support specific buildpacks for buildpack artifact (#3584)
Browse files Browse the repository at this point in the history
* Support specific buildpacks for buildpack artifact

* Add test case for specific buildpacks support

Co-authored-by: David Gageot <david@gageot.net>
  • Loading branch information
kissmikijr and dgageot committed Jan 27, 2020
1 parent 4196479 commit b494348
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
10 changes: 10 additions & 0 deletions docs/content/en/schemas/v2alpha3.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,15 @@
"description": "builder image used.",
"x-intellij-html-description": "builder image used."
},
"buildpacks": {
"items": {
"type": "string"
},
"type": "array",
"description": "a list of strings, where each string is a specific buildpack to use with the builder. If you specify buildpacks the builder image automatic detection will be ignored. These buildpacks will be used to build the Image from your source code. Order matters.",
"x-intellij-html-description": "a list of strings, where each string is a specific buildpack to use with the builder. If you specify buildpacks the builder image automatic detection will be ignored. These buildpacks will be used to build the Image from your source code. Order matters.",
"default": "[]"
},
"dependencies": {
"$ref": "#/definitions/BuildpackDependencies",
"description": "file dependencies that skaffold should watch for both rebuilding and file syncing for this artifact.",
Expand Down Expand Up @@ -521,6 +530,7 @@
"builder",
"runImage",
"env",
"buildpacks",
"dependencies"
],
"additionalProperties": false,
Expand Down
19 changes: 19 additions & 0 deletions pkg/skaffold/build/buildpacks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ func TestBuild(t *testing.T) {
Image: "img:latest",
},
},
{
description: "success with buildpacks",
artifact: 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",
},
},
{
description: "dev mode",
artifact: withSync(&latest.Sync{Infer: []string{"**/*"}}, buildpacksArtifact("another/builder", "another/run")),
Expand Down Expand Up @@ -164,3 +178,8 @@ func withSync(sync *latest.Sync, artifact *latest.Artifact) *latest.Artifact {
artifact.Sync = sync
return artifact
}

func withBuildpacks(buildpacks []string, artifact *latest.Artifact) *latest.Artifact {
artifact.BuildpackArtifact.Buildpacks = buildpacks
return artifact
}
13 changes: 7 additions & 6 deletions pkg/skaffold/build/buildpacks/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ 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, pack.BuildOptions{
AppPath: workspace,
Builder: artifact.Builder,
RunImage: artifact.RunImage,
Env: envMap(env),
Image: latest,
NoPull: alreadyPulled,
AppPath: workspace,
Builder: artifact.Builder,
RunImage: artifact.RunImage,
Buildpacks: artifact.Buildpacks,
Env: envMap(env),
Image: latest,
NoPull: alreadyPulled,
}); err != nil {
return "", err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ type BuildpackArtifact struct {
// For example: `["key1=value1", "key2=value2", "key3={{.ENV_VARIABLE}}"]`.
Env []string `yaml:"env,omitempty"`

// Buildpacks is a list of strings, where each string is a specific buildpack to use with the builder.
// If you specify buildpacks the builder image automatic detection will be ignored. These buildpacks will be used to build the Image from your source code.
// Order matters.
Buildpacks []string `yaml:"buildpacks,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

0 comments on commit b494348

Please sign in to comment.