-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #944 from sm43/buildrun-image
Adds support for specifying image labels and annotation in buildrun
- Loading branch information
Showing
5 changed files
with
222 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,90 @@ var _ = Describe("GenerateTaskrun", func() { | |
Expect(err.Error()).To(Equal("error(s) occurred merging environment variables into BuildStrategy \"buildah\" steps: [environment variable \"MY_VAR_1\" already exists, environment variable \"MY_VAR_2\" already exists]")) | ||
}) | ||
}) | ||
|
||
Context("when only BuildRun has output image labels and annotation defined ", func() { | ||
BeforeEach(func() { | ||
build, err = ctl.LoadBuildYAML([]byte(test.BuildahBuildWithOutput)) | ||
Expect(err).To(BeNil()) | ||
|
||
buildRun, err = ctl.LoadBuildRunFromBytes([]byte(test.BuildahBuildRunWithOutputImageLabelsAndAnnotations)) | ||
Expect(err).To(BeNil()) | ||
|
||
buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) | ||
Expect(err).To(BeNil()) | ||
buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" | ||
|
||
expectedCommandOrArg = []string{ | ||
"bud", "--tag=$(params.shp-output-image)", fmt.Sprintf("--file=$(inputs.params.%s)", "DOCKERFILE"), "$(params.shp-source-context)", | ||
} | ||
|
||
JustBeforeEach(func() { | ||
got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}) | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
It("should contain a step to mutate the image with labels and annotations merged from build and buildrun", func() { | ||
Expect(got.Steps[3].Name).To(Equal("mutate-image")) | ||
Expect(got.Steps[3].Command[0]).To(Equal("/ko-app/mutate-image")) | ||
Expect(got.Steps[3].Args).To(Equal([]string{ | ||
"--image", | ||
"$(params.shp-output-image)", | ||
"--result-file-image-digest", | ||
"$(results.shp-image-digest.path)", | ||
"result-file-image-size", | ||
"$(results.shp-image-size.path)", | ||
"--annotation", | ||
"org.opencontainers.owner=my-company", | ||
"--label", | ||
"[email protected]", | ||
"foo=bar", | ||
})) | ||
}) | ||
}) | ||
}) | ||
|
||
Context("when Build and BuildRun both have output image labels and annotation defined ", func() { | ||
BeforeEach(func() { | ||
build, err = ctl.LoadBuildYAML([]byte(test.BuildahBuildWithAnnotationAndLabel)) | ||
Expect(err).To(BeNil()) | ||
|
||
buildRun, err = ctl.LoadBuildRunFromBytes([]byte(test.BuildahBuildRunWithOutputImageLabelsAndAnnotations)) | ||
Expect(err).To(BeNil()) | ||
|
||
buildStrategy, err = ctl.LoadBuildStrategyFromBytes([]byte(test.MinimalBuildahBuildStrategy)) | ||
Expect(err).To(BeNil()) | ||
buildStrategy.Spec.BuildSteps[0].ImagePullPolicy = "Always" | ||
|
||
expectedCommandOrArg = []string{ | ||
"bud", "--tag=$(params.shp-output-image)", fmt.Sprintf("--file=$(inputs.params.%s)", "DOCKERFILE"), "$(params.shp-source-context)", | ||
} | ||
|
||
JustBeforeEach(func() { | ||
got, err = resources.GenerateTaskSpec(config.NewDefaultConfig(), build, buildRun, buildStrategy.Spec.BuildSteps, []buildv1alpha1.Parameter{}) | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
It("should contain a step to mutate the image with labels and annotations merged from build and buildrun", func() { | ||
Expect(got.Steps[3].Name).To(Equal("mutate-image")) | ||
Expect(got.Steps[3].Command[0]).To(Equal("/ko-app/mutate-image")) | ||
Expect(got.Steps[3].Args).To(Equal([]string{ | ||
"--image", | ||
"$(params.shp-output-image)", | ||
"--result-file-image-digest", | ||
"$(results.shp-image-digest.path)", | ||
"result-file-image-size", | ||
"$(results.shp-image-size.path)", | ||
"--annotation", | ||
"org.opencontainers.owner=my-company", | ||
"org.opencontainers.image.url=https://my-company.com/images", | ||
"--label", | ||
"[email protected]", | ||
"foo=bar", | ||
})) | ||
}) | ||
}) | ||
}) | ||
|
||
}) | ||
|
||
Describe("Generate the TaskRun", func() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,28 @@ spec: | |
fieldPath: "my-fieldpath" | ||
` | ||
|
||
// BuildahBuildRunWithOutputImageLabelsAndAnnotations defines a BuildRun | ||
// with a output image labels and annotation | ||
const BuildahBuildRunWithOutputImageLabelsAndAnnotations = ` | ||
apiVersion: shipwright.io/v1alpha1 | ||
kind: BuildRun | ||
metadata: | ||
name: buildah-run | ||
namespace: build-test | ||
spec: | ||
buildRef: | ||
name: buildah | ||
serviceAccount: | ||
name: buildpacks-v3-serviceaccount | ||
output: | ||
image: image-registry.openshift-image-registry.svc:5000/example/buildpacks-app-v2 | ||
labels: | ||
"maintainer": "[email protected]" | ||
"foo": "bar" | ||
annotations: | ||
"org.opencontainers.owner": "my-company" | ||
` | ||
|
||
// MinimalBuildahBuildRun defines a simple | ||
// BuildRun with a referenced Build | ||
const MinimalBuildahBuildRun = ` | ||
|