Skip to content

Commit

Permalink
Use a specific container name
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi committed Apr 19, 2023
1 parent 9d13836 commit d9d262c
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 118 deletions.
60 changes: 41 additions & 19 deletions tests/e2escenarios/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ var _ = Describe("E2E Test", func() {
helper.CommonAfterEach(commonVar)
})

waitRemoteApp := func(urlInContainer, assertString string) {
waitRemoteApp := func(urlInContainer, assertString, containerName string) {
cmp := helper.NewComponent(componentName, "app", "Dev", commonVar.Project, commonVar.CliRunner)
helper.WaitAppReadyInContainer(cmp, "runtime", []string{"curl", urlInContainer}, 5*time.Second, 120*time.Second, ContainSubstring(assertString), nil)
helper.WaitAppReadyInContainer(cmp, containerName, []string{"curl", urlInContainer}, 5*time.Second, 120*time.Second, ContainSubstring(assertString), nil)
}

checkIfDevEnvIsUp := func(url, assertString string) {
Expand All @@ -44,7 +44,7 @@ var _ = Describe("E2E Test", func() {

body, _ := io.ReadAll(resp.Body)
return string(body)
}, 120*time.Second, 15*time.Second).Should(Equal(assertString))
}, 120*time.Second, 15*time.Second).Should(ContainSubstring(assertString))
}

