diff --git a/docs/build.md b/docs/build.md index a5f7ca1dc4..882d64c8fa 100644 --- a/docs/build.md +++ b/docs/build.md @@ -100,6 +100,7 @@ The `Build` definition supports the following fields: A `Build` resource can specify a Git repository or bundle image source, together with other parameters like: +- `source.type` - Specify the type of the data-source. Currently, the supported types are "Git", "OCI", and "Local". - `source.git.url` - Specify the source location using a Git repository. - `source.git.cloneSecret` - For private repositories or registries, the name references a secret in the namespace that contains the SSH private key or Docker access credentials, respectively. - `source.git.revision` - A specific revision to select from the source repository, this can be a commit, tag or branch name. If not defined, it will fallback to the Git repository default branch. diff --git a/test/data/v1beta1/buildrun_buildah_cr_local_source_upload.yaml b/test/data/v1beta1/buildrun_buildah_cr_local_source_upload.yaml index 33e531c84c..5b602105c2 100644 --- a/test/data/v1beta1/buildrun_buildah_cr_local_source_upload.yaml +++ b/test/data/v1beta1/buildrun_buildah_cr_local_source_upload.yaml @@ -6,5 +6,7 @@ metadata: spec: build: name: buildah-local-source-upload - sources: - - name: local-copy + source: + local: + name: local-copy + type: Local diff --git a/test/e2e/v1beta1/e2e_local_source_upload_test.go b/test/e2e/v1beta1/e2e_local_source_upload_test.go new file mode 100644 index 0000000000..d57177dc38 --- /dev/null +++ b/test/e2e/v1beta1/e2e_local_source_upload_test.go @@ -0,0 +1,104 @@ +// Copyright The Shipwright Contributors +// +// SPDX-License-Identifier: Apache-2.0 + +package e2e_test + +import ( + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "k8s.io/apimachinery/pkg/types" + + buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" + utils "github.com/shipwright-io/build/test/utils/v1beta1" +) + +var _ = Describe("For a Kubernetes cluster with Tekton and build installed", func() { + var ( + testID string + build *buildv1beta1.Build + buildRun *buildv1beta1.BuildRun + ) + + AfterEach(func() { + if buildRun != nil { + testBuild.DeleteBR(buildRun.Name) + buildRun = nil + } + + if build != nil { + testBuild.DeleteBuild(build.Name) + build = nil + } + }) + + Context("when LocalCopy BuildSource is defined", func() { + BeforeEach(func() { + testID = generateTestID("local-copy") + build = createBuild( + testBuild, + testID, + "test/data/v1beta1/build_buildah_cr_local_source_upload.yaml", + ) + }) + + It("should generate LocalCopy TaskRun, using the waiter", func() { + var err error + buildRun, err = buildRunTestData( + testBuild.Namespace, + testID, + "test/data/v1beta1/buildrun_buildah_cr_local_source_upload.yaml", + ) + Expect(err).ToNot(HaveOccurred(), "Error retrieving buildrun test data") + + validateWaiterBuildRun(testBuild, buildRun) + }) + }) +}) + +func getBuildRunStatusCondition(name types.NamespacedName) *buildv1beta1.Condition { + testBuildRun, err := testBuild.LookupBuildRun(name) + Expect(err).ToNot(HaveOccurred(), "Error retrieving the BuildRun") + + if len(testBuildRun.Status.Conditions) == 0 { + return nil + } + return testBuildRun.Status.GetCondition(buildv1beta1.Succeeded) +} + +// validateWaiterBuildRun assert the BuildRun informed will fail, since Waiter's timeout is reached +// and it causes the actual build process to fail as well. +func validateWaiterBuildRun(testBuild *utils.TestBuild, testBuildRun *buildv1beta1.BuildRun) { + err := testBuild.CreateBR(testBuildRun) + Expect(err).ToNot(HaveOccurred(), "Failed to create BuildRun") + + buildRunName := types.NamespacedName{ + Namespace: testBuild.Namespace, + Name: testBuildRun.Name, + } + + // making sure the taskrun is schedule and becomes a pod, since the build controller will transit + // the object status from empty to unknown, when the actual build starts being executed + Eventually(func() bool { + condition := getBuildRunStatusCondition(buildRunName) + if condition == nil { + return false + } + Logf("BuildRun %q status %q...", buildRunName, condition.Status) + return condition.Reason == "Running" + }, time.Duration(1100*getTimeoutMultiplier())*time.Second, 5*time.Second). + Should(BeTrue(), "BuildRun should start running") + + // asserting the waiter step will end up in timeout, in other words, the build is terminated with + // the reason "failed" + Eventually(func() string { + condition := getBuildRunStatusCondition(buildRunName) + Expect(condition).ToNot(BeNil()) + Logf("BuildRun %q condition %v...", buildRunName, condition) + return condition.Reason + }, time.Duration(90*time.Second), 10*time.Second). + Should(Equal("Failed"), "BuildRun should end up in timeout") +}