Skip to content

Commit 95db0fd

Browse files
Add a multistage e2e test
1 parent da9ca32 commit 95db0fd

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

test/extended/builds/multistage.go

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package builds
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
g "github.com/onsi/ginkgo"
8+
o "github.com/onsi/gomega"
9+
10+
corev1 "k8s.io/api/core/v1"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
core "k8s.io/kubernetes/pkg/apis/core"
13+
e2e "k8s.io/kubernetes/test/e2e/framework"
14+
15+
buildapi "github.com/openshift/origin/pkg/build/apis/build"
16+
exutil "github.com/openshift/origin/test/extended/util"
17+
)
18+
19+
var _ = g.Describe("[Feature:Builds] Multi-stage image builds", func() {
20+
defer g.GinkgoRecover()
21+
var (
22+
oc = exutil.NewCLI("build-multistage", exutil.KubeConfigPath())
23+
testDockerfile = `
24+
FROM centos:7 AS test
25+
USER 1001
26+
FROM centos:7
27+
COPY --from=test /usr/bin/curl /test/
28+
`
29+
)
30+
31+
g.Context("", func() {
32+
33+
g.JustBeforeEach(func() {
34+
g.By("waiting for builder service account")
35+
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
36+
o.Expect(err).NotTo(o.HaveOccurred())
37+
oc.SetOutputDir(exutil.TestContext.OutputDir)
38+
})
39+
40+
g.AfterEach(func() {
41+
if g.CurrentGinkgoTestDescription().Failed {
42+
exutil.DumpPodStates(oc)
43+
exutil.DumpPodLogsStartingWith("", oc)
44+
}
45+
})
46+
47+
g.It("should succeed [Conformance]", func() {
48+
g.By("creating a build directly")
49+
build, err := oc.BuildClient().Build().Builds(oc.Namespace()).Create(&buildapi.Build{
50+
ObjectMeta: metav1.ObjectMeta{
51+
Name: "multi-stage",
52+
},
53+
Spec: buildapi.BuildSpec{
54+
CommonSpec: buildapi.CommonSpec{
55+
Source: buildapi.BuildSource{
56+
Dockerfile: &testDockerfile,
57+
},
58+
Strategy: buildapi.BuildStrategy{
59+
DockerStrategy: &buildapi.DockerBuildStrategy{},
60+
},
61+
Output: buildapi.BuildOutput{
62+
To: &core.ObjectReference{
63+
Kind: "DockerImage",
64+
Name: fmt.Sprintf("docker-registry.default.svc:5000/%s/multi-stage:v1", oc.Namespace()),
65+
},
66+
},
67+
},
68+
},
69+
})
70+
o.Expect(err).NotTo(o.HaveOccurred())
71+
result := exutil.NewBuildResult(oc, build)
72+
err = exutil.WaitForBuildResult(oc.AdminBuildClient().Build().Builds(oc.Namespace()), result)
73+
o.Expect(err).NotTo(o.HaveOccurred())
74+
o.Expect(result.BuildSuccess).To(o.BeTrue(), "Build did not succeed: %#v", result)
75+
76+
pod, err := oc.KubeClient().CoreV1().Pods(oc.Namespace()).Get(build.Name+"-build", metav1.GetOptions{})
77+
o.Expect(err).NotTo(o.HaveOccurred())
78+
if strings.HasSuffix(pod.Spec.Containers[0].Image, ":v3.9.0-alpha.0") {
79+
g.Skip(fmt.Sprintf("The currently selected builder image does not yet support optimized image builds: %s", pod.Spec.Containers[0].Image))
80+
}
81+
82+
s, err := result.Logs()
83+
o.Expect(err).NotTo(o.HaveOccurred())
84+
o.Expect(s).To(o.ContainSubstring("--> COPY --from"))
85+
o.Expect(s).To(o.ContainSubstring(fmt.Sprintf("\"OPENSHIFT_BUILD_NAMESPACE\"=\"%s\"", oc.Namespace())))
86+
o.Expect(s).To(o.ContainSubstring("--> Committing changes to "))
87+
e2e.Logf("Build logs:\n%s", result)
88+
89+
c := oc.KubeFramework().PodClient()
90+
pod = c.Create(&corev1.Pod{
91+
ObjectMeta: metav1.ObjectMeta{
92+
Name: "test",
93+
},
94+
Spec: corev1.PodSpec{
95+
RestartPolicy: corev1.RestartPolicyNever,
96+
Containers: []corev1.Container{
97+
{
98+
Name: "run",
99+
Image: fmt.Sprintf("docker-registry.default.svc:5000/%s/multi-stage:v1", oc.Namespace()),
100+
Command: []string{"/test/curl", "-k", "https://kubernetes.default.svc"},
101+
},
102+
},
103+
},
104+
})
105+
c.WaitForSuccess(pod.Name, e2e.PodStartTimeout)
106+
data, err := c.GetLogs(pod.Name, &corev1.PodLogOptions{}).DoRaw()
107+
o.Expect(err).NotTo(o.HaveOccurred())
108+
e2e.Logf("Pod logs:\n%s", string(data))
109+
})
110+
})
111+
})

0 commit comments

Comments
 (0)