Skip to content

Commit bbb2ee1

Browse files
committed
use correct context dir during s2i build
1 parent 44a1372 commit bbb2ee1

File tree

4 files changed

+268
-9
lines changed

4 files changed

+268
-9
lines changed

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": {
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"kind": "List",
3+
"apiVersion": "v1",
4+
"metadata": {},
5+
"items": [
6+
{
7+
"kind": "BuildConfig",
8+
"apiVersion": "v1",
9+
"metadata": {
10+
"name": "dockercontext"
11+
},
12+
"spec": {
13+
"triggers": [],
14+
"source": {
15+
"type": "Git",
16+
"git": {
17+
"uri":"https://github.com/sclorg/s2i-ruby-container"
18+
},
19+
"contextDir": "2.3"
20+
},
21+
"strategy": {
22+
"type": "Docker",
23+
"dockerStrategy": {
24+
"env": [
25+
{
26+
"name": "BUILD_LOGLEVEL",
27+
"value": "5"
28+
}
29+
]
30+
}
31+
}
32+
}
33+
},
34+
{
35+
"kind": "BuildConfig",
36+
"apiVersion": "v1",
37+
"metadata": {
38+
"name": "s2icontext"
39+
},
40+
"spec": {
41+
"triggers": [],
42+
"source": {
43+
"type": "Git",
44+
"git": {
45+
"uri":"https://github.com/sclorg/s2i-ruby-container"
46+
},
47+
"contextDir": "2.3/test/puma-test-app"
48+
},
49+
"strategy": {
50+
"type": "Source",
51+
"sourceStrategy": {
52+
"env": [
53+
{
54+
"name": "BUILD_LOGLEVEL",
55+
"value": "5"
56+
}
57+
],
58+
"from": {
59+
"kind": "DockerImage",
60+
"name": "centos/ruby-23-centos7"
61+
}
62+
}
63+
},
64+
"output": {
65+
"to": {
66+
"kind": "ImageStreamTag",
67+
"name": "test:latest"
68+
}
69+
}
70+
}
71+
},
72+
{
73+
"kind": "ImageStream",
74+
"apiVersion": "v1",
75+
"metadata": {
76+
"name": "test"
77+
}
78+
},
79+
{
80+
"kind": "DeploymentConfig",
81+
"apiVersion": "v1",
82+
"metadata": {
83+
"name": "frontend"
84+
},
85+
"spec": {
86+
"triggers": [
87+
{
88+
"type": "ImageChange",
89+
"imageChangeParams": {
90+
"automatic": true,
91+
"containerNames": [
92+
"frontend"
93+
],
94+
"from": {
95+
"kind": "ImageStreamTag",
96+
"name": "test:latest"
97+
}
98+
}
99+
}
100+
],
101+
"replicas": 1,
102+
"selector": {
103+
"name":"frontend"
104+
},
105+
"template": {
106+
"metadata": {
107+
"labels": {
108+
"name": "frontend"
109+
}
110+
},
111+
"spec": {
112+
"containers": [
113+
{
114+
"name": "frontend",
115+
"image": "",
116+
"ports": [
117+
{
118+
"containerPort": 8080,
119+
"protocol": "TCP"
120+
}
121+
]
122+
}
123+
]
124+
}
125+
}
126+
}
127+
},
128+
{
129+
"kind": "Service",
130+
"apiVersion": "v1",
131+
"metadata": {
132+
"name": "frontend"
133+
},
134+
"spec": {
135+
"ports": [
136+
{
137+
"name": "web",
138+
"protocol": "TCP",
139+
"port": 5432,
140+
"targetPort": 8080,
141+
"nodePort": 0
142+
}
143+
],
144+
"selector": {
145+
"name": "frontend"
146+
},
147+
"type": "ClusterIP",
148+
"sessionAffinity": "None"
149+
},
150+
"status": {
151+
"loadBalancer": {}
152+
}
153+
}
154+
]
155+
}

0 commit comments

Comments
 (0)