[Backport release-1.1] Feat: add nocalhost dev config trait definition (#2564)

* Feat: add nocalhost dev config trait definition

(cherry picked from commit 965869b43b)

* Feat: add nocalhost dev config trait example

add nocalhost dev config trait example in `docs/examples/nocalhost`

Signed-off-by: yuyicai <yuyicai@hotmail.com>
(cherry picked from commit 70114877ce)

Co-authored-by: yuyicai <yuyicai@hotmail.com>
This commit is contained in:
github-actions[bot]
2021-10-27 16:03:39 +08:00
committed by GitHub
parent d21a337dd7
commit 706a65beae
4 changed files with 496 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/nocalhost.cue
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: nocalhost develop configuration.
name: nocalhost
namespace: {{.Values.systemDefinitionNamespace}}
spec:
appliesToWorkloads:
- '*'
podDisruptive: true
schematic:
cue:
template: |
import (
"encoding/json"
)
patch: metadata: annotations: {
"dev.nocalhost/application-name": context.appName
"dev.nocalhost/application-namespace": context.namespace
"dev.nocalhost": json.Marshal({
containers: [
{
name: context.name
dev: {
if parameter.gitUrl != _|_ {
gitUrl: parameter.gitUrl
}
image: parameter.image
shell: parameter.shell
workDir: parameter.workDir
if parameter.storageClass != _|_ {
storageClass: parameter.storageClass
}
resources: {
limits: parameter.resources.limits
requests: parameter.resources.requests
}
if parameter.persistentVolumeDirs != _|_ {
persistentVolumeDirs: [
for v in parameter.persistentVolumeDirs {
path: v.path
capacity: v.capacity
},
]
}
if parameter.command != _|_ {
command: parameter.command
}
if parameter.debug != _|_ {
debug: parameter.debug
}
hotReload: parameter.hotReload
if parameter.sync != _|_ {
sync: parameter.sync
}
if parameter.env != _|_ {
env: [
for v in parameter.env {
name: v.name
value: v.value
},
]
}
if parameter.portForward != _|_ {
portForward: parameter.portForward
}
}
},
]
})
}
parameter: {
gitUrl?: string
image: string
shell: *"bash" | string
workDir: *"/home/nocalhost-dev" | string
storageClass?: string
command?: {
run?: [...string]
debug?: [...string]
}
debug?: remoteDebugPort?: int
hotReload: *true | bool
sync: {
type: *"send" | string
filePattern?: [...string]
ignoreFilePattern?: [...string]
}
env?: [...{
name: string
value: string
}]
portForward?: [...string]
persistentVolumeDirs?: [...{
path: string
capacity: string
}]
resources: {
limits: {
memory: *"2Gi" | string
cpu: *"2" | string
}
requests: {
memory: *"512Mi" | string
cpu: *"0.5" | string
}
}
}

View File

@@ -0,0 +1,113 @@
# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/nocalhost.cue
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: nocalhost develop configuration.
name: nocalhost
namespace: {{.Values.systemDefinitionNamespace}}
spec:
appliesToWorkloads:
- '*'
podDisruptive: true
schematic:
cue:
template: |
import (
"encoding/json"
)
patch: metadata: annotations: {
"dev.nocalhost/application-name": context.appName
"dev.nocalhost/application-namespace": context.namespace
"dev.nocalhost": json.Marshal({
containers: [
{
name: context.name
dev: {
if parameter.gitUrl != _|_ {
gitUrl: parameter.gitUrl
}
image: parameter.image
shell: parameter.shell
workDir: parameter.workDir
if parameter.storageClass != _|_ {
storageClass: parameter.storageClass
}
resources: {
limits: parameter.resources.limits
requests: parameter.resources.requests
}
if parameter.persistentVolumeDirs != _|_ {
persistentVolumeDirs: [
for v in parameter.persistentVolumeDirs {
path: v.path
capacity: v.capacity
},
]
}
if parameter.command != _|_ {
command: parameter.command
}
if parameter.debug != _|_ {
debug: parameter.debug
}
hotReload: parameter.hotReload
if parameter.sync != _|_ {
sync: parameter.sync
}
if parameter.env != _|_ {
env: [
for v in parameter.env {
name: v.name
value: v.value
},
]
}
if parameter.portForward != _|_ {
portForward: parameter.portForward
}
}
},
]
})
}
parameter: {
gitUrl?: string
image: string
shell: *"bash" | string
workDir: *"/home/nocalhost-dev" | string
storageClass?: string
command?: {
run?: [...string]
debug?: [...string]
}
debug?: remoteDebugPort?: int
hotReload: *true | bool
sync: {
type: *"send" | string
filePattern?: [...string]
ignoreFilePattern?: [...string]
}
env?: [...{
name: string
value: string
}]
portForward?: [...string]
persistentVolumeDirs?: [...{
path: string
capacity: string
}]
resources: {
limits: {
memory: *"2Gi" | string
cpu: *"2" | string
}
requests: {
memory: *"512Mi" | string
cpu: *"0.5" | string
}
}
}

View File

@@ -0,0 +1,157 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: bookinfo
spec:
components:
- name: productpage
type: webservice
properties:
image: nocalhost-docker.pkg.coding.net/nocalhost/bookinfo/productpage:latest
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- type: nocalhost
properties:
gitUrl: https://github.com/nocalhost/bookinfo-productpage.git
image: nocalhost-docker.pkg.coding.net/nocalhost/dev-images/python:3.7.7-slim-productpage-with-pydevd
shell: "bash"
workDir: "/opt/work"
resources:
limits:
memory: 1Gi
cpu: "1"
requests:
memory: 512Mi
cpu: "0.5"
debug:
remoteDebugPort: 9009
hotReload: true
sync:
type: send
filePattern:
- ./
ignoreFilePattern:
- .git
- .idea
command:
run:
- sh
- run.sh
debug:
- sh
- debug.sh
env:
- name: "foo"
value: "bar"
portForward:
- 39080:9080
- name: authors
type: webservice
properties:
image: nocalhost-docker.pkg.coding.net/nocalhost/bookinfo/authors:latest
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- type: nocalhost
properties:
gitUrl: https://github.com/nocalhost/bookinfo-authors.git
image: nocalhost-docker.pkg.coding.net/nocalhost/dev-images/golang:latest
command:
run:
- sh
- run.sh
debug:
- sh
- debug.sh
debug:
remoteDebugPort: 9009
- name: details
type: webservice
properties:
image: nocalhost-docker.pkg.coding.net/nocalhost/bookinfo/details:latest
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- type: nocalhost
properties:
gitUrl: https://github.com/nocalhost/bookinfo-details.git
image: nocalhost-docker.pkg.coding.net/nocalhost/dev-images/ruby:2.7.1-slim
command:
run:
- sh
- run.sh
debug:
- sh
- debug.sh
sync:
filePattern:
- ./
ignoreFilePattern:
- .git
- .idea
- name: ratings
type: webservice
properties:
image: nocalhost-docker.pkg.coding.net/nocalhost/bookinfo/ratings:latest
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- type: nocalhost
properties:
gitUrl: https://github.com/nocalhost/bookinfo-ratings.git
image: nocalhost-docker.pkg.coding.net/nocalhost/dev-images/node:12.18.1-slim
command:
run:
- sh
- run.sh
debug:
- sh
- debug.sh
- name: reviews
type: webservice
properties:
image: nocalhost-docker.pkg.coding.net/nocalhost/bookinfo/reviews:latest
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- type: nocalhost
properties:
gitUrl: https://github.com/nocalhost/bookinfo-reviews.git
image: nocalhost-docker.pkg.coding.net/nocalhost/dev-images/java:latest
command:
run:
- sh
- run.sh
debug:
- sh
- debug.sh
debug:
remoteDebugPort: 5005
sync:
filePattern:
- ./
ignoreFilePattern:
- .git
- .idea
- .gradle
- build

View File

@@ -0,0 +1,113 @@
import (
"encoding/json"
)
nocalhost: {
type: "trait"
annotations: {}
labels: {}
description: "nocalhost develop configuration."
attributes: {
podDisruptive: true
appliesToWorkloads: ["*"]
}
}
template: {
patch: {
metadata: annotations: {
"dev.nocalhost/application-name": context.appName
"dev.nocalhost/application-namespace": context.namespace
"dev.nocalhost": json.Marshal({
"containers": [
{
"name": context.name
"dev": {
if parameter.gitUrl != _|_ {
"gitUrl": parameter.gitUrl
}
"image": parameter.image
"shell": parameter.shell
"workDir": parameter.workDir
if parameter.storageClass != _|_ {
"storageClass": parameter.storageClass
}
"resources": {
"limits": parameter.resources.limits
"requests": parameter.resources.requests
}
if parameter.persistentVolumeDirs != _|_ {
persistentVolumeDirs: [
for v in parameter.persistentVolumeDirs {
path: v.path
capacity: v.capacity
},
]
}
if parameter.command != _|_ {
"command": parameter.command
}
if parameter.debug != _|_ {
"debug": parameter.debug
}
"hotReload": parameter.hotReload
if parameter.sync != _|_ {
sync: parameter.sync
}
if parameter.env != _|_ {
env: [
for v in parameter.env {
name: v.name
value: v.value
},
]
}
if parameter.portForward != _|_ {
"portForward": parameter.portForward
}
}
},
]
})
}
}
parameter: {
gitUrl?: string
image: string
shell: *"bash" | string
workDir: *"/home/nocalhost-dev" | string
storageClass?: string
command?: {
run?: [...string]
debug?: [...string]
}
debug?: {
remoteDebugPort?: int
}
hotReload: *true | bool
sync: {
type: *"send" | string
filePattern?: [...string]
ignoreFilePattern?: [...string]
}
env?: [...{
name: string
value: string
}]
portForward?: [...string]
persistentVolumeDirs?: [...{
path: string
capacity: string
}]
resources: {
limits: {
memory: *"2Gi" | string
cpu: *"2" | string
}
requests: {
memory: *"512Mi" | string
cpu: *"0.5" | string
}
}
}
}