Skip to content

fix regressed contextdir buildconfig parameter behavior #12628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions pkg/build/builder/sti.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,20 @@ func (s *S2IBuilder) Build() error {
handleBuildStatusUpdate(s.build, s.client, nil)
return err
}
contextDir := ""
if len(s.build.Spec.Source.ContextDir) > 0 {
contextDir := filepath.Clean(s.build.Spec.Source.ContextDir)
contextDir = filepath.Clean(s.build.Spec.Source.ContextDir)
if contextDir == "." || contextDir == "/" {
contextDir = ""
}
if sourceInfo != nil {
sourceInfo.ContextDir = s.build.Spec.Source.ContextDir
}
srcDir = filepath.Join(srcDir, s.build.Spec.Source.ContextDir)
}
download := &downloader{}

var s2iSourceInfo *s2iapi.SourceInfo
if sourceInfo != nil {
download.sourceInfo = &sourceInfo.SourceInfo
s2iSourceInfo = &sourceInfo.SourceInfo
revision := updateBuildRevision(s.build, sourceInfo)
handleBuildStatusUpdate(s.build, s.client, revision)
}
Expand Down Expand Up @@ -182,6 +183,8 @@ func (s *S2IBuilder) Build() error {
DockerNetworkMode: getDockerNetworkMode(),

Source: srcDir,
ContextDir: contextDir,
SourceInfo: s2iSourceInfo,
ForceCopy: true,
Injections: injections,

Expand Down Expand Up @@ -241,7 +244,7 @@ func (s *S2IBuilder) Build() error {
}

glog.V(4).Infof("Creating a new S2I builder with build config: %#v\n", describe.Config(config))
builder, buildInfo, err := s.builder.Builder(config, s2ibuild.Overrides{Downloader: download})
builder, buildInfo, err := s.builder.Builder(config, s2ibuild.Overrides{Downloader: nil})
if err != nil {
s.build.Status.Reason, s.build.Status.Message = convertS2IFailureType(
buildInfo.FailureReason.Reason,
Expand Down
101 changes: 101 additions & 0 deletions test/extended/builds/contextdir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package builds

import (
"fmt"
"time"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"

kapi "k8s.io/kubernetes/pkg/api"

imageeco "github.com/openshift/origin/test/extended/image_ecosystem"
exutil "github.com/openshift/origin/test/extended/util"
)

var _ = g.Describe("[builds][Slow] builds with a context directory", func() {
defer g.GinkgoRecover()
var (
appFixture = exutil.FixturePath("testdata", "test-context-build.json")
oc = exutil.NewCLI("contextdir", exutil.KubeConfigPath())
s2iBuildConfigName = "s2icontext"
s2iBuildName = "s2icontext-1"
dcName = "frontend"
deploymentName = "frontend-1"
dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", deploymentName))
serviceName = "frontend"
dockerBuildConfigName = "dockercontext"
dockerBuildName = "dockercontext-1"
)
g.Describe("s2i context directory build", func() {
g.It(fmt.Sprintf("should s2i build an application using a context directory"), func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)

exutil.CheckOpenShiftNamespaceImageStreams(oc)
g.By(fmt.Sprintf("calling oc create -f %q", appFixture))
err := oc.Run("create").Args("-f", appFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("starting a build")
err = oc.Run("start-build").Args(s2iBuildConfigName).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("waiting for build to finish")
err = exutil.WaitForABuild(oc.Client().Builds(oc.Namespace()), s2iBuildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn, nil)
if err != nil {
exutil.DumpBuildLogs("s2icontext", oc)
}
o.Expect(err).NotTo(o.HaveOccurred())

// oc.KubeFramework().WaitForAnEndpoint currently will wait forever; for now, prefacing with our WaitForADeploymentToComplete,
// which does have a timeout, since in most cases a failure in the service coming up stems from a failed deployment
g.By("waiting for a deployment")
err = exutil.WaitForADeploymentToComplete(oc.KubeClient().Core().ReplicationControllers(oc.Namespace()), dcName, oc)
o.Expect(err).NotTo(o.HaveOccurred())

g.By("waiting for endpoint")
err = oc.KubeFramework().WaitForAnEndpoint(serviceName)
o.Expect(err).NotTo(o.HaveOccurred())

assertPageContent := func(content string) {
_, err := exutil.WaitForPods(oc.KubeClient().Core().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute)
o.Expect(err).NotTo(o.HaveOccurred())

result, err := imageeco.CheckPageContains(oc, "frontend", "", content)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(result).To(o.BeTrue())
}

g.By("testing application content")
assertPageContent("Hello world!")

g.By("checking the pod count")
pods, err := oc.KubeClient().Core().Pods(oc.Namespace()).List(kapi.ListOptions{LabelSelector: dcLabel})
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(pods.Items)).To(o.Equal(1))
})
})

g.Describe("docker context directory build", func() {
g.It(fmt.Sprintf("should docker build an application using a context directory"), func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)

exutil.CheckOpenShiftNamespaceImageStreams(oc)
g.By(fmt.Sprintf("calling oc create -f %q", appFixture))
err := oc.Run("create").Args("-f", appFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("starting a build")
err = oc.Run("start-build").Args(dockerBuildConfigName).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

// build will fail if we don't use the right context dir because there won't be a dockerfile present.
g.By("waiting for build to finish")
err = exutil.WaitForABuild(oc.Client().Builds(oc.Namespace()), dockerBuildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn, nil)
if err != nil {
exutil.DumpBuildLogs("dockercontext", oc)
}
o.Expect(err).NotTo(o.HaveOccurred())
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@
}
],
"resources": {
"limits": {
"memory": "${MEMORY_LIMIT}"
}
},
"limits": {
"memory": "${MEMORY_LIMIT}"
}
},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "IfNotPresent",
"securityContext": {
Expand Down
Loading