Skip to content

Commit b505750

Browse files
feat: schema addition to specify contianer build network for buildpack
1 parent f6b9cfe commit b505750

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

docs-v2/content/en/schemas/v4beta13.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,11 @@
10311031
"[\"key1=value1\", \"key2=value2\", \"key3={{.ENV_VARIABLE}}\"]"
10321032
]
10331033
},
1034+
"network": {
1035+
"type": "string",
1036+
"description": "network to use for the build.",
1037+
"x-intellij-html-description": "network to use for the build."
1038+
},
10341039
"projectDescriptor": {
10351040
"type": "string",
10361041
"description": "path to the project descriptor file.",
@@ -1066,7 +1071,8 @@
10661071
"clearCache",
10671072
"projectDescriptor",
10681073
"dependencies",
1069-
"volumes"
1074+
"volumes",
1075+
"network"
10701076
],
10711077
"additionalProperties": false,
10721078
"type": "object",

pkg/skaffold/build/gcb/buildpacks.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func (b *Builder) buildpackBuildSpec(artifact *latest.BuildpackArtifact, tag str
4848
args = append(args, "--trust-builder")
4949
}
5050

51+
if artifact.Network != "" {
52+
args = append(args, "--network", artifact.Network)
53+
}
54+
5155
env, err := misc.EvaluateEnv(artifact.Env)
5256
if err != nil {
5357
return cloudbuild.Build{}, fmt.Errorf("unable to evaluate env variables: %w", err)

pkg/skaffold/build/gcb/buildpacks_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ func TestBuildpackBuildSpec(t *testing.T) {
176176
Images: []string{"img"},
177177
},
178178
},
179+
{
180+
description: "build network",
181+
artifact: &latest.BuildpackArtifact{
182+
Builder: "builder",
183+
ProjectDescriptor: "project.toml",
184+
Network: "cloudbuild",
185+
},
186+
expected: cloudbuild.Build{
187+
Steps: []*cloudbuild.BuildStep{{
188+
Name: "pack/image",
189+
Args: []string{"pack", "build", "img", "--builder", "builder", "--network", "cloudbuild"},
190+
}},
191+
Images: []string{"img"},
192+
},
193+
},
179194
}
180195
for _, test := range tests {
181196
testutil.Run(t, test.description, func(t *testutil.T) {

pkg/skaffold/schema/latest/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,9 @@ type BuildpackArtifact struct {
13171317

13181318
// Volumes support mounting host volumes into the container.
13191319
Volumes []*BuildpackVolume `yaml:"volumes,omitempty"`
1320+
1321+
// Network is the network to use for the build.
1322+
Network string `yaml:"network,omitempty"`
13201323
}
13211324

13221325
// BuildpackDependencies *alpha* is used to specify dependencies for an artifact built by buildpacks.

pkg/skaffold/schema/validation/validation_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,32 @@ func TestValidateNetworkMode(t *testing.T) {
556556
},
557557
},
558558
},
559+
{
560+
description: "buildpack custom build network",
561+
shouldErr: false,
562+
artifacts: []*latest.Artifact{
563+
{
564+
ImageName: "image/someimage",
565+
ArtifactType: latest.ArtifactType{
566+
BuildpackArtifact: &latest.BuildpackArtifact{
567+
Network: "cloudbuild",
568+
},
569+
},
570+
},
571+
},
572+
},
573+
{
574+
description: "buildpack build network omitted",
575+
shouldErr: false,
576+
artifacts: []*latest.Artifact{
577+
{
578+
ImageName: "image/someimage",
579+
ArtifactType: latest.ArtifactType{
580+
BuildpackArtifact: &latest.BuildpackArtifact{},
581+
},
582+
},
583+
},
584+
},
559585
}
560586
for _, test := range tests {
561587
testutil.Run(t, test.description, func(t *testutil.T) {

0 commit comments

Comments
 (0)