Skip to content

Commit d3213bd

Browse files
committed
[Custom] Use $IMAGE instead of $IMAGES
Fixes #3081 Signed-off-by: David Gageot <[email protected]>
1 parent a0bfe56 commit d3213bd

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

docs/content/en/docs/pipeline-stages/builders.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ Skaffold will pass in the following environment variables to the custom build sc
265265

266266
| Environment Variable | Description | Expectation |
267267
| ------------- |-------------| -----|
268-
| $IMAGES | An array of fully qualified image names, separated by spaces. For example, "gcr.io/image1 gcr.io/image2" | The custom build script is expected to build an image and tag it with each image name in $IMAGES. Each image should also be pushed if `$PUSH_IMAGE=true`. |
269-
| $PUSH_IMAGE | Set to true if each image in `$IMAGES` is expected to exist in a remote registry. Set to false if each image in `$IMAGES` is expected to exist locally. | The custom build script will push each image in `$IMAGES` if `$PUSH_IMAGE=true` |
268+
| $IMAGE | The fully qualified image name. For example, "gcr.io/image1:tag" | The custom build script is expected to build this image and tag it with the name provided in $IMAGE. The image should also be pushed if `$PUSH_IMAGE=true`. |
269+
| $PUSH_IMAGE | Set to true if the image in `$IMAGE` is expected to exist in a remote registry. Set to false if the image is expected to exist locally. | The custom build script will push the image `$IMAGE` if `$PUSH_IMAGE=true` |
270270
| $BUILD_CONTEXT | An absolute path to the directory this artifact is meant to be built from. Specified by artifact `context` in the skaffold.yaml. | None. |
271271
| Local environment variables | The current state of the local environment (e.g. `$HOST`, `$PATH)`. Determined by the golang [os.Environ](https://golang.org/pkg/os#Environ) function.| None. |
272272

273273
As described above, the custom build script is expected to:
274274

275-
1. Build and tag each image in `$IMAGES`
276-
2. Push each image in `$IMAGES` if `$PUSH_IMAGE=true`
275+
1. Build and tag the `$IMAGE` image
276+
2. Push the image if `$PUSH_IMAGE=true`
277277

278278
Once the build script has finished executing, skaffold will try to obtain the digest of the newly built image from a remote registry (if `$PUSH_IMAGE=true`) or the local daemon (if `$PUSH_IMAGE=false`).
279279
If skaffold fails to obtain the digest, it will error out.

pkg/skaffold/build/custom/custom.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ func (b *ArtifactBuilder) retrieveCmd(out io.Writer, a *latest.Artifact, tag str
9090
}
9191

9292
func (b *ArtifactBuilder) retrieveEnv(a *latest.Artifact, tag string) ([]string, error) {
93-
images := strings.Join([]string{tag}, " ")
9493
buildContext, err := buildContext(a.Workspace)
9594
if err != nil {
9695
return nil, errors.Wrap(err, "getting absolute path for artifact build context")
9796
}
9897

9998
envs := []string{
100-
fmt.Sprintf("%s=%s", constants.Images, images),
99+
fmt.Sprintf("%s=%s", constants.Image, tag),
100+
fmt.Sprintf("%s=%s", constants.DeprecatedImages, tag),
101101
fmt.Sprintf("%s=%t", constants.PushImage, b.pushImages),
102102
fmt.Sprintf("%s=%s", constants.BuildContext, buildContext),
103103
}

pkg/skaffold/build/custom/custom_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,24 @@ func TestRetrieveEnv(t *testing.T) {
4242
tag: "gcr.io/image/tag:mytag",
4343
environ: nil,
4444
buildContext: "/some/path",
45-
expected: []string{"IMAGES=gcr.io/image/tag:mytag", "PUSH_IMAGE=false", "BUILD_CONTEXT=/some/path"},
45+
expected: []string{"IMAGE=gcr.io/image/tag:mytag", "IMAGES=gcr.io/image/tag:mytag", "PUSH_IMAGE=false", "BUILD_CONTEXT=/some/path"},
4646
}, {
4747
description: "make sure environ is correctly applied",
4848
tag: "gcr.io/image/tag:anothertag",
4949
environ: []string{"PATH=/path", "HOME=/root"},
5050
buildContext: "/some/path",
51-
expected: []string{"IMAGES=gcr.io/image/tag:anothertag", "PUSH_IMAGE=false", "BUILD_CONTEXT=/some/path", "PATH=/path", "HOME=/root"},
51+
expected: []string{"IMAGE=gcr.io/image/tag:anothertag", "IMAGES=gcr.io/image/tag:anothertag", "PUSH_IMAGE=false", "BUILD_CONTEXT=/some/path", "PATH=/path", "HOME=/root"},
5252
}, {
5353
description: "push image is true",
5454
tag: "gcr.io/image/push:tag",
5555
pushImages: true,
56-
expected: []string{"IMAGES=gcr.io/image/push:tag", "PUSH_IMAGE=true", "BUILD_CONTEXT="},
56+
expected: []string{"IMAGE=gcr.io/image/push:tag", "IMAGES=gcr.io/image/push:tag", "PUSH_IMAGE=true", "BUILD_CONTEXT="},
5757
}, {
5858
description: "add additional env",
5959
tag: "gcr.io/image/push:tag",
6060
pushImages: true,
6161
additionalEnv: []string{"KUBECONTEXT=mycluster"},
62-
expected: []string{"IMAGES=gcr.io/image/push:tag", "PUSH_IMAGE=true", "BUILD_CONTEXT=", "KUBECONTEXT=mycluster"},
62+
expected: []string{"IMAGE=gcr.io/image/push:tag", "IMAGES=gcr.io/image/push:tag", "PUSH_IMAGE=true", "BUILD_CONTEXT=", "KUBECONTEXT=mycluster"},
6363
},
6464
}
6565
for _, test := range tests {
@@ -94,7 +94,7 @@ func TestRetrieveCmd(t *testing.T) {
9494
},
9595
},
9696
tag: "image:tag",
97-
expected: expectedCmd("./build.sh", "workspace", nil, []string{"IMAGES=image:tag", "PUSH_IMAGE=false", "BUILD_CONTEXT=workspace"}),
97+
expected: expectedCmd("./build.sh", "workspace", nil, []string{"IMAGE=image:tag", "IMAGES=image:tag", "PUSH_IMAGE=false", "BUILD_CONTEXT=workspace"}),
9898
}, {
9999
description: "buildcommand with multiple args",
100100
artifact: &latest.Artifact{
@@ -105,7 +105,7 @@ func TestRetrieveCmd(t *testing.T) {
105105
},
106106
},
107107
tag: "image:tag",
108-
expected: expectedCmd("./build.sh", "", []string{"--flag", "--anotherflag"}, []string{"IMAGES=image:tag", "PUSH_IMAGE=false", "BUILD_CONTEXT="}),
108+
expected: expectedCmd("./build.sh", "", []string{"--flag", "--anotherflag"}, []string{"IMAGE=image:tag", "IMAGES=image:tag", "PUSH_IMAGE=false", "BUILD_CONTEXT="}),
109109
},
110110
}
111111
for _, test := range tests {

pkg/skaffold/constants/constants.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ var (
8080
)
8181

8282
var (
83-
// Images is an environment variable key, whose value is an array of fully qualified image names passed in to a custom build script.
84-
Images = "IMAGES"
83+
// DeprecatedImages is an environment variable key, whose value is an array of fully qualified image names passed in to a custom build script.
84+
DeprecatedImages = "IMAGES"
85+
86+
// Image is an environment variable key, whose value is the fully qualified image names passed in to a custom build script.
87+
Image = "IMAGE"
8588

8689
// PushImage lets the custom build script know if the image is expected to be pushed to a remote registry
8790
PushImage = "PUSH_IMAGE"

0 commit comments

Comments
 (0)