github.com/kubevela/workflow@v0.6.0/pkg/stdlib/actions/v1/pkgs/task.cue (about)

     1  
     2  let defaultToolImage = "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/entrypoint:v0.27.2"
     3  let defaultBaseImage = "gcr.io/distroless/base@sha256:aa4fd987555ea10e1a4ec8765da8158b5ffdfef1e72da512c7ede509bc9966c4"
     4  
     5  #Task: {
     6  	#do:       "steps"
     7  	name:      string
     8  	namespace: string
     9  	workspaces: [_name_=string]: #workspace & {name: "\(_name_)"}
    10  	secrets: [_name_=string]:    #secret & {name:    "\(_name_)"}
    11  	pullSecrets: [...string]
    12  	steps: [...#Script]
    13  
    14  	toolImage: *defaultToolImage | string
    15  	baseImage: *defaultBaseImage | string
    16  
    17  	generate_scripts_: [ for i, x in steps {
    18  		"""
    19          scriptfile="/vela/scripts/script-\(i)"
    20          touch ${scriptfile} && chmod +x ${scriptfile}
    21          cat > ${scriptfile} << _EOF_
    22          \(base64.Encode(null, x.script))
    23          _EOF_
    24          /vela/tools/entrypoint decode-script ${scriptfile}
    25  
    26          """
    27  	}]
    28  
    29  	name_:      name
    30  	namespace_: namespace
    31  
    32  	apply: #Apply & {
    33  		value: #PodTask & {
    34  			_settings: {
    35  				scripts_:    strings.Join(generate_scripts_, "")
    36  				workspaces_: workspaces
    37  				secrets_:    secrets
    38  				pullSecrets_: pullSecrets
    39  				toolImage_:  toolImage
    40  				baseImage_:  baseImage
    41  			}
    42  
    43  			metadata: {
    44  				name:      name_
    45  				namespace: namespace_
    46  			}
    47  			spec: containers: [ for i, step in steps {
    48  				#StepContainer
    49  				name:  step.name
    50  				image: step.image
    51  				env:   step.envs
    52  
    53  				_settings: {
    54  					workspaceMounts_: step.workspaceMounts
    55  					secretMounts_:    step.secretMounts
    56  					index_:           i
    57  				}
    58  			}]
    59  		}
    60  	}
    61  }
    62  
    63  #Script: {
    64  	name:   string
    65  	image:  string
    66  	script: string
    67  	envs: [...{name: string, value: string}]
    68  	workspaceMounts: [...{workspace: #workspace, mountPath: string}]
    69  	secretMounts: [...{secret: #secret, mountPath: string}]
    70  }
    71  
    72  #workspace: {
    73  	name: string
    74  }
    75  
    76  #secret: {
    77  	name: string
    78  	items: [...{key: string, path: string}]
    79  }
    80  
    81  #PodTask: {
    82  	_settings: {
    83  		scripts_: string
    84  		workspaces_: {...}
    85  		secrets_: {...}
    86  		pullSecrets_: [...string]
    87  		volumes_: [ for x in workspaces_ {name: x.name, emptyDir: {}}]
    88  		secretVolumes_: [ for x in secrets_ {name: x.name, secret: {secretName: x.name, items: x.items}}]
    89  		toolImage_: string
    90  		baseImage_: string
    91  	}
    92  
    93  	apiVersion: "v1"
    94  	kind:       "Pod"
    95  	metadata: {
    96  		annotations: "vela.dev/ready": "READY"
    97  		namespace: *"default" | string
    98  		name:      string
    99  	}
   100  	spec: {
   101  		containers: [...#StepContainer]
   102  		initContainers: [
   103  			{
   104  				name: "place-tools"
   105  				command: ["/ko-app/entrypoint", "cp", "/ko-app/entrypoint", "/vela/tools/entrypoint"]
   106  				image:           _settings.toolImage_
   107  				imagePullPolicy: "IfNotPresent"
   108  				volumeMounts: [{name: "vela-internal-tools", mountPath: "/vela/tools"}]
   109  			}, {
   110  				name:            "place-scripts"
   111  				imagePullPolicy: "IfNotPresent"
   112  				image:           _settings.baseImage_
   113  				command: ["sh"]
   114  				args: ["-c", _settings.scripts_]
   115  				volumeMounts: [{name: "vela-internal-scripts", mountPath: "/vela/scripts"}, {name: "vela-internal-tools", mountPath: "/vela/tools"}]
   116  			}]
   117  		volumes: [
   118  				{emptyDir: {}
   119  				name: "vela-internal-workspace"
   120  			},
   121  			{emptyDir: {}
   122  				name: "vela-internal-home"
   123  			},
   124  			{emptyDir: {}
   125  				name: "vela-internal-results"
   126  			},
   127  			{emptyDir: {}
   128  				name: "vela-internal-steps"
   129  			},
   130  			{emptyDir: {}
   131  				name: "vela-internal-scripts"
   132  			},
   133  			{emptyDir: {}
   134  				name: "vela-internal-tools"
   135  			},
   136  			{downwardAPI: {
   137  				defaultMode: 420
   138  				items: [{
   139  					fieldRef: {
   140  						apiVersion: "v1"
   141  						fieldPath:  "metadata.annotations['vela.dev/ready']"
   142  					}
   143  					path: "ready"
   144  				}]
   145  			}
   146  					name: "vela-internal-downward"
   147  				}] + _settings.volumes_ + _settings.secretVolumes_
   148  		restartPolicy: "Never"
   149  		imagePullSecrets: [ for x in _settings.pullSecrets_ {name: x}]
   150  	}
   151  }
   152  
   153  #StepContainer: {
   154  	_settings: {
   155  		index_: int
   156  		workspaceMounts_: [...{workspace: #workspace, mountPath: string}]
   157  		volumeMounts_: [ for v in workspaceMounts_ {name: v.workspace.name, mountPath: v.mountPath}]
   158  
   159  		secretMounts_: [...{secret: #secret, mountPath: string}]
   160  		secretVolumeMounts_: [ for v in secretMounts_ {name: v.secret.name, mountPath: v.mountPath}]
   161  	}
   162  
   163  	name: string
   164  	command: ["/vela/tools/entrypoint"]
   165  
   166  	args: *["-wait_file", "/vela/downward/ready", "-wait_file_content", "-post_file", "/vela/tools/\(_settings.index_)", "-termination_path", "/vela/termination", "-step_metadata_dir", "/vela/steps/step-\(name)", "-step_metadata_dir_link", "/vela/steps/\(_settings.index_)", "-entrypoint", "/vela/scripts/script-\(_settings.index_)", "--"] | [...string]
   167  	if _settings.index_ > 0 {
   168  		args: ["-wait_file", "/vela/tools/\(_settings.index_-1)", "-post_file", "/vela/tools/\(_settings.index_)", "-termination_path", "/vela/termination", "-step_metadata_dir", "/vela/steps/step-\(name)", "-step_metadata_dir_link", "/vela/steps/\(_settings.index_)", "-entrypoint", "/vela/scripts/script-\(_settings.index_)", "--"]
   169  	}
   170  
   171  	env?:                     _
   172  	image:                    string
   173  	imagePullPolicy:          "Always"
   174  	terminationMessagePath:   "/vela/termination"
   175  	terminationMessagePolicy: "File"
   176  	volumeMounts:             [{
   177  		name:      "vela-internal-scripts"
   178  		mountPath: "/vela/scripts"
   179  	}, {
   180  		name:      "vela-internal-tools"
   181  		mountPath: "/vela/tools"
   182  	}, {
   183  		name:      "vela-internal-downward"
   184  		mountPath: "/vela/downward"
   185  	}, {
   186  		name:      "vela-internal-workspace"
   187  		mountPath: "/workspace"
   188  	}, {
   189  		name:      "vela-internal-home"
   190  		mountPath: "/vela/home"
   191  	}, {
   192  		name:      "vela-internal-results"
   193  		mountPath: "/vela/results"
   194  	}, {
   195  		name:      "vela-internal-steps"
   196  		mountPath: "/vela/steps"
   197  	}] + _settings.volumeMounts_ + _settings.secretVolumeMounts_
   198  }