Skip to content

Commit 57f171c

Browse files
author
OpenShift Bot
authored
Merge pull request #12628 from bparees/context_dir
Merged by openshift-bot
2 parents 9c10505 + 91c6017 commit 57f171c

File tree

6 files changed

+296
-35
lines changed

6 files changed

+296
-35
lines changed

Godeps/Godeps.json

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/build/builder/sti.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,20 @@ func (s *S2IBuilder) Build() error {
121121
handleBuildStatusUpdate(s.build, s.client, nil)
122122
return err
123123
}
124+
contextDir := ""
124125
if len(s.build.Spec.Source.ContextDir) > 0 {
125-
contextDir := filepath.Clean(s.build.Spec.Source.ContextDir)
126+
contextDir = filepath.Clean(s.build.Spec.Source.ContextDir)
126127
if contextDir == "." || contextDir == "/" {
127128
contextDir = ""
128129
}
129130
if sourceInfo != nil {
130131
sourceInfo.ContextDir = s.build.Spec.Source.ContextDir
131132
}
132-
srcDir = filepath.Join(srcDir, s.build.Spec.Source.ContextDir)
133133
}
134-
download := &downloader{}
134+
135+
var s2iSourceInfo *s2iapi.SourceInfo
135136
if sourceInfo != nil {
136-
download.sourceInfo = &sourceInfo.SourceInfo
137+
s2iSourceInfo = &sourceInfo.SourceInfo
137138
revision := updateBuildRevision(s.build, sourceInfo)
138139
handleBuildStatusUpdate(s.build, s.client, revision)
139140
}
@@ -182,6 +183,8 @@ func (s *S2IBuilder) Build() error {
182183
DockerNetworkMode: getDockerNetworkMode(),
183184

184185
Source: srcDir,
186+
ContextDir: contextDir,
187+
SourceInfo: s2iSourceInfo,
185188
ForceCopy: true,
186189
Injections: injections,
187190

@@ -241,7 +244,7 @@ func (s *S2IBuilder) Build() error {
241244
}
242245

243246
glog.V(4).Infof("Creating a new S2I builder with build config: %#v\n", describe.Config(config))
244-
builder, buildInfo, err := s.builder.Builder(config, s2ibuild.Overrides{Downloader: download})
247+
builder, buildInfo, err := s.builder.Builder(config, s2ibuild.Overrides{Downloader: nil})
245248
if err != nil {
246249
s.build.Status.Reason, s.build.Status.Message = convertS2IFailureType(
247250
buildInfo.FailureReason.Reason,

test/extended/builds/contextdir.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package builds
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
g "github.com/onsi/ginkgo"
8+
o "github.com/onsi/gomega"
9+
10+
kapi "k8s.io/kubernetes/pkg/api"
11+
12+
imageeco "github.com/openshift/origin/test/extended/image_ecosystem"
13+
exutil "github.com/openshift/origin/test/extended/util"
14+
)
15+
16+
var _ = g.Describe("[builds][Slow] builds with a context directory", func() {
17+
defer g.GinkgoRecover()
18+
var (
19+
appFixture = exutil.FixturePath("testdata", "test-context-build.json")
20+
oc = exutil.NewCLI("contextdir", exutil.KubeConfigPath())
21+
s2iBuildConfigName = "s2icontext"
22+
s2iBuildName = "s2icontext-1"
23+
dcName = "frontend"
24+
deploymentName = "frontend-1"
25+
dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", deploymentName))
26+
serviceName = "frontend"
27+
dockerBuildConfigName = "dockercontext"
28+
dockerBuildName = "dockercontext-1"
29+
)
30+
g.Describe("s2i context directory build", func() {
31+
g.It(fmt.Sprintf("should s2i build an application using a context directory"), func() {
32+
oc.SetOutputDir(exutil.TestContext.OutputDir)
33+
34+
exutil.CheckOpenShiftNamespaceImageStreams(oc)
35+
g.By(fmt.Sprintf("calling oc create -f %q", appFixture))
36+
err := oc.Run("create").Args("-f", appFixture).Execute()
37+
o.Expect(err).NotTo(o.HaveOccurred())
38+
39+
g.By("starting a build")
40+
err = oc.Run("start-build").Args(s2iBuildConfigName).Execute()
41+
o.Expect(err).NotTo(o.HaveOccurred())
42+
43+
g.By("waiting for build to finish")
44+
err = exutil.WaitForABuild(oc.Client().Builds(oc.Namespace()), s2iBuildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn, nil)
45+
if err != nil {
46+
exutil.DumpBuildLogs("s2icontext", oc)
47+
}
48+
o.Expect(err).NotTo(o.HaveOccurred())
49+
50+
// oc.KubeFramework().WaitForAnEndpoint currently will wait forever; for now, prefacing with our WaitForADeploymentToComplete,
51+
// which does have a timeout, since in most cases a failure in the service coming up stems from a failed deployment
52+
g.By("waiting for a deployment")
53+
err = exutil.WaitForADeploymentToComplete(oc.KubeClient().Core().ReplicationControllers(oc.Namespace()), dcName, oc)
54+
o.Expect(err).NotTo(o.HaveOccurred())
55+
56+
g.By("waiting for endpoint")
57+
err = oc.KubeFramework().WaitForAnEndpoint(serviceName)
58+
o.Expect(err).NotTo(o.HaveOccurred())
59+
60+
assertPageContent := func(content string) {
61+
_, err := exutil.WaitForPods(oc.KubeClient().Core().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute)
62+
o.Expect(err).NotTo(o.HaveOccurred())
63+
64+
result, err := imageeco.CheckPageContains(oc, "frontend", "", content)
65+
o.Expect(err).NotTo(o.HaveOccurred())
66+
o.Expect(result).To(o.BeTrue())
67+
}
68+
69+
g.By("testing application content")
70+
assertPageContent("Hello world!")
71+
72+
g.By("checking the pod count")
73+
pods, err := oc.KubeClient().Core().Pods(oc.Namespace()).List(kapi.ListOptions{LabelSelector: dcLabel})
74+
o.Expect(err).NotTo(o.HaveOccurred())
75+
o.Expect(len(pods.Items)).To(o.Equal(1))
76+
})
77+
})
78+
79+
g.Describe("docker context directory build", func() {
80+
g.It(fmt.Sprintf("should docker build an application using a context directory"), func() {
81+
oc.SetOutputDir(exutil.TestContext.OutputDir)
82+
83+
exutil.CheckOpenShiftNamespaceImageStreams(oc)
84+
g.By(fmt.Sprintf("calling oc create -f %q", appFixture))
85+
err := oc.Run("create").Args("-f", appFixture).Execute()
86+
o.Expect(err).NotTo(o.HaveOccurred())
87+
88+
g.By("starting a build")
89+
err = oc.Run("start-build").Args(dockerBuildConfigName).Execute()
90+
o.Expect(err).NotTo(o.HaveOccurred())
91+
92+
// build will fail if we don't use the right context dir because there won't be a dockerfile present.
93+
g.By("waiting for build to finish")
94+
err = exutil.WaitForABuild(oc.Client().Builds(oc.Namespace()), dockerBuildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn, nil)
95+
if err != nil {
96+
exutil.DumpBuildLogs("dockercontext", oc)
97+
}
98+
o.Expect(err).NotTo(o.HaveOccurred())
99+
})
100+
})
101+
})

test/extended/testdata/jenkins-plugin/shared-resources-template.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@
107107
}
108108
],
109109
"resources": {
110-
"limits": {
111-
"memory": "${MEMORY_LIMIT}"
112-
}
113-
},
110+
"limits": {
111+
"memory": "${MEMORY_LIMIT}"
112+
}
113+
},
114114
"terminationMessagePath": "/dev/termination-log",
115115
"imagePullPolicy": "IfNotPresent",
116116
"securityContext": {

0 commit comments

Comments
 (0)