diff --git a/pkg/apis/build/v1alpha1/build_source.go b/pkg/apis/build/v1alpha1/build_source.go index 2e946bc960..53f9cadca0 100644 --- a/pkg/apis/build/v1alpha1/build_source.go +++ b/pkg/apis/build/v1alpha1/build_source.go @@ -11,9 +11,12 @@ import ( // BuildSourceType enumerates build source type names. type BuildSourceType string -// LocalCopy defines a source type that waits for user input, as in a local copy into a POD. +// LocalCopy source type when the user will upload local content. const LocalCopy BuildSourceType = "LocalCopy" +// HTTP defines the remote artifact default source type. +const HTTP BuildSourceType = "HTTP" + // BuildSource remote artifact definition, also known as "sources". Simple "name" and "url" pairs, // initially without "credentials" (authentication) support yet. type BuildSource struct { diff --git a/pkg/reconciler/buildrun/resources/sources.go b/pkg/reconciler/buildrun/resources/sources.go index eb70a69fb2..c2b69d4167 100644 --- a/pkg/reconciler/buildrun/resources/sources.go +++ b/pkg/reconciler/buildrun/resources/sources.go @@ -55,11 +55,13 @@ func AmendTaskSpecWithSources( } } - // create the step for spec.sources, this will eventually change into different steps depending on the type of the source if build.Spec.Sources != nil { + // inspecting .spec.sources looking for http typed sources to generate the TaskSpec items in + // order to handle external artifacts for _, source := range *build.Spec.Sources { - // today, we only have HTTP sources - sources.AppendHTTPStep(cfg, taskSpec, source) + if source.Type == buildv1alpha1.HTTP { + sources.AppendHTTPStep(cfg, taskSpec, source) + } } } } diff --git a/pkg/reconciler/buildrun/resources/sources/http.go b/pkg/reconciler/buildrun/resources/sources/http.go index 86acd4e10a..2ecc075917 100644 --- a/pkg/reconciler/buildrun/resources/sources/http.go +++ b/pkg/reconciler/buildrun/resources/sources/http.go @@ -13,6 +13,9 @@ import ( corev1 "k8s.io/api/core/v1" ) +// RemoteArtifactsContainerName name for the container dealing with remote artifacts download. +const RemoteArtifactsContainerName = "sources-http" + // AppendHTTPStep appends the step for a HTTP source to the TaskSpec func AppendHTTPStep( cfg *config.Config, @@ -26,7 +29,7 @@ func AppendHTTPStep( } else { httpStep := tektonv1beta1.Step{ Container: corev1.Container{ - Name: "sources-http", + Name: RemoteArtifactsContainerName, Image: cfg.RemoteArtifactsContainerImage, WorkingDir: fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), Command: []string{ @@ -48,10 +51,9 @@ func AppendHTTPStep( func findExistingHTTPSourcesStep(taskSpec *tektonv1beta1.TaskSpec) *tektonv1beta1.Step { for _, candidateStep := range taskSpec.Steps { - if candidateStep.Name == "sources-http" { + if candidateStep.Name == RemoteArtifactsContainerName { return &candidateStep } } - return nil } diff --git a/pkg/reconciler/buildrun/resources/sources/http_test.go b/pkg/reconciler/buildrun/resources/sources/http_test.go index fb0150ba7d..26885d4a95 100644 --- a/pkg/reconciler/buildrun/resources/sources/http_test.go +++ b/pkg/reconciler/buildrun/resources/sources/http_test.go @@ -35,7 +35,7 @@ var _ = Describe("HTTP", func() { }) Expect(len(taskSpec.Steps)).To(Equal(1)) - Expect(taskSpec.Steps[0].Name).To(Equal("sources-http")) + Expect(taskSpec.Steps[0].Name).To(Equal(sources.RemoteArtifactsContainerName)) Expect(taskSpec.Steps[0].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) Expect(taskSpec.Steps[0].WorkingDir).To(Equal("$(params.shp-source-root)")) Expect(taskSpec.Steps[0].Args[3]).To(Equal("wget \"https://shipwright.io/icons/logo.svg\"")) @@ -51,7 +51,7 @@ var _ = Describe("HTTP", func() { Steps: []tektonv1beta1.Step{ { Container: corev1.Container{ - Name: "sources-http", + Name: sources.RemoteArtifactsContainerName, Image: cfg.RemoteArtifactsContainerImage, WorkingDir: "$(params.shp-source-root)", Command: []string{ @@ -76,7 +76,7 @@ var _ = Describe("HTTP", func() { }) Expect(len(taskSpec.Steps)).To(Equal(1)) - Expect(taskSpec.Steps[0].Name).To(Equal("sources-http")) + Expect(taskSpec.Steps[0].Name).To(Equal(sources.RemoteArtifactsContainerName)) Expect(taskSpec.Steps[0].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) Expect(taskSpec.Steps[0].WorkingDir).To(Equal("$(params.shp-source-root)")) Expect(taskSpec.Steps[0].Args[3]).To(Equal("wget \"https://tekton.dev/images/tekton-horizontal-color.png\" ; wget \"https://shipwright.io/icons/logo.svg\"")) @@ -106,7 +106,7 @@ var _ = Describe("HTTP", func() { }) Expect(len(taskSpec.Steps)).To(Equal(2)) - Expect(taskSpec.Steps[1].Name).To(Equal("sources-http")) + Expect(taskSpec.Steps[1].Name).To(Equal(sources.RemoteArtifactsContainerName)) Expect(taskSpec.Steps[1].Image).To(Equal(cfg.RemoteArtifactsContainerImage)) Expect(taskSpec.Steps[1].WorkingDir).To(Equal("$(params.shp-source-root)")) Expect(taskSpec.Steps[1].Args[3]).To(Equal("wget \"https://shipwright.io/icons/logo.svg\""))