From 706a65beaedf3fc8daca2f4646415643a92a6767 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 27 Oct 2021 16:03:39 +0800 Subject: [PATCH] [Backport release-1.1] Feat: add nocalhost dev config trait definition (#2564) * Feat: add nocalhost dev config trait definition (cherry picked from commit 965869b43bb36a349592864bbdcbd27b83be09d8) * Feat: add nocalhost dev config trait example add nocalhost dev config trait example in `docs/examples/nocalhost` Signed-off-by: yuyicai (cherry picked from commit 70114877ce00be7b51c3c59d69e3dc40c178001d) Co-authored-by: yuyicai --- .../templates/defwithtemplate/nocalhost.yaml | 113 +++++++++++++ .../templates/defwithtemplate/nocalhost.yaml | 113 +++++++++++++ docs/examples/nocalhost/nocalhost.yaml | 157 ++++++++++++++++++ .../definitions/internal/nocalhost.cue | 113 +++++++++++++ 4 files changed, 496 insertions(+) create mode 100644 charts/vela-core/templates/defwithtemplate/nocalhost.yaml create mode 100644 charts/vela-minimal/templates/defwithtemplate/nocalhost.yaml create mode 100644 docs/examples/nocalhost/nocalhost.yaml create mode 100644 vela-templates/definitions/internal/nocalhost.cue diff --git a/charts/vela-core/templates/defwithtemplate/nocalhost.yaml b/charts/vela-core/templates/defwithtemplate/nocalhost.yaml new file mode 100644 index 000000000..fc4d1f655 --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/nocalhost.yaml @@ -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 + } + } + } + diff --git a/charts/vela-minimal/templates/defwithtemplate/nocalhost.yaml b/charts/vela-minimal/templates/defwithtemplate/nocalhost.yaml new file mode 100644 index 000000000..fc4d1f655 --- /dev/null +++ b/charts/vela-minimal/templates/defwithtemplate/nocalhost.yaml @@ -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 + } + } + } + diff --git a/docs/examples/nocalhost/nocalhost.yaml b/docs/examples/nocalhost/nocalhost.yaml new file mode 100644 index 000000000..88fb343e1 --- /dev/null +++ b/docs/examples/nocalhost/nocalhost.yaml @@ -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 diff --git a/vela-templates/definitions/internal/nocalhost.cue b/vela-templates/definitions/internal/nocalhost.cue new file mode 100644 index 000000000..b8a442df9 --- /dev/null +++ b/vela-templates/definitions/internal/nocalhost.cue @@ -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 + } + } + } +}