Skip to content

Commit

Permalink
Remote Artifacts
Browse files Browse the repository at this point in the history
Implementing "type" on the BuildSource instances employed for the
Remote Artifacts support.
  • Loading branch information
otaviof committed Jan 13, 2022
1 parent dd72409 commit 377dfb0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
5 changes: 4 additions & 1 deletion pkg/apis/build/v1alpha1/build_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions pkg/reconciler/buildrun/resources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/reconciler/buildrun/resources/sources/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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{
Expand All @@ -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
}
8 changes: 4 additions & 4 deletions pkg/reconciler/buildrun/resources/sources/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\""))
Expand All @@ -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{
Expand All @@ -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\""))
Expand Down Expand Up @@ -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\""))
Expand Down

0 comments on commit 377dfb0

Please sign in to comment.