github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/trait/nocalhost.cue (about) 1 import ( 2 "encoding/json" 3 ) 4 5 nocalhost: { 6 type: "trait" 7 annotations: {} 8 labels: { 9 "ui-hidden": "true" 10 } 11 description: "nocalhost develop configuration." 12 attributes: { 13 podDisruptive: true 14 appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"] 15 } 16 } 17 18 template: { 19 outputs: { 20 nocalhostService: { 21 apiVersion: "v1" 22 kind: "Service" 23 metadata: name: context.name 24 spec: { 25 selector: "app.oam.dev/component": context.name 26 ports: [ 27 { 28 port: parameter.port 29 targetPort: parameter.port 30 }, 31 ] 32 type: "ClusterIP" 33 } 34 } 35 } 36 37 patch: { 38 metadata: annotations: { 39 "dev.nocalhost/application-name": context.appName 40 "dev.nocalhost/application-namespace": context.namespace 41 "dev.nocalhost": json.Marshal({ 42 name: context.name 43 serviceType: parameter.serviceType 44 "containers": [ 45 { 46 "name": context.name 47 "dev": { 48 if parameter.gitUrl != _|_ { 49 "gitUrl": parameter.gitUrl 50 } 51 if parameter.image == "go" { 52 "image": "nocalhost-docker.pkg.coding.net/nocalhost/dev-images/golang:latest" 53 } 54 if parameter.image == "java" { 55 "image": "nocalhost-docker.pkg.coding.net/nocalhost/dev-images/java:latest" 56 } 57 if parameter.image == "python" { 58 "image": "nocalhost-docker.pkg.coding.net/nocalhost/dev-images/python:latest" 59 } 60 if parameter.image == "node" { 61 "image": "nocalhost-docker.pkg.coding.net/nocalhost/dev-images/node:latest" 62 } 63 if parameter.image == "ruby" { 64 "image": "nocalhost-docker.pkg.coding.net/nocalhost/dev-images/ruby:latest" 65 } 66 if parameter.image != "go" && parameter.image != "java" && parameter.image != "python" && parameter.image != "node" && parameter.image != "ruby" { 67 "image": parameter.image 68 } 69 "shell": parameter.shell 70 "workDir": parameter.workDir 71 if parameter.storageClass != _|_ { 72 "storageClass": parameter.storageClass 73 } 74 "resources": { 75 "limits": parameter.resources.limits 76 "requests": parameter.resources.requests 77 } 78 if parameter.persistentVolumeDirs != _|_ { 79 persistentVolumeDirs: [ 80 for v in parameter.persistentVolumeDirs { 81 path: v.path 82 capacity: v.capacity 83 }, 84 ] 85 } 86 if parameter.command != _|_ { 87 "command": parameter.command 88 } 89 if parameter.debug != _|_ { 90 "debug": parameter.debug 91 } 92 "hotReload": parameter.hotReload 93 if parameter.sync != _|_ { 94 sync: parameter.sync 95 } 96 if parameter.env != _|_ { 97 env: [ 98 for v in parameter.env { 99 name: v.name 100 value: v.value 101 }, 102 ] 103 } 104 if parameter.portForward != _|_ { 105 "portForward": parameter.portForward 106 } 107 if parameter.portForward == _|_ { 108 "portForward": ["\(parameter.port):\(parameter.port)"] 109 } 110 } 111 }, 112 ] 113 }) 114 } 115 } 116 language: "go" | "java" | "python" | "node" | "ruby" 117 parameter: { 118 port: int 119 serviceType: *"deployment" | string 120 gitUrl?: string 121 image: language | string 122 shell: *"bash" | string 123 workDir: *"/home/nocalhost-dev" | string 124 storageClass?: string 125 command: { 126 run: *["sh", "run.sh"] | [...string] 127 debug: *["sh", "debug.sh"] | [...string] 128 } 129 debug?: { 130 remoteDebugPort?: int 131 } 132 hotReload: *true | bool 133 sync: { 134 type: *"send" | string 135 filePattern: *["./"] | [...string] 136 ignoreFilePattern: *[".git", ".vscode", ".idea", ".gradle", "build"] | [...string] 137 } 138 env?: [...{ 139 name: string 140 value: string 141 }] 142 portForward?: [...string] 143 persistentVolumeDirs?: [...{ 144 path: string 145 capacity: string 146 }] 147 resources: { 148 limits: { 149 memory: *"2Gi" | string 150 cpu: *"2" | string 151 } 152 requests: { 153 memory: *"512Mi" | string 154 cpu: *"0.5" | string 155 } 156 } 157 } 158 }