Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-default deploy commands do not break running the default one #5481

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,25 @@ func (a Adapter) getDeployCommand() (devfilev1.Command, error) {
return devfilev1.Command{}, &NoDefaultDeployCommandFoundError{}
}
if len(deployGroupCmd) > 1 {
return devfilev1.Command{}, &MoreThanOneDefaultDeployCommandFoundError{}
var found bool
var foundGroupCmd devfilev1.Command
for _, groupCmd := range deployGroupCmd {
group := parsercommon.GetGroup(groupCmd)
if group == nil {
continue
}
if group.IsDefault != nil && *group.IsDefault {
if found {
return devfilev1.Command{}, &MoreThanOneDefaultDeployCommandFoundError{}
}
found = true
foundGroupCmd = groupCmd
}
}
if !found {
return devfilev1.Command{}, &NoDefaultDeployCommandFoundError{}
}
return foundGroupCmd, nil
}
return deployGroupCmd[0], nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
workingDir: /project
id: install
- exec:
commandLine: npm start
component: runtime
group:
isDefault: true
kind: run
workingDir: /project
id: run
- exec:
commandLine: npm run debug
component: runtime
group:
isDefault: true
kind: debug
workingDir: /project
id: debug
- exec:
commandLine: npm test
component: runtime
group:
isDefault: true
kind: test
workingDir: /project
id: test
- id: build-image
apply:
component: outerloop-build
- id: deployk8s
apply:
component: outerloop-deploy
- id: deploy1
composite:
commands:
- build-image
- deployk8s
group:
kind: deploy
isDefault: true
- id: deploy2
composite:
commands:
- deployk8s
group:
kind: deploy
isDefault: false
components:
- container:
endpoints:
- name: http-3000
targetPort: 3000
image: registry.access.redhat.com/ubi8/nodejs-14:latest
memoryLimit: 1024Mi
mountSources: true
sourceMapping: /project
name: runtime
- 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: node-app
template:
metadata:
labels:
app: node-app
spec:
containers:
- name: main
image: {{CONTAINER_IMAGE}}
resources:
limits:
memory: "128Mi"
cpu: "500m"
metadata:
description: Stack with Node.js 14
displayName: Node.js Runtime
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
language: javascript
name: nodejs-prj1-api-abhz
projectType: nodejs
tags:
- NodeJS
- Express
- ubi8
version: 1.0.1
schemaVersion: 2.2.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/nodejs-ex.git
name: nodejs-starter
variables:
CONTAINER_IMAGE: quay.io/unknown-account/myimage
22 changes: 22 additions & 0 deletions tests/integration/devfile/cmd_devfile_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,26 @@ var _ = Describe("odo devfile deploy command tests", func() {
})
})
})

When("using a devfile.yaml containing two deploy commands", func() {

BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-with-two-deploy-commands.yaml"), path.Join(commonVar.Context, "devfile.yaml"))
})
AfterEach(func() {
helper.Cmd("odo", "delete", "-a").ShouldPass()
})
It("should run odo deploy", func() {
stdout := helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass().Out()
By("building and pushing image to registry", func() {
Expect(stdout).To(ContainSubstring("build -t quay.io/unknown-account/myimage -f " + filepath.Join(commonVar.Context, "Dockerfile ") + commonVar.Context))
Expect(stdout).To(ContainSubstring("push quay.io/unknown-account/myimage"))
})
By("deploying a deployment with the built image", func() {
out := commonVar.CliRunner.Run("get", "deployment", "my-component", "-n", commonVar.Project, "-o", `jsonpath="{.spec.template.spec.containers[0].image}"`).Wait().Out.Contents()
Expect(out).To(ContainSubstring("quay.io/unknown-account/myimage"))
})
})
})
})