Context("starting with empty Directory", func() {
Expand Down Expand Up @@ -102,22 +102,22 @@ var _ = Describe("E2E Test", func() {

devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js Starter Application!")
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js Starter Application!", "runtime")
checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js Starter Application!")

helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js", "from updated Node.js")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should update the changes"
waitRemoteApp("http://127.0.0.1:3000", "Hello from updated Node.js Starter Application!")
waitRemoteApp("http://127.0.0.1:3000", "Hello from updated Node.js Starter Application!", "runtime")
checkIfDevEnvIsUp(ports["3000"], "Hello from updated Node.js Starter Application!")

// "changes are made to the applications"
helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from updated Node.js", "from Node.js app v2")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should deploy new changes"
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js app v2 Starter Application!")
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js app v2 Starter Application!", "runtime")
checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js app v2 Starter Application!")

// "running odo list"
Expand Down Expand Up @@ -158,7 +158,7 @@ var _ = Describe("E2E Test", func() {
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should update the changes"
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js app v3 Starter Application!")
waitRemoteApp("http://127.0.0.1:3000", "Hello from Node.js app v3 Starter Application!", "runtime")
checkIfDevEnvIsUp(ports["3000"], "Hello from Node.js app v3 Starter Application!")

// should list both dev,deploy
Expand Down Expand Up @@ -231,22 +231,22 @@ var _ = Describe("E2E Test", func() {
devSession, out, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())
Expect(out).ToNot(BeEmpty())
waitRemoteApp(AppLocalURL, "Hello World!")
waitRemoteApp(AppLocalURL, "Hello World!", "tools")
checkIfDevEnvIsUp(ports[AppPort], "Hello World!")

helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello World!", "Hello updated World!")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should update the changes"
waitRemoteApp(AppLocalURL, "Hello updated World!")
waitRemoteApp(AppLocalURL, "Hello updated World!", "tools")
checkIfDevEnvIsUp(ports[AppPort], "Hello updated World!")

// "changes are made to the applications"
helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello updated World!", "Hello from an updated World!")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should deploy new changes"
waitRemoteApp(AppLocalURL, "Hello from an updated World!")
waitRemoteApp(AppLocalURL, "Hello from an updated World!", "tools")
checkIfDevEnvIsUp(ports[AppPort], "Hello from an updated World!")

// "running odo list"
Expand Down Expand Up @@ -276,17 +276,19 @@ var _ = Describe("E2E Test", func() {

// should deploy new changes
stdout = helper.Cmd("odo", "list", "component").ShouldPass().Out()
helper.MatchAllInOutput(stdout, []string{componentName, "springbooot", "Deploy"})
helper.MatchAllInOutput(stdout, []string{componentName, "springboot", "Deploy"})

// start dev mode again
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{})
Expect(err).ToNot(HaveOccurred())

// making changes to the project again
helper.ReplaceString(filepath.Join(commonVar.Context, "src", "main", "java", "com", "example", "demo", "DemoApplication.java"), "Hello from an updated World!", "Hello from an updated v2 World!")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())

// "should update the changes"
waitRemoteApp(AppLocalURL, "Hello from an updated v2 World!")
waitRemoteApp(AppLocalURL, "Hello from an updated v2 World!", "tools")
checkIfDevEnvIsUp(ports[AppPort], "Hello from an updated v2 World!")

// should list both dev,deploy
Expand Down Expand Up @@ -336,7 +338,25 @@ var _ = Describe("E2E Test", func() {
helper.SendLine(ctx, "")

helper.ExpectString(ctx, "Select container for which you want to change configuration?")
helper.SendLine(ctx, "runtime")

// Personalize the Devfile to use the debug envvar defined inside package.json
helper.ExpectString(ctx, "What configuration do you want change")
helper.SendLine(ctx, "Delete environment variable \"DEBUG_PORT\"")

helper.ExpectString(ctx, "What configuration do you want change")
helper.SendLine(ctx, "Add new environment variable")

helper.ExpectString(ctx, "Enter new environment variable name")
helper.SendLine(ctx, "DEBUG_PORT_PROJECT")

helper.ExpectString(ctx, "Enter value for \"DEBUG_PORT_PROJECT\" environment variable")
helper.SendLine(ctx, "5858")

helper.ExpectString(ctx, "What configuration do you want change")
helper.SendLine(ctx, "")

helper.ExpectString(ctx, "Select container for which you want to change configuration?")
helper.SendLine(ctx, "")

helper.ExpectString(ctx, "Enter component name")
Expand All @@ -352,21 +372,23 @@ var _ = Describe("E2E Test", func() {
// "execute odo dev and add changes to application"
var devSession helper.DevSession
var ports map[string]string
var out []byte
devSession, out, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{
var out, errOut []byte
devSession, out, errOut, ports, err = helper.StartDevMode(helper.DevSessionOpts{
CmdlineArgs: []string{"--debug"},
})
Expect(err).ToNot(HaveOccurred())
Expect(out).ToNot(BeEmpty())
waitRemoteApp(LocalAppURL, "Hello from Node.js Starter Application!")
// This is to ensure all the ports are ready and there is nothing in the warnings
Expect(errOut).To(BeEmpty())
waitRemoteApp(LocalAppURL, "Hello from Node.js Starter Application!", "runtime")
checkIfDevEnvIsUp(ports[AppPort], "Hello from Node.js Starter Application!")
checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected")

helper.ReplaceString(filepath.Join(commonVar.Context, "server.js"), "from Node.js", "from updated Node.js")
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should update the changes"
waitRemoteApp(LocalAppURL, "Hello from updated Node.js Starter Application!")
waitRemoteApp(LocalAppURL, "Hello from updated Node.js Starter Application!", "runtime")
checkIfDevEnvIsUp(ports[AppPort], "Hello from updated Node.js Starter Application!")
checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected")

Expand All @@ -375,15 +397,15 @@ var _ = Describe("E2E Test", func() {
_, _, _, err = devSession.WaitSync()
Expect(err).ToNot(HaveOccurred())
// "should deploy new changes"
waitRemoteApp(LocalAppURL, "Hello from Node.js app v2 Starter Application!")
waitRemoteApp(LocalAppURL, "Hello from Node.js app v2 Starter Application!", "runtime")
checkIfDevEnvIsUp(ports[AppPort], "Hello from Node.js app v2 Starter Application!")
checkIfDevEnvIsUp(ports[DebugPort], "WebSockets request was expected")

// "running odo list"
stdout := helper.Cmd("odo", "list", "component").ShouldPass().Out()
helper.MatchAllInOutput(stdout, []string{componentName, "Node.js", "Dev"})

// "exit dev mode and run odo deploy"
// "exit dev mode"
devSession.Stop()
devSession.WaitEnd()

Expand Down Expand Up @@ -484,7 +506,7 @@ var _ = Describe("E2E Test", func() {
Expect(err).ToNot(HaveOccurred())

// "send data"
waitRemoteApp("http://127.0.0.1:8080/ping", "pong")
waitRemoteApp("http://127.0.0.1:8080/ping", "pong", "runtime")
data := sendDataEntry(ports["8080"])
Expect(data["message"]).To(Equal("User created successfully"))

Expand Down
192 changes: 93 additions & 99 deletions tests/examples/source/devfiles/springboot/devfile-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,102 +1,96 @@
---
schemaVersion: 2.2.0
commands:
- exec:
commandLine: mvn clean -Dmaven.repo.local=/home/user/.m2/repository package -Dmaven.test.skip=true
component: tools
group:
isDefault: true
kind: build
workingDir: ${PROJECT_SOURCE}
id: build
- exec:
commandLine: mvn -Dmaven.repo.local=/home/user/.m2/repository spring-boot:run
component: tools
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
- exec:
commandLine: java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=${DEBUG_PORT},suspend=n
-jar target/*.jar
component: tools
group:
isDefault: true
kind: debug
workingDir: ${PROJECT_SOURCE}
id: debug
- apply:
component: build
id: build-image
- apply:
component: deploy
id: deployk8s
- composite:
commands:
- build-image
- deployk8s
group:
isDefault: true
kind: deploy
id: deploy
components:
- container:
command:
- tail
- -f
- /dev/null
endpoints:
- name: http-springboot
targetPort: 8080
- exposure: none
name: debug
targetPort: 5858
env:
- name: DEBUG_PORT
value: "5858"
image: registry.access.redhat.com/ubi8/openjdk-11:latest
memoryLimit: 768Mi
mountSources: true
volumeMounts:
- name: m2
path: /home/user/.m2
name: tools
- name: m2
volume:
size: 3Gi
- image:
dockerfile:
buildContext: .
rootRequired: false
uri: docker/Dockerfile
imageName: java-springboot-image:latest
name: build
- kubernetes:
endpoints:
- name: http-8081
targetPort: 8081
uri: kubernetes/deploy.yaml
name: deploy
metadata:
name: java-spring-boot
language: java
description: Java application using Spring Boot® and OpenJDK 11
displayName: Spring Boot®
globalMemoryLimit: 2674Mi
icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg
language: Java
name: demo
projectType: springboot
tags:
- Java
- Spring
version: 2.0.0
schemaVersion: 2.2.0
starterProjects:
- name: springbootproject
git:
remotes:
origin: "https://github.com/odo-devfiles/springboot-ex.git"
components:
- name: tools
container:
image: registry.access.redhat.com/ubi8/openjdk-11:latest
memoryLimit: 768Mi
command: ['tail']
args: [ '-f', '/dev/null']
mountSources: true
volumeMounts:
- name: springbootpvc
path: /data/cache/.m2
- name: runtime
container:
image: registry.access.redhat.com/ubi8/openjdk-11:latest
memoryLimit: 768Mi
endpoints:
- name: "8080-tcp"
targetPort: 8080
volumeMounts:
- name: springbootpvc
path: /data/cache/.m2
mountSources: true
- name: springbootpvc
volume:
size: 3Gi
ephemeral: true
- name: outerloop-build
image:
imageName: "{{CONTAINER_IMAGE}}"
dockerfile:
uri: ./Dockerfile
buildContext: ${PROJECTS_ROOT}
rootRequired: false

- name: outerloop-deploy
kubernetes:
inlined: |
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-component
spec:
replicas: 1
selector:
matchLabels:
app: springboot-app
template:
metadata:
labels:
app: springboot-app
spec:
containers:
- name: main
image: {{CONTAINER_IMAGE}}
resources:
limits:
memory: "128Mi"
cpu: "500m"
commands:
- id: defaultbuild
exec:
component: tools
commandLine: "mvn clean -Dmaven.repo.local=/data/cache/.m2/repository package -Dmaven.test.skip=true"
workingDir: /projects
group:
kind: build
- id: defaultrun
exec:
component: runtime
commandLine: "mvn -Dmaven.repo.local=/data/cache/.m2/repository spring-boot:run"
workingDir: /projects
group:
kind: run
isDefault: true
- id: build-image
apply:
component: outerloop-build
- id: deployk8s
apply:
component: outerloop-deploy
- id: deploy
composite:
commands:
- build-image
- deployk8s
group:
kind: deploy
isDefault: true
variables:
CONTAINER_IMAGE: quay.io/unknown-account/myimage

- git:
remotes:
origin: https://github.com/odo-devfiles/springboot-ex.git
name: springbootproject
Loading

0 comments on commit d9d262c

Please sign in to comment.