Skip to content

Commit f2240ed

Browse files
committed
use src distinct directory for context-dir builds
1 parent b5dfd56 commit f2240ed

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/build/builder/sti.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ func (s *S2IBuilder) Build() error {
127127
if contextDir == "." || contextDir == "/" {
128128
contextDir = ""
129129
}
130+
if len(contextDir) > 0 {
131+
// if we're building out of a context dir, we need to use a different working
132+
// directory from where we put the source code because s2i is going to copy
133+
// from the context dir to the workdir, and if the workdir is a parent of the
134+
// context dir, we end up with a directory that contains 2 copies of the
135+
// input source code.
136+
buildDir, err = ioutil.TempDir("", "s2i-build-context")
137+
}
130138
if sourceInfo != nil {
131139
sourceInfo.ContextDir = s.build.Spec.Source.ContextDir
132140
}

test/extended/builds/contextdir.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ var _ = g.Describe("[builds][Slow] builds with a context directory", func() {
7373
pods, err := oc.KubeClient().Core().Pods(oc.Namespace()).List(kapi.ListOptions{LabelSelector: dcLabel})
7474
o.Expect(err).NotTo(o.HaveOccurred())
7575
o.Expect(len(pods.Items)).To(o.Equal(1))
76+
77+
g.By("expecting the pod not to contain two copies of the source")
78+
pod := pods.Items[0]
79+
out, err := oc.Run("exec").Args(pod.Name, "-c", pod.Spec.Containers[0].Name, "--", "ls", "/opt/app-root/src").Output()
80+
o.Expect(err).NotTo(o.HaveOccurred())
81+
o.Expect(out).To(o.ContainSubstring("2.3"))
7682
})
7783
})
7884

0 commit comments

Comments
 (0)